This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/stdlib/docker/compose/compose.cue
Tom Chauveau 020c458921 Add project management in compose.#App definition
I found an issue when during tests execution : there was orphan.
It's because #App doesn't give way to specify the compose project,
by default it's the directory where you launch your app but in our
definition, it will always be source.

The problem is that if we launch two differents docker-compose in the same
server, his project name will be source for both and it will create
orphans problems on cleanup (by docker-compose down).

This case is exactly what we do in tests so I've add the field name
to specify the projet name and avoid that issue.

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
2021-06-26 16:07:14 +02:00

87 lines
1.8 KiB
CUE

// Docker-compose operations
package compose
import (
"strconv"
"alpha.dagger.io/dagger"
"alpha.dagger.io/docker"
)
#App: {
ssh?: {
// ssh host
host: string @dagger(input)
// ssh user
user: string @dagger(input)
// ssh port
port: *22 | int @dagger(input)
// private key
key: dagger.#Secret @dagger(input)
// fingerprint
fingerprint?: string @dagger(input)
// ssh key passphrase
keyPassphrase?: dagger.#Secret @dagger(input)
}
// Accept either a contaxt, a docker-compose or both together
source?: dagger.#Artifact @dagger(input)
composeFile?: string @dagger(input)
// App name (use as COMPOSE_PROJECT_NAME)
name: *"source" | string @dagger(input)
// Image registries
registries: [...{
target?: string
username: string
secret: dagger.#Secret
}] @dagger(input)
#code: #"""
if [ -n "$DOCKER_HOSTNAME" ]; then
ssh -i /key -fNT -o "StreamLocalBindUnlink=yes" -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME"
export DOCKER_HOST="unix://$(pwd)/docker.sock"
fi
# Extend session duration
echo "Host *\nServerAliveInterval 240" >> "$HOME"/.ssh/config
chmod 600 "$HOME"/.ssh/config
# Move compose
if [ -d "$SOURCE_DIR" ]; then
if [ -f docker-compose.yaml ]; then
cp docker-compose.yaml "$SOURCE_DIR"/docker-compose.yaml
fi
cd "$SOURCE_DIR"
fi
docker-compose build
docker-compose up -d
"""#
run: docker.#Command & {
"ssh": ssh
command: #code
package: "docker-compose": true
"registries": registries
if source != _|_ {
copy: "/source": from: source
}
if composeFile != _|_ {
files: "/docker-compose.yaml": composeFile
}
env: {
COMPOSE_HTTP_TIMEOUT: strconv.FormatInt(200, 10)
COMPOSE_PROJECT_NAME: name
if source != _|_ {
SOURCE_DIR: "source"
}
}
}
}