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/pkg/alpha.dagger.io/docker/compose/compose.cue
Andrea Luzzardi 282759c0e5 cue modules: move stdlib to pkg/alpha.dagger.io
In preparation for Europa, we will vendor multiple CUE modules:

- `pkg/alpha.dagger.io`: legacy non-europa packages
- `pkg/dagger.io`: core Europa packages
- `pkg/universe.dagger.io`: Europa universe

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
2022-01-11 13:16:37 -08:00

96 lines
1.9 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)
}
// Mount local docker socket
socket?: dagger.#Stream & 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 & {
if ssh != _|_ {
"ssh": ssh
}
if socket != _|_ {
"socket": socket
}
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"
}
}
}
}