Add compose.#Up test in universe

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau
2021-06-17 17:12:51 +02:00
parent 5029b5d815
commit ae209ee090
22 changed files with 693 additions and 1 deletions

View File

@@ -0,0 +1,89 @@
package compose
import (
"strconv"
"dagger.io/dagger"
"dagger.io/dagger/op"
)
#CleanupCompose: {
// docker-compose up context
context: dagger.#Artifact
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)
}
#code: #"""
# Export host
export DOCKER_HOST="unix://$(pwd)/docker.sock"
# Start ssh agent
eval $(ssh-agent) > /dev/null
ssh-add /key > /dev/null
ssh -i /key -o "StreamLocalBindUnlink=yes" -fNT -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" || true
# Down
if [ -d /source ]; then
cd /source
fi
docker-compose down -v
"""#
#up: [
op.#Load & {from: context},
op.#WriteFile & {
content: #code
dest: "/entrypoint.sh"
},
op.#Exec & {
always: true
args: [
"/bin/sh",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
env: {
DOCKER_HOSTNAME: ssh.host
DOCKER_USERNAME: ssh.user
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
if ssh.keyPassphrase != _|_ {
SSH_ASKPASS: "/get_passphrase"
DISPLAY: "1"
}
}
mount: {
if ssh.key != _|_ {
"/key": secret: ssh.key
}
if ssh.keyPassphrase != _|_ {
"/passphrase": secret: ssh.keyPassphrase
}
}
},
]
}

View File

@@ -0,0 +1,46 @@
package compose
import (
"dagger.io/dagger"
"dagger.io/docker"
"dagger.io/docker/compose"
)
repo: dagger.#Artifact
TestCompose: {
up: compose.#Up & {
ssh: {
host: "143.198.64.230"
user: "root"
}
source: repo
composeFile: #"""
version: "3"
services:
api-mix:
build: .
environment:
PORT: 7000
ports:
- 7000:7000
networks:
default:
name: mix-context
"""#
}
verify: docker.#Command & {
ssh: up.run.ssh
command: #"""
docker container ls | grep "api-mix" | grep "Up"
"""#
}
cleanup: #CleanupCompose & {
context: up.run
ssh: verify.ssh
}
}