From 9270168f17b6ca1f6716117ea99c65531cab4fd1 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Sat, 5 Jun 2021 23:09:53 +0200 Subject: [PATCH 1/8] Add docker-compose package in stdlib Signed-off-by: Tom Chauveau --- stdlib/docker/compose/client.cue | 16 ++++ stdlib/docker/compose/compose.cue | 152 ++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 stdlib/docker/compose/client.cue create mode 100644 stdlib/docker/compose/compose.cue diff --git a/stdlib/docker/compose/client.cue b/stdlib/docker/compose/client.cue new file mode 100644 index 00000000..99eec7ba --- /dev/null +++ b/stdlib/docker/compose/client.cue @@ -0,0 +1,16 @@ +package compose + +import ( + "dagger.io/alpine" +) + +// A container image to run the docker-compose client +#Client: alpine.#Image & { + package: { + bash: true + jq: true + curl: true + "openssh-client": true + "docker-compose": true + } +} diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue new file mode 100644 index 00000000..d67eb7e8 --- /dev/null +++ b/stdlib/docker/compose/compose.cue @@ -0,0 +1,152 @@ +package compose + +import ( + "strconv" + "dagger.io/dagger" + "dagger.io/dagger/op" +) + +#Up: { + 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 + context?: dagger.#Artifact @dagger(input) + composeFile?: string @dagger(input) + + // Image registries + registries: [...{ + target?: string + username: string + secret: dagger.#Secret + }] @dagger(input) + + #code: #""" + if [ -n "$DOCKER_HOSTNAME" ]; then + export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + # Start ssh-agent + eval $(ssh-agent) > /dev/null + # Add key + if [ -f "/key" ]; then + message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { + >&2 echo "$message" + exit 1 + } + ssh-add /key > /dev/null + if [ "$?" != 0 ]; then + exit 1 + fi + fi + if [[ ! -z $FINGERPRINT ]]; then + mkdir -p "$HOME"/.ssh + # Add user's fingerprint to known hosts + echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts + else + # Add host to known hosts + ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" /bin/true > /dev/null 2>&1 + fi + fi + + cd /context + docker-compose build + docker-compose up -d + """# + + #up: [ + op.#Load & {from: #Client}, + + for registry in registries { + op.#DockerLogin & {registry} + }, + + if context != _|_ { + op.#Copy & { + from: context + dest: "/context/" + } + }, + + if context == _|_ { + op.#Mkdir & { + path: "/context/" + } + }, + + if composeFile != _|_ { + op.#WriteFile & { + content: composeFile + dest: "/context/docker-compose.yaml" + } + }, + + if ssh.keyPassphrase != _|_ { + op.#WriteFile & { + content: #""" + #!/bin/bash + cat /passphrase + """# + dest: "/get_passphrase" + mode: 0o500 + } + }, + + op.#WriteFile & { + content: #code + dest: "/entrypoint.sh" + }, + + op.#Exec & { + always: true + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "/entrypoint.sh", + ] + env: { + if ssh != _|_ { + DOCKER_HOSTNAME: ssh.host + DOCKER_USERNAME: ssh.user + DOCKER_PORT: strconv.FormatInt(ssh.port, 10) + if ssh.keyPassphrase != _|_ { + SSH_ASKPASS: "/get_passphrase" + DISPLAY: "1" + } + if ssh.fingerprint != _|_ { + FINGERPRINT: ssh.fingerprint + } + } + } + mount: { + if ssh == _|_ { + "/var/run/docker.sock": "docker.sock" + } + if ssh.key != _|_ { + "/key": secret: ssh.key + } + if ssh.keyPassphrase != _|_ { + "/passphrase": secret: ssh.keyPassphrase + } + } + }, + ] +} From b6c8ef34b06d6b225eb632a4992a969e85e1d1fe Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Sat, 5 Jun 2021 23:10:21 +0200 Subject: [PATCH 2/8] Add docker-compose tests Signed-off-by: Tom Chauveau --- stdlib/docker/compose/compose.cue | 1 + .../directory/.dagger/env/default/.gitignore | 2 + .../.dagger/env/default/plan/cleanup.cue | 77 +++++++++++ .../.dagger/env/default/plan/compose.cue | 28 ++++ .../.dagger/env/default/plan/verify.cue | 121 ++++++++++++++++++ .../directory/.dagger/env/default/values.yaml | 27 ++++ .../compose/directory/testdata/Dockerfile | 15 +++ .../directory/testdata/docker-compose.yaml | 7 + .../compose/directory/testdata/index.ts | 13 ++ .../compose/directory/testdata/package.json | 22 ++++ .../compose/directory/testdata/tsconfig.json | 12 ++ .../.dagger/env/default/.gitignore | 2 + .../.dagger/env/default/plan/cleanup.cue | 77 +++++++++++ .../.dagger/env/default/plan/compose.cue | 39 ++++++ .../.dagger/env/default/plan/verify.cue | 121 ++++++++++++++++++ .../.dagger/env/default/values.yaml | 27 ++++ .../compose/mix-context/testdata/Dockerfile | 15 +++ .../mix-context/testdata/docker-compose.yaml | 7 + .../compose/mix-context/testdata/index.ts | 13 ++ .../compose/mix-context/testdata/package.json | 22 ++++ .../mix-context/testdata/tsconfig.json | 12 ++ .../simple/.dagger/env/default/.gitignore | 2 + .../.dagger/env/default/plan/cleanup.cue | 77 +++++++++++ .../.dagger/env/default/plan/compose.cue | 33 +++++ .../.dagger/env/default/plan/verify.cue | 120 +++++++++++++++++ .../simple/.dagger/env/default/values.yaml | 24 ++++ .../voteapp/.dagger/env/default/.gitignore | 2 + .../.dagger/env/default/plan/cleanup.cue | 77 +++++++++++ .../.dagger/env/default/plan/compose.cue | 35 +++++ .../.dagger/env/default/plan/verify.cue | 120 +++++++++++++++++ .../voteapp/.dagger/env/default/values.yaml | 24 ++++ 31 files changed, 1174 insertions(+) create mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore create mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue create mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue create mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue create mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml create mode 100644 tests/stdlib/docker/compose/directory/testdata/Dockerfile create mode 100644 tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml create mode 100644 tests/stdlib/docker/compose/directory/testdata/index.ts create mode 100644 tests/stdlib/docker/compose/directory/testdata/package.json create mode 100644 tests/stdlib/docker/compose/directory/testdata/tsconfig.json create mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore create mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue create mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue create mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue create mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml create mode 100644 tests/stdlib/docker/compose/mix-context/testdata/Dockerfile create mode 100644 tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml create mode 100644 tests/stdlib/docker/compose/mix-context/testdata/index.ts create mode 100644 tests/stdlib/docker/compose/mix-context/testdata/package.json create mode 100644 tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml create mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore create mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue create mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue create mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue create mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index d67eb7e8..5be7881c 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -72,6 +72,7 @@ import ( #up: [ op.#Load & {from: #Client}, + // Login to registries for registry in registries { op.#DockerLogin & {registry} }, diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue new file mode 100644 index 00000000..d44afb09 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue @@ -0,0 +1,77 @@ +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="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + + # Start ssh agent + eval $(ssh-agent) > /dev/null + ssh-add /key > /dev/null + + # Down + cd /context + 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) + } + mount: { + if ssh.key != _|_ { + "/key": secret: ssh.key + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue new file mode 100644 index 00000000..1e3d251c --- /dev/null +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue @@ -0,0 +1,28 @@ +package compose + +import ( + "dagger.io/dagger" + "dagger.io/docker/compose" +) + +repo: dagger.#Artifact + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + context: repo + } + + verify: #VerifyCompose & { + ssh: up.ssh + port: 8080 + } + + cleanup: #CleanupCompose & { + context: up + ssh: verify.ssh + } +} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue new file mode 100644 index 00000000..8921d6c5 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue @@ -0,0 +1,121 @@ +package compose + +import ( + "strconv" + + "dagger.io/alpine" + "dagger.io/dagger/op" + "dagger.io/dagger" +) + +#VerifyCompose: { + 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) + } + + port: int | *8080 + + #code: #""" + # Start ssh-agent + eval $(ssh-agent) > /dev/null + + # Add key + if [ -f "/key" ]; then + message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { + >&2 echo "$message" + exit 1 + } + ssh-add /key > /dev/null + if [ "$?" != 0 ]; then + exit 1 + fi + fi + + if [[ ! -z $FINGERPRINT ]]; then + mkdir -p "$HOME"/.ssh + # Add user's fingerprint to known hosts + echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts + else + # Add host to known hosts + ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 + fi + + ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT"/ping > result.txt + grep -q "pong" result.txt + """# + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: { + bash: true + curl: true + "openssh-client": true + } + } + }, + + if ssh.keyPassphrase != _|_ { + op.#WriteFile & { + content: #""" + #!/bin/bash + cat /passphrase + """# + dest: "/get_passphrase" + mode: 0o500 + } + }, + + op.#WriteFile & { + content: #code + dest: "/entrypoint.sh" + }, + + op.#Exec & { + always: true + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "/entrypoint.sh", + ] + env: { + CONTAINER_PORT: strconv.FormatInt(port, 10) + REMOTE_HOSTNAME: ssh.host + REMOTE_USERNAME: ssh.user + REMOTE_PORT: strconv.FormatInt(ssh.port, 10) + if ssh.keyPassphrase != _|_ { + SSH_ASKPASS: "/get_passphrase" + DISPLAY: "1" + } + if ssh.fingerprint != _|_ { + FINGERPRINT: ssh.fingerprint + } + } + mount: { + "/key": secret: ssh.key + if ssh.keyPassphrase != _|_ { + "/passphrase": secret: ssh.keyPassphrase + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml new file mode 100644 index 00000000..ce5dd5b8 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml @@ -0,0 +1,27 @@ +name: default +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:/IwBkVdtKdXNYmJVyMhN9VUV9Hxku7E1coy1hJFNEA3cilmMsSw1rAf8NVol1QA92/Phw78he+uCosaQSWhgNIPcUWm/cX5dXOS35DLjt07Wjprw0ZMO3x+qMXp9yPZ6pBQvBZkvaJ+A8T7Ik9/H+AqtrH9uLD8GSUmy/KUTUqKO/M4lUr/PaMOJKtR9K+z9sOF+LbD061U4YwyM1RhZhkf/7/USLsHy6cCwW1FbCUjUy2Q/T6gq3SdcJKoL6bhKWxwTWQnLe9tYN1+c4gBDW4RBtsj4XKuetn/T+2ticlV/0Doc4ZihlC1IKHOc6KrrKVRTcCeVEOgNTEs73yeCIhnfm5Ndwli+nLdIkVYZJcG3HiOGvly84ZZpUEcxJfu2pnX1Qrcp7zJKoOk+JaxqQGxbqGaiAQgrB3qBX9oNIUI3p05Sd0LCHgM/HNxhLc71d2oT2gbHwCapNUPm+5Ga0M4NsPbJnRJWKbjp3p/C2FdhXSOLpJ17qWNNaLZS4Yoq8wGn5Gt01TteETIek9ZaLo/hgEaEC/ZoEjEq,iv:39HyMlg/2ctq5sqAUkpX6P7D2UFXPD2N8AIfqWxtHC8=,tag:NrLXRcVAKx82sXSIJihfPQ==,type:str] + repo: + dir: + path: ./testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBrQXpjM0VuVFhxNm5BUFRq + YWNwV0NCYTRpVTNFUnlaNHNkZzdidE8ydVhBCmtnQmJXZWFEaS9Ja0ViR0xBRisy + RlN3SGwyTXJuZExNOXV0Q0pPSk40THMKLS0tIHk5OXU3bTdUNzVMRVliWEZUaElP + UDQ3VG5mZzhGd21iYzl3L3N2UnF5bWMKllktgXwodYZEJypAC3C/VOATVlVsB8m+ + t3/WUeAe913Mhbxg11v2PekSFiUhv3Hh8Uz5FT4XJYeyXWl8UoS4jg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-05T19:29:59Z" + mac: ENC[AES256_GCM,data:aRwx2MCtVXUdKXiogYZ9c61FYH4MTMXCwuPmW6neHAhwKc962u01Bje6Zqypc74iddmCz3QCADs5OhkL6sT7utTmM1oJKBUfYwxh8udabWP5WRE/bmW1xXMLQsYW2j++uC0OJuZNQliOSo+Rw+6hwbVVezI/dNBG6ki87eyT6K0=,iv:D5/nJ9enZ1CO4wBcRiKSILezYWywD1bTiDSZJps7hA0=,tag:stneW8K4u/vsxW9k++g+lA==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/tests/stdlib/docker/compose/directory/testdata/Dockerfile b/tests/stdlib/docker/compose/directory/testdata/Dockerfile new file mode 100644 index 00000000..25d4c068 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/testdata/Dockerfile @@ -0,0 +1,15 @@ +FROM node:12-alpine + +WORKDIR /app + +COPY package.json package.json + +RUN npm install + +COPY . . + +ENV PORT=8080 + +EXPOSE 8080 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml b/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml new file mode 100644 index 00000000..b091d2e1 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml @@ -0,0 +1,7 @@ +version: "3" + +services: + api: + build: . + ports: + - "8080:8080" \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/index.ts b/tests/stdlib/docker/compose/directory/testdata/index.ts new file mode 100644 index 00000000..d37fe572 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/testdata/index.ts @@ -0,0 +1,13 @@ +import express from "express"; +import { get } from "env-var"; + + +const app = express(); + +const port: number = get('PORT').required().asPortNumber(); + +app.get('/ping', (req, res) => { + res.status(200).send('pong') +}); + +app.listen(port, '0.0.0.0', () => console.log("Server listen on http://localhost:" + port)); \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/package.json b/tests/stdlib/docker/compose/directory/testdata/package.json new file mode 100644 index 00000000..c2be41f2 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/testdata/package.json @@ -0,0 +1,22 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "A simple api", + "main": "index.ts", + "scripts": { + "build": "tsc", + "start": "ts-node index.ts", + "test": "test" + }, + "author": "Tom Chauveau", + "license": "ISC", + "devDependencies": { + "ts-node": "^8.9.1", + "typescript": "^3.8.3" + }, + "dependencies": { + "@types/express": "^4.17.6", + "env-var": "^6.1.1", + "express": "^4.17.1" + } +} diff --git a/tests/stdlib/docker/compose/directory/testdata/tsconfig.json b/tests/stdlib/docker/compose/directory/testdata/tsconfig.json new file mode 100644 index 00000000..98907427 --- /dev/null +++ b/tests/stdlib/docker/compose/directory/testdata/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "sourceMap": true, + "outDir": "dist", + "strict": true, + "lib": [ + "esnext", + "dom" + ], + "esModuleInterop": true + } +} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue new file mode 100644 index 00000000..d44afb09 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue @@ -0,0 +1,77 @@ +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="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + + # Start ssh agent + eval $(ssh-agent) > /dev/null + ssh-add /key > /dev/null + + # Down + cd /context + 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) + } + mount: { + if ssh.key != _|_ { + "/key": secret: ssh.key + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue new file mode 100644 index 00000000..2620c472 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue @@ -0,0 +1,39 @@ +package compose + +import ( + "dagger.io/dagger" + "dagger.io/docker/compose" +) + +repo: dagger.#Artifact + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + context: repo + composeFile: #""" + version: "3" + + services: + api: + build: . + environment: + PORT: 7000 + ports: + - 7000:7000 + """# + } + + verify: #VerifyCompose & { + ssh: up.ssh + port: 7000 + } + + cleanup: #CleanupCompose & { + context: up + ssh: verify.ssh + } +} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue new file mode 100644 index 00000000..8921d6c5 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue @@ -0,0 +1,121 @@ +package compose + +import ( + "strconv" + + "dagger.io/alpine" + "dagger.io/dagger/op" + "dagger.io/dagger" +) + +#VerifyCompose: { + 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) + } + + port: int | *8080 + + #code: #""" + # Start ssh-agent + eval $(ssh-agent) > /dev/null + + # Add key + if [ -f "/key" ]; then + message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { + >&2 echo "$message" + exit 1 + } + ssh-add /key > /dev/null + if [ "$?" != 0 ]; then + exit 1 + fi + fi + + if [[ ! -z $FINGERPRINT ]]; then + mkdir -p "$HOME"/.ssh + # Add user's fingerprint to known hosts + echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts + else + # Add host to known hosts + ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 + fi + + ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT"/ping > result.txt + grep -q "pong" result.txt + """# + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: { + bash: true + curl: true + "openssh-client": true + } + } + }, + + if ssh.keyPassphrase != _|_ { + op.#WriteFile & { + content: #""" + #!/bin/bash + cat /passphrase + """# + dest: "/get_passphrase" + mode: 0o500 + } + }, + + op.#WriteFile & { + content: #code + dest: "/entrypoint.sh" + }, + + op.#Exec & { + always: true + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "/entrypoint.sh", + ] + env: { + CONTAINER_PORT: strconv.FormatInt(port, 10) + REMOTE_HOSTNAME: ssh.host + REMOTE_USERNAME: ssh.user + REMOTE_PORT: strconv.FormatInt(ssh.port, 10) + if ssh.keyPassphrase != _|_ { + SSH_ASKPASS: "/get_passphrase" + DISPLAY: "1" + } + if ssh.fingerprint != _|_ { + FINGERPRINT: ssh.fingerprint + } + } + mount: { + "/key": secret: ssh.key + if ssh.keyPassphrase != _|_ { + "/passphrase": secret: ssh.keyPassphrase + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml new file mode 100644 index 00000000..485db6d9 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml @@ -0,0 +1,27 @@ +name: default +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:VER9BalLBamLFIvFPCHS5xW6lTjyToNDCmnQu6pSsnsOo6B9WYoZf5KiMfnmRYL99eKiGJAgK67S6jWyiUYCdFBi+wXav+YpvqgWENFP1gSVk3AvoQx2RR403/1D9hFtJd+cQaL2wjUBkGRdjZ2WX//ElBeDAPlcdoLnNvOvITIYsb54elqvkfQdm5yCgwi+EsSkaGresWYUdBxFqhkILUPhJ6hKd/7RyPRyOVCTEK9HxpfY/a6Q7gcLJk1W+mJQLPd1T+Z+GkJuv2Xe1uozazrXDLb+Yt/Cz3TfXwXt2zbE10zoM3dhQ++DC6ZQx+wWOaGhIn8fd4WUb9DM4NqbcSQWxmmbo9mhhRBpP7/ea8EFs8wz0otF/FZy5sK/bThq1ziotUc3i7CWrU4xrwDwK+pYGA7kssXUFzi2mUn9mqH2WoYUAsC24BP5XJjgjz8nqhhx+WnMzYY1RhW7+cAZFvgzAJPmJ3aEv9tyGbdczg2O3n0fboumIP3Rl/99Ld+5JMVzcneHmdS7adH9+CWi19a66o9I0Jxufys1,iv:4D7/IZk3niD8rFbOcZEI0w9Wz6kwS2DCDp9BgW+eoho=,tag:AJdUzma7XAPiqbo7z90OEQ==,type:str] + repo: + dir: + path: ./testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBjSVBlUG54ZlJyRXVVZUVx + dGZOT3FueFkwditJSEY0YytaMkZoSWM0aEZrCmVOM3J1Wnc0VjgwZUJYSndXS255 + dUFUdzhHQy95Nkg1aHZtR3ExL3Y1WncKLS0tIExVZC94aWFCbkZGWkFSdmFNbTRJ + S0p6aEVtOFdKYk03NjUzU21Zdk5GYm8KuPlFhlBq31vMea+RQhBliHlm/iXIGq2u + QsSR6owRh7doEq0PheYz8ypZuqWduj9tuTLqXxCz0djjgsVbvo52LQ== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-05T19:55:53Z" + mac: ENC[AES256_GCM,data:FB0sUdVVYjWeovBYR5K78CGBxUfd8ddsHulWNzNUp/Jf/M6Rd/LBCN0DmneUO2oWI9pgOJYlvgK3EO7xIA42uO9gIyRU1O7ikjhN0pzFcCE7VKVUjBky2p5UQ5m9kvm4RIXYRC0aKkp7NJ8V3XXDrpag21+R5Y/p7iF9/BkdlsU=,iv:bbq/sIa2uSTc3Yu0j/AJ3dmDyn4tSV2JmutFwdi3B/c=,tag:3Rc2FjmX1u/qF6oWiFmKkA==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile b/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile new file mode 100644 index 00000000..25d4c068 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile @@ -0,0 +1,15 @@ +FROM node:12-alpine + +WORKDIR /app + +COPY package.json package.json + +RUN npm install + +COPY . . + +ENV PORT=8080 + +EXPOSE 8080 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml b/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml new file mode 100644 index 00000000..b091d2e1 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml @@ -0,0 +1,7 @@ +version: "3" + +services: + api: + build: . + ports: + - "8080:8080" \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/index.ts b/tests/stdlib/docker/compose/mix-context/testdata/index.ts new file mode 100644 index 00000000..d37fe572 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/testdata/index.ts @@ -0,0 +1,13 @@ +import express from "express"; +import { get } from "env-var"; + + +const app = express(); + +const port: number = get('PORT').required().asPortNumber(); + +app.get('/ping', (req, res) => { + res.status(200).send('pong') +}); + +app.listen(port, '0.0.0.0', () => console.log("Server listen on http://localhost:" + port)); \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/package.json b/tests/stdlib/docker/compose/mix-context/testdata/package.json new file mode 100644 index 00000000..c2be41f2 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/testdata/package.json @@ -0,0 +1,22 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "A simple api", + "main": "index.ts", + "scripts": { + "build": "tsc", + "start": "ts-node index.ts", + "test": "test" + }, + "author": "Tom Chauveau", + "license": "ISC", + "devDependencies": { + "ts-node": "^8.9.1", + "typescript": "^3.8.3" + }, + "dependencies": { + "@types/express": "^4.17.6", + "env-var": "^6.1.1", + "express": "^4.17.1" + } +} diff --git a/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json b/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json new file mode 100644 index 00000000..98907427 --- /dev/null +++ b/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "sourceMap": true, + "outDir": "dist", + "strict": true, + "lib": [ + "esnext", + "dom" + ], + "esModuleInterop": true + } +} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue new file mode 100644 index 00000000..d44afb09 --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue @@ -0,0 +1,77 @@ +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="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + + # Start ssh agent + eval $(ssh-agent) > /dev/null + ssh-add /key > /dev/null + + # Down + cd /context + 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) + } + mount: { + if ssh.key != _|_ { + "/key": secret: ssh.key + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue new file mode 100644 index 00000000..20cafe92 --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue @@ -0,0 +1,33 @@ +package compose + +import ( + "dagger.io/docker/compose" +) + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + composeFile: #""" + version: "3" + + services: + nginx: + image: nginx:alpine + ports: + - 8080:80 + """# + } + + verify: #VerifyCompose & { + ssh: up.ssh + port: 8080 + } + + cleanup: #CleanupCompose & { + context: up + ssh: verify.ssh + } +} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue new file mode 100644 index 00000000..5d0c2e5e --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue @@ -0,0 +1,120 @@ +package compose + +import ( + "strconv" + + "dagger.io/alpine" + "dagger.io/dagger/op" + "dagger.io/dagger" +) + +#VerifyCompose: { + 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) + } + + port: int | *8080 + + #code: #""" + # Start ssh-agent + eval $(ssh-agent) > /dev/null + + # Add key + if [ -f "/key" ]; then + message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { + >&2 echo "$message" + exit 1 + } + ssh-add /key > /dev/null + if [ "$?" != 0 ]; then + exit 1 + fi + fi + + if [[ ! -z $FINGERPRINT ]]; then + mkdir -p "$HOME"/.ssh + # Add user's fingerprint to known hosts + echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts + else + # Add host to known hosts + ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 + fi + + ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT" + """# + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: { + bash: true + curl: true + "openssh-client": true + } + } + }, + + if ssh.keyPassphrase != _|_ { + op.#WriteFile & { + content: #""" + #!/bin/bash + cat /passphrase + """# + dest: "/get_passphrase" + mode: 0o500 + } + }, + + op.#WriteFile & { + content: #code + dest: "/entrypoint.sh" + }, + + op.#Exec & { + always: true + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "/entrypoint.sh", + ] + env: { + CONTAINER_PORT: strconv.FormatInt(port, 10) + REMOTE_HOSTNAME: ssh.host + REMOTE_USERNAME: ssh.user + REMOTE_PORT: strconv.FormatInt(ssh.port, 10) + if ssh.keyPassphrase != _|_ { + SSH_ASKPASS: "/get_passphrase" + DISPLAY: "1" + } + if ssh.fingerprint != _|_ { + FINGERPRINT: ssh.fingerprint + } + } + mount: { + "/key": secret: ssh.key + if ssh.keyPassphrase != _|_ { + "/passphrase": secret: ssh.keyPassphrase + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml new file mode 100644 index 00000000..01dedc9c --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml @@ -0,0 +1,24 @@ +name: default +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:ixiwG8s0jeEQ2hy6kQmOOYjwTAAaLB9hz0ih8az0mvqPV0HZSWQwOg3OPVgBW9Slk3MZjv6RYc8n2YoanHWZm2WxsA/neSFI7XG/IH/xhLDtxX+wmqrjP4To1KGZ4R4QgVdpA/bhCxXDt9a9lqJSMGGh2mOklRs+vMDhV6kkXbc/dX1ki7JSH754QME3HRdQn6Q7VYDg2ro3Ry/IrOA9uzqNUdAK7GW4ADe3Lez3HPg3jS2vvccHURRfSGnBBbtLa7kgpQdtrAhZuZP6h+6XOJZDZ+/aZSar+nY/CFey+2JnBSAMzZ2MvNy9uoW/NwalT5uN+U/skqdhfVMWVkExb5Pnhpfr44pLBt8uvBwOzZ97XUgI/rgWkmi3efY33A9/vL2ac3HVZSok7XMz8TbwOZM9JU3u3nHx6VS//Mp6c0qXYSrHNlJJeBpF61HGX/rqpYoZC86Sj2AwzuYVsbUwVGwGI9FytJVyp/zCrQaRte0coM1Huy5UKX7KotMIFyQdjtDmsOo5dfjkmxWC+4AB5nwgu+wYz6qUKV7C,iv:T7hpMnKdGirSirC9V/xitgFwhHsuYc9XuHXc7NqX8Eg=,tag:w1jORINS1hyDpOJskHOQ7Q==,type:str] +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAvcFgyV0NXUCthU1B4NE5I + RWRXREZuS3FtbEd3a0p2SHZmNW9QOGpxWG5JClgzamp0SUlkY0E1SytKK2pXb2ts + YzZpZWxWR0lua1g0V3U5Nlk1Y1hIWWsKLS0tIC9MVTZCdDNFUmtnR2RjekZnbnUv + M1czbGlnRmdmaVQxK1h2eGhqSXpJcTQKWl4r3FLuqFkX13ivmsIAsRxoXGGyeu9f + CfkCQ9jc7N6YH4MtEFO33VNJNc+xQDXKzRDVjo0vCxxk12iebi5o3w== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-05T16:01:39Z" + mac: ENC[AES256_GCM,data:CuzfQP5Wg4AJHI83onmg2SYC9U8a/KezVORQH0DLr9BaYRMX/qpxv0+DEqLlWADmaCNcA2NF43FmwcaKybn5SBc4i2GoVfouwIxzfPSvfu3cCH/uyjFVZ4Me0IP6vnd3EGLbZDQgJFV6bBTYSJS6OqVypmFPr6pyaAd1RO5KqfA=,iv:MY3Vdx9BqPC+HIY8Qc4ldu0sjM2rlxy4GEEzIKXyUCk=,tag:jCgDpsf3WZQC3Rlngd1uVg==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue new file mode 100644 index 00000000..d44afb09 --- /dev/null +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue @@ -0,0 +1,77 @@ +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="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + + # Start ssh agent + eval $(ssh-agent) > /dev/null + ssh-add /key > /dev/null + + # Down + cd /context + 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) + } + mount: { + if ssh.key != _|_ { + "/key": secret: ssh.key + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue new file mode 100644 index 00000000..150f286d --- /dev/null +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue @@ -0,0 +1,35 @@ +package compose + +import ( + "dagger.io/git" + "dagger.io/docker/compose" +) + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + context: git.#Repository & { + remote: "https://github.com/dagger/examples" + ref: "main" + subdir: "voteapp" + } + } + + verifyApp: #VerifyCompose & { + ssh: up.ssh + port: 5000 + } + + verifyResult: #VerifyCompose & { + ssh: up.ssh + port: 5001 + } + + cleanup: #CleanupCompose & { + context: up + ssh: verifyResult.ssh + } +} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue new file mode 100644 index 00000000..5d0c2e5e --- /dev/null +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue @@ -0,0 +1,120 @@ +package compose + +import ( + "strconv" + + "dagger.io/alpine" + "dagger.io/dagger/op" + "dagger.io/dagger" +) + +#VerifyCompose: { + 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) + } + + port: int | *8080 + + #code: #""" + # Start ssh-agent + eval $(ssh-agent) > /dev/null + + # Add key + if [ -f "/key" ]; then + message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { + >&2 echo "$message" + exit 1 + } + ssh-add /key > /dev/null + if [ "$?" != 0 ]; then + exit 1 + fi + fi + + if [[ ! -z $FINGERPRINT ]]; then + mkdir -p "$HOME"/.ssh + # Add user's fingerprint to known hosts + echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts + else + # Add host to known hosts + ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 + fi + + ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT" + """# + + #up: [ + op.#Load & { + from: alpine.#Image & { + package: { + bash: true + curl: true + "openssh-client": true + } + } + }, + + if ssh.keyPassphrase != _|_ { + op.#WriteFile & { + content: #""" + #!/bin/bash + cat /passphrase + """# + dest: "/get_passphrase" + mode: 0o500 + } + }, + + op.#WriteFile & { + content: #code + dest: "/entrypoint.sh" + }, + + op.#Exec & { + always: true + args: [ + "/bin/sh", + "--noprofile", + "--norc", + "-eo", + "pipefail", + "/entrypoint.sh", + ] + env: { + CONTAINER_PORT: strconv.FormatInt(port, 10) + REMOTE_HOSTNAME: ssh.host + REMOTE_USERNAME: ssh.user + REMOTE_PORT: strconv.FormatInt(ssh.port, 10) + if ssh.keyPassphrase != _|_ { + SSH_ASKPASS: "/get_passphrase" + DISPLAY: "1" + } + if ssh.fingerprint != _|_ { + FINGERPRINT: ssh.fingerprint + } + } + mount: { + "/key": secret: ssh.key + if ssh.keyPassphrase != _|_ { + "/passphrase": secret: ssh.keyPassphrase + } + } + }, + ] +} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml new file mode 100644 index 00000000..3d64b33d --- /dev/null +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml @@ -0,0 +1,24 @@ +name: default +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:eLBDG05PNBU5O3ICj7GAgUO4niTgxEGhqo0XvhKlkLnSvys0/MXHMnuRpJdEXypt6V3aoD+iAgOvO4M3JKvxWNagYk45yfjrtCpjW8e/j+pu7zc1IrxJtD++GMfIQ3WZBDHu7bZ4XJWGbVHhEngPjhgJKozgb1GLZQKw0ArgrufIIZ9S4mgYnCytiCjV1M5WFWmI0AVAEgGgQdlvKDUK/k6hcUNb/8bQhXPnlLM7nGjz1yLYaUfScWeDaHSx/NXMwIaadHzR/6naFnEn5xJJZjQ8Y+SkJcLu1fwE2Z5zYuhvqhYdu+36x7gDHTrtf6+eCCitRUU2Mj4RN1g9FzGDCyFuhn/I1E54lhm8N6WcPHLTX1kRIQk/7wLF0zT918YNLoWicXLg4hqOe/D5ew8i+ZLnQJAjzlYKZQawZsaSkhOozSuYFg8pjrTbroX+yg0cipfodt7J1aX0ddgWSuzYQADUDx2iIJwuFxFtQiSJw4IIJiAeKipWsEKKyBHChpDFz3+RIWkzOe0rs/VYf4SKhGAO4oMaOmXtBY6Z,iv:KjCJFkm3rOz55yeIc8pTx6LQqNZselhjsyHIyHps0MY=,tag:/upNvd/QGzU+A86tv7h0AA==,type:str] +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBIUkd0TUY5Zlc5TUJTaEgw + RlEwWU10RWcvOGR2WkRpajh4WWtjUmZYV0U0CjRyQlB2N0paMXdTRXJSRmV5T1lX + WmwzbDZleG9IZXdDMHlLbmhVSTlVYncKLS0tIEJIaitaSUw3LzhkOHVjQVpzd3NV + bWFNREMxU1NVQ01xUmU5cnlER0Fad0UKMkFvd3S/56/k0dw2GYDsGyjBWqy29Mht + ed/N7FxrAkHBnGzfs+A1mMtrrTsrs70sWOsZvxr406Pp+Iue899Q2A== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-05T21:00:42Z" + mac: ENC[AES256_GCM,data:ajVoJ9nInK6kvxxkCpAjMNQ97oZdXgIvscA3R7OlItRA1Xlvu3C6ndU6VoSy6hotR8OJkad2EHfCXDlgrcodXVJcwaqVdCTNDSJLyu8XAIDQKqIpGQwtl6dPrvomE4gmEg3qDC5xPfDV9MNpo1j5M6VyIhrmSJjnWiCg4juIHD4=,iv:FjfWpIHdfQ7gwbM5PBUBVR0LOofRmLvgCpSeMkgGmI4=,tag:FCSHpYrCZR0eLVgy//gI/g==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 From f2d8cb39bd2ff2b4a1a60051b60d2576423fab3d Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Sun, 6 Jun 2021 17:51:28 +0200 Subject: [PATCH 3/8] Fix network error on docker-compose Signed-off-by: Tom Chauveau --- stdlib/docker/compose/compose.cue | 14 ++++++++++---- .../.dagger/env/default/plan/cleanup.cue | 11 ++++++++++- .../.dagger/env/default/plan/compose.cue | 10 +++++----- .../.dagger/env/default/plan/verify.cue | 2 +- .../.dagger/env/default/plan/cleanup.cue | 11 ++++++++++- .../.dagger/env/default/plan/compose.cue | 10 +++++----- .../.dagger/env/default/plan/verify.cue | 2 +- .../.dagger/env/default/plan/cleanup.cue | 11 ++++++++++- .../.dagger/env/default/plan/compose.cue | 10 +++++----- .../simple/.dagger/env/default/plan/verify.cue | 3 ++- .../.dagger/env/default/plan/cleanup.cue | 11 ++++++++++- .../.dagger/env/default/plan/compose.cue | 18 +++++++++--------- .../.dagger/env/default/plan/verify.cue | 2 +- 13 files changed, 79 insertions(+), 36 deletions(-) diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index 5be7881c..1f93416b 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -40,7 +40,6 @@ import ( #code: #""" if [ -n "$DOCKER_HOSTNAME" ]; then - export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" # Start ssh-agent eval $(ssh-agent) > /dev/null # Add key @@ -62,8 +61,14 @@ import ( # Add host to known hosts ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" /bin/true > /dev/null 2>&1 fi + 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 + cd /context docker-compose build docker-compose up -d @@ -125,9 +130,10 @@ import ( ] env: { if ssh != _|_ { - DOCKER_HOSTNAME: ssh.host - DOCKER_USERNAME: ssh.user - DOCKER_PORT: strconv.FormatInt(ssh.port, 10) + COMPOSE_HTTP_TIMEOUT: strconv.FormatInt(200, 10) + DOCKER_HOSTNAME: ssh.host + DOCKER_USERNAME: ssh.user + DOCKER_PORT: strconv.FormatInt(ssh.port, 10) if ssh.keyPassphrase != _|_ { SSH_ASKPASS: "/get_passphrase" DISPLAY: "1" diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue index d44afb09..1d43884d 100644 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue @@ -33,12 +33,14 @@ import ( #code: #""" # Export host - export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + 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 cd /context docker-compose down -v @@ -66,11 +68,18 @@ import ( 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 + } } }, ] diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue index 1e3d251c..4be94d30 100644 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue @@ -16,13 +16,13 @@ TestCompose: { context: repo } - verify: #VerifyCompose & { - ssh: up.ssh - port: 8080 - } + //verify: #VerifyCompose & { + // ssh: up.ssh + // port: 8080 + //} cleanup: #CleanupCompose & { context: up - ssh: verify.ssh + ssh: up.ssh } } diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue index 8921d6c5..53ac99ff 100644 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue +++ b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue @@ -56,7 +56,7 @@ import ( ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 fi - ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT"/ping > result.txt + sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT"/ping > result.txt grep -q "pong" result.txt """# diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue index d44afb09..1d43884d 100644 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue @@ -33,12 +33,14 @@ import ( #code: #""" # Export host - export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + 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 cd /context docker-compose down -v @@ -66,11 +68,18 @@ import ( 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 + } } }, ] diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue index 2620c472..7e318989 100644 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue @@ -27,13 +27,13 @@ TestCompose: { """# } - verify: #VerifyCompose & { - ssh: up.ssh - port: 7000 - } + //verify: #VerifyCompose & { + // ssh: up.ssh + // port: 7000 + //} cleanup: #CleanupCompose & { context: up - ssh: verify.ssh + ssh: up.ssh } } diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue index 8921d6c5..53ac99ff 100644 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue +++ b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue @@ -56,7 +56,7 @@ import ( ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 fi - ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT"/ping > result.txt + sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT"/ping > result.txt grep -q "pong" result.txt """# diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue index d44afb09..1d43884d 100644 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue @@ -33,12 +33,14 @@ import ( #code: #""" # Export host - export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + 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 cd /context docker-compose down -v @@ -66,11 +68,18 @@ import ( 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 + } } }, ] diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue index 20cafe92..04b24173 100644 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue @@ -21,13 +21,13 @@ TestCompose: { """# } - verify: #VerifyCompose & { - ssh: up.ssh - port: 8080 - } + //verify: #VerifyCompose & { + // ssh: up.ssh + // port: 8080 + //} cleanup: #CleanupCompose & { context: up - ssh: verify.ssh + ssh: up.ssh } } diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue index 5d0c2e5e..24a813ed 100644 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue @@ -55,8 +55,9 @@ import ( # Add host to known hosts ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 fi + - ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT" + sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT" """# #up: [ diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue index d44afb09..1d43884d 100644 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue @@ -33,12 +33,14 @@ import ( #code: #""" # Export host - export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT" + 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 cd /context docker-compose down -v @@ -66,11 +68,18 @@ import ( 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 + } } }, ] diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue index 150f286d..d6c5b586 100644 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue @@ -18,18 +18,18 @@ TestCompose: { } } - verifyApp: #VerifyCompose & { - ssh: up.ssh - port: 5000 - } + //verifyApp: #VerifyCompose & { + // ssh: up.ssh + // port: 5000 + //} - verifyResult: #VerifyCompose & { - ssh: up.ssh - port: 5001 - } + //verifyResult: #VerifyCompose & { + // ssh: up.ssh + // port: 5001 + //} cleanup: #CleanupCompose & { context: up - ssh: verifyResult.ssh + ssh: up.ssh } } diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue index 5d0c2e5e..c59762b9 100644 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue +++ b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue @@ -56,7 +56,7 @@ import ( ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 fi - ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl localhost:"$CONTAINER_PORT" + sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT" """# #up: [ From f1a6f66ed542c0a79999f21f016a33a484b8cc33 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 17 Jun 2021 17:09:33 +0200 Subject: [PATCH 4/8] Remove all docker-compose stdlib tests Signed-off-by: Tom Chauveau --- .../directory/.dagger/env/default/.gitignore | 2 - .../.dagger/env/default/plan/cleanup.cue | 86 ------------- .../.dagger/env/default/plan/compose.cue | 28 ---- .../.dagger/env/default/plan/verify.cue | 121 ------------------ .../directory/.dagger/env/default/values.yaml | 27 ---- .../compose/directory/testdata/Dockerfile | 15 --- .../directory/testdata/docker-compose.yaml | 7 - .../compose/directory/testdata/index.ts | 13 -- .../compose/directory/testdata/package.json | 22 ---- .../compose/directory/testdata/tsconfig.json | 12 -- .../.dagger/env/default/.gitignore | 2 - .../.dagger/env/default/plan/cleanup.cue | 86 ------------- .../.dagger/env/default/plan/compose.cue | 39 ------ .../.dagger/env/default/plan/verify.cue | 121 ------------------ .../.dagger/env/default/values.yaml | 27 ---- .../compose/mix-context/testdata/Dockerfile | 15 --- .../mix-context/testdata/docker-compose.yaml | 7 - .../compose/mix-context/testdata/index.ts | 13 -- .../compose/mix-context/testdata/package.json | 22 ---- .../mix-context/testdata/tsconfig.json | 12 -- .../simple/.dagger/env/default/.gitignore | 2 - .../.dagger/env/default/plan/cleanup.cue | 86 ------------- .../.dagger/env/default/plan/compose.cue | 33 ----- .../.dagger/env/default/plan/verify.cue | 121 ------------------ .../simple/.dagger/env/default/values.yaml | 24 ---- .../voteapp/.dagger/env/default/.gitignore | 2 - .../.dagger/env/default/plan/cleanup.cue | 86 ------------- .../.dagger/env/default/plan/compose.cue | 35 ----- .../.dagger/env/default/plan/verify.cue | 120 ----------------- .../voteapp/.dagger/env/default/values.yaml | 24 ---- 30 files changed, 1210 deletions(-) delete mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore delete mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue delete mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue delete mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue delete mode 100644 tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml delete mode 100644 tests/stdlib/docker/compose/directory/testdata/Dockerfile delete mode 100644 tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml delete mode 100644 tests/stdlib/docker/compose/directory/testdata/index.ts delete mode 100644 tests/stdlib/docker/compose/directory/testdata/package.json delete mode 100644 tests/stdlib/docker/compose/directory/testdata/tsconfig.json delete mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore delete mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue delete mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue delete mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue delete mode 100644 tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml delete mode 100644 tests/stdlib/docker/compose/mix-context/testdata/Dockerfile delete mode 100644 tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml delete mode 100644 tests/stdlib/docker/compose/mix-context/testdata/index.ts delete mode 100644 tests/stdlib/docker/compose/mix-context/testdata/package.json delete mode 100644 tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml delete mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore delete mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue delete mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue delete mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue delete mode 100644 tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue deleted file mode 100644 index 1d43884d..00000000 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/cleanup.cue +++ /dev/null @@ -1,86 +0,0 @@ -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 - cd /context - 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 - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue deleted file mode 100644 index 4be94d30..00000000 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/compose.cue +++ /dev/null @@ -1,28 +0,0 @@ -package compose - -import ( - "dagger.io/dagger" - "dagger.io/docker/compose" -) - -repo: dagger.#Artifact - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - context: repo - } - - //verify: #VerifyCompose & { - // ssh: up.ssh - // port: 8080 - //} - - cleanup: #CleanupCompose & { - context: up - ssh: up.ssh - } -} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue deleted file mode 100644 index 53ac99ff..00000000 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/plan/verify.cue +++ /dev/null @@ -1,121 +0,0 @@ -package compose - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" - "dagger.io/dagger" -) - -#VerifyCompose: { - 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) - } - - port: int | *8080 - - #code: #""" - # Start ssh-agent - eval $(ssh-agent) > /dev/null - - # Add key - if [ -f "/key" ]; then - message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { - >&2 echo "$message" - exit 1 - } - ssh-add /key > /dev/null - if [ "$?" != 0 ]; then - exit 1 - fi - fi - - if [[ ! -z $FINGERPRINT ]]; then - mkdir -p "$HOME"/.ssh - # Add user's fingerprint to known hosts - echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts - else - # Add host to known hosts - ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 - fi - - sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT"/ping > result.txt - grep -q "pong" result.txt - """# - - #up: [ - op.#Load & { - from: alpine.#Image & { - package: { - bash: true - curl: true - "openssh-client": true - } - } - }, - - if ssh.keyPassphrase != _|_ { - op.#WriteFile & { - content: #""" - #!/bin/bash - cat /passphrase - """# - dest: "/get_passphrase" - mode: 0o500 - } - }, - - op.#WriteFile & { - content: #code - dest: "/entrypoint.sh" - }, - - op.#Exec & { - always: true - args: [ - "/bin/sh", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "/entrypoint.sh", - ] - env: { - CONTAINER_PORT: strconv.FormatInt(port, 10) - REMOTE_HOSTNAME: ssh.host - REMOTE_USERNAME: ssh.user - REMOTE_PORT: strconv.FormatInt(ssh.port, 10) - if ssh.keyPassphrase != _|_ { - SSH_ASKPASS: "/get_passphrase" - DISPLAY: "1" - } - if ssh.fingerprint != _|_ { - FINGERPRINT: ssh.fingerprint - } - } - mount: { - "/key": secret: ssh.key - if ssh.keyPassphrase != _|_ { - "/passphrase": secret: ssh.keyPassphrase - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml deleted file mode 100644 index ce5dd5b8..00000000 --- a/tests/stdlib/docker/compose/directory/.dagger/env/default/values.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: default -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:/IwBkVdtKdXNYmJVyMhN9VUV9Hxku7E1coy1hJFNEA3cilmMsSw1rAf8NVol1QA92/Phw78he+uCosaQSWhgNIPcUWm/cX5dXOS35DLjt07Wjprw0ZMO3x+qMXp9yPZ6pBQvBZkvaJ+A8T7Ik9/H+AqtrH9uLD8GSUmy/KUTUqKO/M4lUr/PaMOJKtR9K+z9sOF+LbD061U4YwyM1RhZhkf/7/USLsHy6cCwW1FbCUjUy2Q/T6gq3SdcJKoL6bhKWxwTWQnLe9tYN1+c4gBDW4RBtsj4XKuetn/T+2ticlV/0Doc4ZihlC1IKHOc6KrrKVRTcCeVEOgNTEs73yeCIhnfm5Ndwli+nLdIkVYZJcG3HiOGvly84ZZpUEcxJfu2pnX1Qrcp7zJKoOk+JaxqQGxbqGaiAQgrB3qBX9oNIUI3p05Sd0LCHgM/HNxhLc71d2oT2gbHwCapNUPm+5Ga0M4NsPbJnRJWKbjp3p/C2FdhXSOLpJ17qWNNaLZS4Yoq8wGn5Gt01TteETIek9ZaLo/hgEaEC/ZoEjEq,iv:39HyMlg/2ctq5sqAUkpX6P7D2UFXPD2N8AIfqWxtHC8=,tag:NrLXRcVAKx82sXSIJihfPQ==,type:str] - repo: - dir: - path: ./testdata -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBrQXpjM0VuVFhxNm5BUFRq - YWNwV0NCYTRpVTNFUnlaNHNkZzdidE8ydVhBCmtnQmJXZWFEaS9Ja0ViR0xBRisy - RlN3SGwyTXJuZExNOXV0Q0pPSk40THMKLS0tIHk5OXU3bTdUNzVMRVliWEZUaElP - UDQ3VG5mZzhGd21iYzl3L3N2UnF5bWMKllktgXwodYZEJypAC3C/VOATVlVsB8m+ - t3/WUeAe913Mhbxg11v2PekSFiUhv3Hh8Uz5FT4XJYeyXWl8UoS4jg== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-05T19:29:59Z" - mac: ENC[AES256_GCM,data:aRwx2MCtVXUdKXiogYZ9c61FYH4MTMXCwuPmW6neHAhwKc962u01Bje6Zqypc74iddmCz3QCADs5OhkL6sT7utTmM1oJKBUfYwxh8udabWP5WRE/bmW1xXMLQsYW2j++uC0OJuZNQliOSo+Rw+6hwbVVezI/dNBG6ki87eyT6K0=,iv:D5/nJ9enZ1CO4wBcRiKSILezYWywD1bTiDSZJps7hA0=,tag:stneW8K4u/vsxW9k++g+lA==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/tests/stdlib/docker/compose/directory/testdata/Dockerfile b/tests/stdlib/docker/compose/directory/testdata/Dockerfile deleted file mode 100644 index 25d4c068..00000000 --- a/tests/stdlib/docker/compose/directory/testdata/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:12-alpine - -WORKDIR /app - -COPY package.json package.json - -RUN npm install - -COPY . . - -ENV PORT=8080 - -EXPOSE 8080 - -CMD ["npm", "start"] \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml b/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml deleted file mode 100644 index b091d2e1..00000000 --- a/tests/stdlib/docker/compose/directory/testdata/docker-compose.yaml +++ /dev/null @@ -1,7 +0,0 @@ -version: "3" - -services: - api: - build: . - ports: - - "8080:8080" \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/index.ts b/tests/stdlib/docker/compose/directory/testdata/index.ts deleted file mode 100644 index d37fe572..00000000 --- a/tests/stdlib/docker/compose/directory/testdata/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import express from "express"; -import { get } from "env-var"; - - -const app = express(); - -const port: number = get('PORT').required().asPortNumber(); - -app.get('/ping', (req, res) => { - res.status(200).send('pong') -}); - -app.listen(port, '0.0.0.0', () => console.log("Server listen on http://localhost:" + port)); \ No newline at end of file diff --git a/tests/stdlib/docker/compose/directory/testdata/package.json b/tests/stdlib/docker/compose/directory/testdata/package.json deleted file mode 100644 index c2be41f2..00000000 --- a/tests/stdlib/docker/compose/directory/testdata/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "test", - "version": "1.0.0", - "description": "A simple api", - "main": "index.ts", - "scripts": { - "build": "tsc", - "start": "ts-node index.ts", - "test": "test" - }, - "author": "Tom Chauveau", - "license": "ISC", - "devDependencies": { - "ts-node": "^8.9.1", - "typescript": "^3.8.3" - }, - "dependencies": { - "@types/express": "^4.17.6", - "env-var": "^6.1.1", - "express": "^4.17.1" - } -} diff --git a/tests/stdlib/docker/compose/directory/testdata/tsconfig.json b/tests/stdlib/docker/compose/directory/testdata/tsconfig.json deleted file mode 100644 index 98907427..00000000 --- a/tests/stdlib/docker/compose/directory/testdata/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "sourceMap": true, - "outDir": "dist", - "strict": true, - "lib": [ - "esnext", - "dom" - ], - "esModuleInterop": true - } -} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue deleted file mode 100644 index 1d43884d..00000000 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/cleanup.cue +++ /dev/null @@ -1,86 +0,0 @@ -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 - cd /context - 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 - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue deleted file mode 100644 index 7e318989..00000000 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/compose.cue +++ /dev/null @@ -1,39 +0,0 @@ -package compose - -import ( - "dagger.io/dagger" - "dagger.io/docker/compose" -) - -repo: dagger.#Artifact - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - context: repo - composeFile: #""" - version: "3" - - services: - api: - build: . - environment: - PORT: 7000 - ports: - - 7000:7000 - """# - } - - //verify: #VerifyCompose & { - // ssh: up.ssh - // port: 7000 - //} - - cleanup: #CleanupCompose & { - context: up - ssh: up.ssh - } -} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue deleted file mode 100644 index 53ac99ff..00000000 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/plan/verify.cue +++ /dev/null @@ -1,121 +0,0 @@ -package compose - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" - "dagger.io/dagger" -) - -#VerifyCompose: { - 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) - } - - port: int | *8080 - - #code: #""" - # Start ssh-agent - eval $(ssh-agent) > /dev/null - - # Add key - if [ -f "/key" ]; then - message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { - >&2 echo "$message" - exit 1 - } - ssh-add /key > /dev/null - if [ "$?" != 0 ]; then - exit 1 - fi - fi - - if [[ ! -z $FINGERPRINT ]]; then - mkdir -p "$HOME"/.ssh - # Add user's fingerprint to known hosts - echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts - else - # Add host to known hosts - ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 - fi - - sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT"/ping > result.txt - grep -q "pong" result.txt - """# - - #up: [ - op.#Load & { - from: alpine.#Image & { - package: { - bash: true - curl: true - "openssh-client": true - } - } - }, - - if ssh.keyPassphrase != _|_ { - op.#WriteFile & { - content: #""" - #!/bin/bash - cat /passphrase - """# - dest: "/get_passphrase" - mode: 0o500 - } - }, - - op.#WriteFile & { - content: #code - dest: "/entrypoint.sh" - }, - - op.#Exec & { - always: true - args: [ - "/bin/sh", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "/entrypoint.sh", - ] - env: { - CONTAINER_PORT: strconv.FormatInt(port, 10) - REMOTE_HOSTNAME: ssh.host - REMOTE_USERNAME: ssh.user - REMOTE_PORT: strconv.FormatInt(ssh.port, 10) - if ssh.keyPassphrase != _|_ { - SSH_ASKPASS: "/get_passphrase" - DISPLAY: "1" - } - if ssh.fingerprint != _|_ { - FINGERPRINT: ssh.fingerprint - } - } - mount: { - "/key": secret: ssh.key - if ssh.keyPassphrase != _|_ { - "/passphrase": secret: ssh.keyPassphrase - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml deleted file mode 100644 index 485db6d9..00000000 --- a/tests/stdlib/docker/compose/mix-context/.dagger/env/default/values.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: default -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:VER9BalLBamLFIvFPCHS5xW6lTjyToNDCmnQu6pSsnsOo6B9WYoZf5KiMfnmRYL99eKiGJAgK67S6jWyiUYCdFBi+wXav+YpvqgWENFP1gSVk3AvoQx2RR403/1D9hFtJd+cQaL2wjUBkGRdjZ2WX//ElBeDAPlcdoLnNvOvITIYsb54elqvkfQdm5yCgwi+EsSkaGresWYUdBxFqhkILUPhJ6hKd/7RyPRyOVCTEK9HxpfY/a6Q7gcLJk1W+mJQLPd1T+Z+GkJuv2Xe1uozazrXDLb+Yt/Cz3TfXwXt2zbE10zoM3dhQ++DC6ZQx+wWOaGhIn8fd4WUb9DM4NqbcSQWxmmbo9mhhRBpP7/ea8EFs8wz0otF/FZy5sK/bThq1ziotUc3i7CWrU4xrwDwK+pYGA7kssXUFzi2mUn9mqH2WoYUAsC24BP5XJjgjz8nqhhx+WnMzYY1RhW7+cAZFvgzAJPmJ3aEv9tyGbdczg2O3n0fboumIP3Rl/99Ld+5JMVzcneHmdS7adH9+CWi19a66o9I0Jxufys1,iv:4D7/IZk3niD8rFbOcZEI0w9Wz6kwS2DCDp9BgW+eoho=,tag:AJdUzma7XAPiqbo7z90OEQ==,type:str] - repo: - dir: - path: ./testdata -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBjSVBlUG54ZlJyRXVVZUVx - dGZOT3FueFkwditJSEY0YytaMkZoSWM0aEZrCmVOM3J1Wnc0VjgwZUJYSndXS255 - dUFUdzhHQy95Nkg1aHZtR3ExL3Y1WncKLS0tIExVZC94aWFCbkZGWkFSdmFNbTRJ - S0p6aEVtOFdKYk03NjUzU21Zdk5GYm8KuPlFhlBq31vMea+RQhBliHlm/iXIGq2u - QsSR6owRh7doEq0PheYz8ypZuqWduj9tuTLqXxCz0djjgsVbvo52LQ== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-05T19:55:53Z" - mac: ENC[AES256_GCM,data:FB0sUdVVYjWeovBYR5K78CGBxUfd8ddsHulWNzNUp/Jf/M6Rd/LBCN0DmneUO2oWI9pgOJYlvgK3EO7xIA42uO9gIyRU1O7ikjhN0pzFcCE7VKVUjBky2p5UQ5m9kvm4RIXYRC0aKkp7NJ8V3XXDrpag21+R5Y/p7iF9/BkdlsU=,iv:bbq/sIa2uSTc3Yu0j/AJ3dmDyn4tSV2JmutFwdi3B/c=,tag:3Rc2FjmX1u/qF6oWiFmKkA==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile b/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile deleted file mode 100644 index 25d4c068..00000000 --- a/tests/stdlib/docker/compose/mix-context/testdata/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM node:12-alpine - -WORKDIR /app - -COPY package.json package.json - -RUN npm install - -COPY . . - -ENV PORT=8080 - -EXPOSE 8080 - -CMD ["npm", "start"] \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml b/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml deleted file mode 100644 index b091d2e1..00000000 --- a/tests/stdlib/docker/compose/mix-context/testdata/docker-compose.yaml +++ /dev/null @@ -1,7 +0,0 @@ -version: "3" - -services: - api: - build: . - ports: - - "8080:8080" \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/index.ts b/tests/stdlib/docker/compose/mix-context/testdata/index.ts deleted file mode 100644 index d37fe572..00000000 --- a/tests/stdlib/docker/compose/mix-context/testdata/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import express from "express"; -import { get } from "env-var"; - - -const app = express(); - -const port: number = get('PORT').required().asPortNumber(); - -app.get('/ping', (req, res) => { - res.status(200).send('pong') -}); - -app.listen(port, '0.0.0.0', () => console.log("Server listen on http://localhost:" + port)); \ No newline at end of file diff --git a/tests/stdlib/docker/compose/mix-context/testdata/package.json b/tests/stdlib/docker/compose/mix-context/testdata/package.json deleted file mode 100644 index c2be41f2..00000000 --- a/tests/stdlib/docker/compose/mix-context/testdata/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "test", - "version": "1.0.0", - "description": "A simple api", - "main": "index.ts", - "scripts": { - "build": "tsc", - "start": "ts-node index.ts", - "test": "test" - }, - "author": "Tom Chauveau", - "license": "ISC", - "devDependencies": { - "ts-node": "^8.9.1", - "typescript": "^3.8.3" - }, - "dependencies": { - "@types/express": "^4.17.6", - "env-var": "^6.1.1", - "express": "^4.17.1" - } -} diff --git a/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json b/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json deleted file mode 100644 index 98907427..00000000 --- a/tests/stdlib/docker/compose/mix-context/testdata/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "sourceMap": true, - "outDir": "dist", - "strict": true, - "lib": [ - "esnext", - "dom" - ], - "esModuleInterop": true - } -} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue deleted file mode 100644 index 1d43884d..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/cleanup.cue +++ /dev/null @@ -1,86 +0,0 @@ -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 - cd /context - 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 - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue deleted file mode 100644 index 04b24173..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/compose.cue +++ /dev/null @@ -1,33 +0,0 @@ -package compose - -import ( - "dagger.io/docker/compose" -) - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - composeFile: #""" - version: "3" - - services: - nginx: - image: nginx:alpine - ports: - - 8080:80 - """# - } - - //verify: #VerifyCompose & { - // ssh: up.ssh - // port: 8080 - //} - - cleanup: #CleanupCompose & { - context: up - ssh: up.ssh - } -} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue deleted file mode 100644 index 24a813ed..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/plan/verify.cue +++ /dev/null @@ -1,121 +0,0 @@ -package compose - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" - "dagger.io/dagger" -) - -#VerifyCompose: { - 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) - } - - port: int | *8080 - - #code: #""" - # Start ssh-agent - eval $(ssh-agent) > /dev/null - - # Add key - if [ -f "/key" ]; then - message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { - >&2 echo "$message" - exit 1 - } - ssh-add /key > /dev/null - if [ "$?" != 0 ]; then - exit 1 - fi - fi - - if [[ ! -z $FINGERPRINT ]]; then - mkdir -p "$HOME"/.ssh - # Add user's fingerprint to known hosts - echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts - else - # Add host to known hosts - ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 - fi - - - sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT" - """# - - #up: [ - op.#Load & { - from: alpine.#Image & { - package: { - bash: true - curl: true - "openssh-client": true - } - } - }, - - if ssh.keyPassphrase != _|_ { - op.#WriteFile & { - content: #""" - #!/bin/bash - cat /passphrase - """# - dest: "/get_passphrase" - mode: 0o500 - } - }, - - op.#WriteFile & { - content: #code - dest: "/entrypoint.sh" - }, - - op.#Exec & { - always: true - args: [ - "/bin/sh", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "/entrypoint.sh", - ] - env: { - CONTAINER_PORT: strconv.FormatInt(port, 10) - REMOTE_HOSTNAME: ssh.host - REMOTE_USERNAME: ssh.user - REMOTE_PORT: strconv.FormatInt(ssh.port, 10) - if ssh.keyPassphrase != _|_ { - SSH_ASKPASS: "/get_passphrase" - DISPLAY: "1" - } - if ssh.fingerprint != _|_ { - FINGERPRINT: ssh.fingerprint - } - } - mount: { - "/key": secret: ssh.key - if ssh.keyPassphrase != _|_ { - "/passphrase": secret: ssh.keyPassphrase - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml deleted file mode 100644 index 01dedc9c..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/values.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: default -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:ixiwG8s0jeEQ2hy6kQmOOYjwTAAaLB9hz0ih8az0mvqPV0HZSWQwOg3OPVgBW9Slk3MZjv6RYc8n2YoanHWZm2WxsA/neSFI7XG/IH/xhLDtxX+wmqrjP4To1KGZ4R4QgVdpA/bhCxXDt9a9lqJSMGGh2mOklRs+vMDhV6kkXbc/dX1ki7JSH754QME3HRdQn6Q7VYDg2ro3Ry/IrOA9uzqNUdAK7GW4ADe3Lez3HPg3jS2vvccHURRfSGnBBbtLa7kgpQdtrAhZuZP6h+6XOJZDZ+/aZSar+nY/CFey+2JnBSAMzZ2MvNy9uoW/NwalT5uN+U/skqdhfVMWVkExb5Pnhpfr44pLBt8uvBwOzZ97XUgI/rgWkmi3efY33A9/vL2ac3HVZSok7XMz8TbwOZM9JU3u3nHx6VS//Mp6c0qXYSrHNlJJeBpF61HGX/rqpYoZC86Sj2AwzuYVsbUwVGwGI9FytJVyp/zCrQaRte0coM1Huy5UKX7KotMIFyQdjtDmsOo5dfjkmxWC+4AB5nwgu+wYz6qUKV7C,iv:T7hpMnKdGirSirC9V/xitgFwhHsuYc9XuHXc7NqX8Eg=,tag:w1jORINS1hyDpOJskHOQ7Q==,type:str] -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAvcFgyV0NXUCthU1B4NE5I - RWRXREZuS3FtbEd3a0p2SHZmNW9QOGpxWG5JClgzamp0SUlkY0E1SytKK2pXb2ts - YzZpZWxWR0lua1g0V3U5Nlk1Y1hIWWsKLS0tIC9MVTZCdDNFUmtnR2RjekZnbnUv - M1czbGlnRmdmaVQxK1h2eGhqSXpJcTQKWl4r3FLuqFkX13ivmsIAsRxoXGGyeu9f - CfkCQ9jc7N6YH4MtEFO33VNJNc+xQDXKzRDVjo0vCxxk12iebi5o3w== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-05T16:01:39Z" - mac: ENC[AES256_GCM,data:CuzfQP5Wg4AJHI83onmg2SYC9U8a/KezVORQH0DLr9BaYRMX/qpxv0+DEqLlWADmaCNcA2NF43FmwcaKybn5SBc4i2GoVfouwIxzfPSvfu3cCH/uyjFVZ4Me0IP6vnd3EGLbZDQgJFV6bBTYSJS6OqVypmFPr6pyaAd1RO5KqfA=,iv:MY3Vdx9BqPC+HIY8Qc4ldu0sjM2rlxy4GEEzIKXyUCk=,tag:jCgDpsf3WZQC3Rlngd1uVg==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue deleted file mode 100644 index 1d43884d..00000000 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/cleanup.cue +++ /dev/null @@ -1,86 +0,0 @@ -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 - cd /context - 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 - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue deleted file mode 100644 index d6c5b586..00000000 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/compose.cue +++ /dev/null @@ -1,35 +0,0 @@ -package compose - -import ( - "dagger.io/git" - "dagger.io/docker/compose" -) - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - context: git.#Repository & { - remote: "https://github.com/dagger/examples" - ref: "main" - subdir: "voteapp" - } - } - - //verifyApp: #VerifyCompose & { - // ssh: up.ssh - // port: 5000 - //} - - //verifyResult: #VerifyCompose & { - // ssh: up.ssh - // port: 5001 - //} - - cleanup: #CleanupCompose & { - context: up - ssh: up.ssh - } -} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue deleted file mode 100644 index c59762b9..00000000 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/plan/verify.cue +++ /dev/null @@ -1,120 +0,0 @@ -package compose - -import ( - "strconv" - - "dagger.io/alpine" - "dagger.io/dagger/op" - "dagger.io/dagger" -) - -#VerifyCompose: { - 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) - } - - port: int | *8080 - - #code: #""" - # Start ssh-agent - eval $(ssh-agent) > /dev/null - - # Add key - if [ -f "/key" ]; then - message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { - >&2 echo "$message" - exit 1 - } - ssh-add /key > /dev/null - if [ "$?" != 0 ]; then - exit 1 - fi - fi - - if [[ ! -z $FINGERPRINT ]]; then - mkdir -p "$HOME"/.ssh - # Add user's fingerprint to known hosts - echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts - else - # Add host to known hosts - ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" /bin/true > /dev/null 2>&1 - fi - - sleep 2 ; ssh -i /key -p "$REMOTE_PORT" "$REMOTE_USERNAME"@"$REMOTE_HOSTNAME" curl -L localhost:"$CONTAINER_PORT" - """# - - #up: [ - op.#Load & { - from: alpine.#Image & { - package: { - bash: true - curl: true - "openssh-client": true - } - } - }, - - if ssh.keyPassphrase != _|_ { - op.#WriteFile & { - content: #""" - #!/bin/bash - cat /passphrase - """# - dest: "/get_passphrase" - mode: 0o500 - } - }, - - op.#WriteFile & { - content: #code - dest: "/entrypoint.sh" - }, - - op.#Exec & { - always: true - args: [ - "/bin/sh", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "/entrypoint.sh", - ] - env: { - CONTAINER_PORT: strconv.FormatInt(port, 10) - REMOTE_HOSTNAME: ssh.host - REMOTE_USERNAME: ssh.user - REMOTE_PORT: strconv.FormatInt(ssh.port, 10) - if ssh.keyPassphrase != _|_ { - SSH_ASKPASS: "/get_passphrase" - DISPLAY: "1" - } - if ssh.fingerprint != _|_ { - FINGERPRINT: ssh.fingerprint - } - } - mount: { - "/key": secret: ssh.key - if ssh.keyPassphrase != _|_ { - "/passphrase": secret: ssh.keyPassphrase - } - } - }, - ] -} diff --git a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml b/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml deleted file mode 100644 index 3d64b33d..00000000 --- a/tests/stdlib/docker/compose/voteapp/.dagger/env/default/values.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: default -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:eLBDG05PNBU5O3ICj7GAgUO4niTgxEGhqo0XvhKlkLnSvys0/MXHMnuRpJdEXypt6V3aoD+iAgOvO4M3JKvxWNagYk45yfjrtCpjW8e/j+pu7zc1IrxJtD++GMfIQ3WZBDHu7bZ4XJWGbVHhEngPjhgJKozgb1GLZQKw0ArgrufIIZ9S4mgYnCytiCjV1M5WFWmI0AVAEgGgQdlvKDUK/k6hcUNb/8bQhXPnlLM7nGjz1yLYaUfScWeDaHSx/NXMwIaadHzR/6naFnEn5xJJZjQ8Y+SkJcLu1fwE2Z5zYuhvqhYdu+36x7gDHTrtf6+eCCitRUU2Mj4RN1g9FzGDCyFuhn/I1E54lhm8N6WcPHLTX1kRIQk/7wLF0zT918YNLoWicXLg4hqOe/D5ew8i+ZLnQJAjzlYKZQawZsaSkhOozSuYFg8pjrTbroX+yg0cipfodt7J1aX0ddgWSuzYQADUDx2iIJwuFxFtQiSJw4IIJiAeKipWsEKKyBHChpDFz3+RIWkzOe0rs/VYf4SKhGAO4oMaOmXtBY6Z,iv:KjCJFkm3rOz55yeIc8pTx6LQqNZselhjsyHIyHps0MY=,tag:/upNvd/QGzU+A86tv7h0AA==,type:str] -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBIUkd0TUY5Zlc5TUJTaEgw - RlEwWU10RWcvOGR2WkRpajh4WWtjUmZYV0U0CjRyQlB2N0paMXdTRXJSRmV5T1lX - WmwzbDZleG9IZXdDMHlLbmhVSTlVYncKLS0tIEJIaitaSUw3LzhkOHVjQVpzd3NV - bWFNREMxU1NVQ01xUmU5cnlER0Fad0UKMkFvd3S/56/k0dw2GYDsGyjBWqy29Mht - ed/N7FxrAkHBnGzfs+A1mMtrrTsrs70sWOsZvxr406Pp+Iue899Q2A== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-05T21:00:42Z" - mac: ENC[AES256_GCM,data:ajVoJ9nInK6kvxxkCpAjMNQ97oZdXgIvscA3R7OlItRA1Xlvu3C6ndU6VoSy6hotR8OJkad2EHfCXDlgrcodXVJcwaqVdCTNDSJLyu8XAIDQKqIpGQwtl6dPrvomE4gmEg3qDC5xPfDV9MNpo1j5M6VyIhrmSJjnWiCg4juIHD4=,iv:FjfWpIHdfQ7gwbM5PBUBVR0LOofRmLvgCpSeMkgGmI4=,tag:FCSHpYrCZR0eLVgy//gI/g==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 From 5029b5d8150568a95c63207e3a846db9d92a029a Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 17 Jun 2021 17:12:24 +0200 Subject: [PATCH 5/8] Refactor compose.#Up definition to use docker.#Command Add some feature to docker.#Command to : - Copy artifact in the container - Write files in the container - Login to registries Signed-off-by: Tom Chauveau --- stdlib/docker/command.cue | 50 +++++++++- stdlib/docker/compose/compose.cue | 148 +++++++----------------------- 2 files changed, 82 insertions(+), 116 deletions(-) diff --git a/stdlib/docker/command.cue b/stdlib/docker/command.cue index e2be5084..05e24676 100644 --- a/stdlib/docker/command.cue +++ b/stdlib/docker/command.cue @@ -62,6 +62,19 @@ import ( [string]: true | false | string @dagger(input) } + // Image registries + registries: [...{ + target?: string + username: string + secret: dagger.#Secret + }] @dagger(input) + + // Copy contents from other artifacts + copy: [string]: from: dagger.#Artifact + + // Write file in the container + files: [string]: string + // Setup docker client and then execute the user command #code: #""" # Setup ssh @@ -103,7 +116,8 @@ import ( #up: [ op.#Load & { from: alpine.#Image & { - package: { + "package": { + package bash: true "openssh-client": true "docker-cli": true @@ -111,6 +125,34 @@ import ( } }, + for registry in registries { + op.#Exec & { + args: ["/bin/bash", "-c", #""" + echo "$TARGER_HOST" | docker login --username "$DOCKER_USERNAME" --password-stdin "$(cat /password)" + """#, + ] + env: { + TARGET_HOST: registry.target + DOCKER_USERNAME: registry.username + } + mount: "/password": secret: registry.password + } + }, + + for dest, content in files { + op.#WriteFile & { + "content": content + "dest": dest + } + }, + + for dest, src in copy { + op.#Copy & { + from: src.from + "dest": dest + } + }, + if ssh.keyPassphrase != _|_ { op.#WriteFile & { content: #""" @@ -137,7 +179,7 @@ import ( op.#Exec & { always: true args: [ - "/bin/sh", + "/bin/bash", "--noprofile", "--norc", "-eo", @@ -146,7 +188,6 @@ import ( ] "env": { env - if ssh != _|_ { DOCKER_HOSTNAME: ssh.host DOCKER_USERNAME: ssh.user @@ -161,6 +202,9 @@ import ( } } "mount": { + if ssh == _|_ { + "/var/run/docker.sock": "docker.sock" + } if ssh != _|_ { if ssh.key != _|_ { "/key": secret: ssh.key diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index 1f93416b..69f423ea 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -3,7 +3,7 @@ package compose import ( "strconv" "dagger.io/dagger" - "dagger.io/dagger/op" + "dagger.io/docker" ) #Up: { @@ -28,7 +28,7 @@ import ( } // Accept either a contaxt, a docker-compose or both together - context?: dagger.#Artifact @dagger(input) + source?: dagger.#Artifact @dagger(input) composeFile?: string @dagger(input) // Image registries @@ -39,121 +39,43 @@ import ( }] @dagger(input) #code: #""" - if [ -n "$DOCKER_HOSTNAME" ]; then - # Start ssh-agent - eval $(ssh-agent) > /dev/null - # Add key - if [ -f "/key" ]; then - message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || { - >&2 echo "$message" - exit 1 - } - ssh-add /key > /dev/null - if [ "$?" != 0 ]; then - exit 1 - fi - fi - if [[ ! -z $FINGERPRINT ]]; then - mkdir -p "$HOME"/.ssh - # Add user's fingerprint to known hosts - echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts - else - # Add host to known hosts - ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" /bin/true > /dev/null 2>&1 - fi - 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" + 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 - # Extend session duration - echo "Host *\nServerAliveInterval 240" >> "$HOME"/.ssh/config - chmod 600 "$HOME"/.ssh/config - - cd /context - docker-compose build - docker-compose up -d + docker-compose build + docker-compose up -d """# - #up: [ - op.#Load & {from: #Client}, - - // Login to registries - for registry in registries { - op.#DockerLogin & {registry} - }, - - if context != _|_ { - op.#Copy & { - from: context - dest: "/context/" - } - }, - - if context == _|_ { - op.#Mkdir & { - path: "/context/" - } - }, - + run: docker.#Command & { + "ssh": ssh + command: #code + package: "docker-compose": true + "registries": registries + if source != _|_ { + copy: "/source": from: source + } if composeFile != _|_ { - op.#WriteFile & { - content: composeFile - dest: "/context/docker-compose.yaml" + files: "/docker-compose.yaml": composeFile + } + env: { + COMPOSE_HTTP_TIMEOUT: strconv.FormatInt(200, 10) + if source != _|_ { + SOURCE_DIR: "source" } - }, - - if ssh.keyPassphrase != _|_ { - op.#WriteFile & { - content: #""" - #!/bin/bash - cat /passphrase - """# - dest: "/get_passphrase" - mode: 0o500 - } - }, - - op.#WriteFile & { - content: #code - dest: "/entrypoint.sh" - }, - - op.#Exec & { - always: true - args: [ - "/bin/sh", - "--noprofile", - "--norc", - "-eo", - "pipefail", - "/entrypoint.sh", - ] - env: { - if ssh != _|_ { - COMPOSE_HTTP_TIMEOUT: strconv.FormatInt(200, 10) - DOCKER_HOSTNAME: ssh.host - DOCKER_USERNAME: ssh.user - DOCKER_PORT: strconv.FormatInt(ssh.port, 10) - if ssh.keyPassphrase != _|_ { - SSH_ASKPASS: "/get_passphrase" - DISPLAY: "1" - } - if ssh.fingerprint != _|_ { - FINGERPRINT: ssh.fingerprint - } - } - } - mount: { - if ssh == _|_ { - "/var/run/docker.sock": "docker.sock" - } - if ssh.key != _|_ { - "/key": secret: ssh.key - } - if ssh.keyPassphrase != _|_ { - "/passphrase": secret: ssh.keyPassphrase - } - } - }, - ] + } + } } From ae209ee0901840e11c7066cff75b6d3fde297b1a Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 17 Jun 2021 17:12:51 +0200 Subject: [PATCH 6/8] Add compose.#Up test in universe Signed-off-by: Tom Chauveau --- docs/reference/universe/docker/README.md | 107 ++++++++++++++++++ docs/reference/universe/docker/compose.md | 36 ++++++ .../env/docker-compose-directory/.gitignore | 2 + .../docker-compose-directory/plan/cleanup.cue | 89 +++++++++++++++ .../docker-compose-directory/plan/compose.cue | 31 +++++ .../env/docker-compose-directory/values.yaml | 29 +++++ .../env/docker-compose-mix-context/.gitignore | 2 + .../plan/cleanup.cue | 89 +++++++++++++++ .../plan/compose.cue | 46 ++++++++ .../docker-compose-mix-context/values.yaml | 29 +++++ .../env/docker-compose-simple/.gitignore | 2 + .../docker-compose-simple/plan/cleanup.cue | 85 ++++++++++++++ .../docker-compose-simple/plan/compose.cue | 37 ++++++ .../env/docker-compose-simple/values.yaml | 26 +++++ stdlib/docker/command.cue | 2 +- stdlib/docker/compose/testdata/Dockerfile | 15 +++ .../compose/testdata/docker-compose.yaml | 7 ++ stdlib/docker/compose/testdata/index.ts | 13 +++ stdlib/docker/compose/testdata/package.json | 22 ++++ stdlib/docker/compose/testdata/tsconfig.json | 12 ++ stdlib/universe.bats | 12 ++ .../.dagger/env/default/state/computed.json | 1 + 22 files changed, 693 insertions(+), 1 deletion(-) create mode 100644 docs/reference/universe/docker/README.md create mode 100644 docs/reference/universe/docker/compose.md create mode 100644 stdlib/.dagger/env/docker-compose-directory/.gitignore create mode 100644 stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue create mode 100644 stdlib/.dagger/env/docker-compose-directory/plan/compose.cue create mode 100644 stdlib/.dagger/env/docker-compose-directory/values.yaml create mode 100644 stdlib/.dagger/env/docker-compose-mix-context/.gitignore create mode 100644 stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue create mode 100644 stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue create mode 100644 stdlib/.dagger/env/docker-compose-mix-context/values.yaml create mode 100644 stdlib/.dagger/env/docker-compose-simple/.gitignore create mode 100644 stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue create mode 100644 stdlib/.dagger/env/docker-compose-simple/plan/compose.cue create mode 100644 stdlib/.dagger/env/docker-compose-simple/values.yaml create mode 100644 stdlib/docker/compose/testdata/Dockerfile create mode 100644 stdlib/docker/compose/testdata/docker-compose.yaml create mode 100644 stdlib/docker/compose/testdata/index.ts create mode 100644 stdlib/docker/compose/testdata/package.json create mode 100644 stdlib/docker/compose/testdata/tsconfig.json create mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json diff --git a/docs/reference/universe/docker/README.md b/docs/reference/universe/docker/README.md new file mode 100644 index 00000000..b465e880 --- /dev/null +++ b/docs/reference/universe/docker/README.md @@ -0,0 +1,107 @@ +--- +sidebar_label: docker +--- + +# dagger.io/docker + +Docker container operations + +```cue +import "dagger.io/docker" +``` + +## docker.#Build + +Build a Docker image from source, using included Dockerfile + +### docker.#Build Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*source* | `dagger.#Artifact` |- | + +### docker.#Build Outputs + +_No output._ + +## docker.#Command + +A container image that can run any docker command + +### docker.#Command Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*command* | `string` |Command to execute | +|*registries* | `[]` |Image registries | + +### docker.#Command Outputs + +_No output._ + +## docker.#ImageFromDockerfile + +Build a Docker image from the provided Dockerfile contents + +### docker.#ImageFromDockerfile Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*dockerfile* | `string` |Dockerfile passed as a string | +|*context* | `dagger.#Artifact` |Build context | + +### docker.#ImageFromDockerfile Outputs + +_No output._ + +## docker.#Pull + +Pull a docker container + +### docker.#Pull Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*from* | `string` |Remote ref (example: "index.docker.io/alpine:latest") | + +### docker.#Pull Outputs + +_No output._ + +## docker.#Push + +Push a docker image + +### docker.#Push Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*ref* | `string` |Remote ref (example: "index.docker.io/alpine:latest") | +|*source* | `dagger.#Artifact` |Image | + +### docker.#Push Outputs + +_No output._ + +## docker.#Run + +### docker.#Run Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*ssh.host* | `string` |ssh host | +|*ssh.user* | `string` |ssh user | +|*ssh.port* | `*22 \| int` |ssh port | +|*ssh.key* | `dagger.#Secret` |private key | +|*ref* | `string` |Image reference (e.g: nginx:alpine) | +|*run.ssh.host* | `string` |ssh host | +|*run.ssh.user* | `string` |ssh user | +|*run.ssh.port* | `*22 \| int` |ssh port | +|*run.ssh.key* | `dagger.#Secret` |private key | +|*run.command* | `"""\n # Run detach container\n OPTS=""\n \n if [ ! -z "$CONTAINER_NAME" ]; then\n \tOPTS="$OPTS --name $CONTAINER_NAME"\n fi\n \n docker container run -d $OPTS "$IMAGE_REF"\n """` |Command to execute | +|*run.env.IMAGE_REF* | `string` |- | +|*run.registries* | `[]` |Image registries | + +### docker.#Run Outputs + +_No output._ diff --git a/docs/reference/universe/docker/compose.md b/docs/reference/universe/docker/compose.md new file mode 100644 index 00000000..97202b74 --- /dev/null +++ b/docs/reference/universe/docker/compose.md @@ -0,0 +1,36 @@ +--- +sidebar_label: compose +--- + +# dagger.io/docker/compose + +```cue +import "dagger.io/docker/compose" +``` + +## compose.#Client + +A container image to run the docker-compose client + +### compose.#Client Inputs + +_No input._ + +### compose.#Client Outputs + +_No output._ + +## compose.#Up + +### compose.#Up Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*registries* | `[]` |Image registries | +|*run.command* | `"""\n if [ -n "$DOCKER_HOSTNAME" ]; then\n \tssh -i /key -fNT -o "StreamLocalBindUnlink=yes" -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME"\n \texport DOCKER_HOST="unix://$(pwd)/docker.sock"\n fi\n \n # Extend session duration\n echo "Host *\\nServerAliveInterval 240" \>\> "$HOME"/.ssh/config\n chmod 600 "$HOME"/.ssh/config\n \n # Move compose\n if [ -d "$SOURCE_DIR" ]; then\n \tif [ -f docker-compose.yaml ]; then\n \t\tcp docker-compose.yaml "$SOURCE_DIR"/docker-compose.yaml\n \tfi\n \tcd "$SOURCE_DIR"\n fi\n \n docker-compose build\n docker-compose up -d\n """` |Command to execute | +|*run.package."docker-compose"* | `true` |- | +|*run.registries* | `[]` |Image registries | + +### compose.#Up Outputs + +_No output._ diff --git a/stdlib/.dagger/env/docker-compose-directory/.gitignore b/stdlib/.dagger/env/docker-compose-directory/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-directory/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue new file mode 100644 index 00000000..a5a0d1bc --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue @@ -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 + } + } + }, + ] +} diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue b/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue new file mode 100644 index 00000000..f252b14d --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue @@ -0,0 +1,31 @@ +package compose + +import ( + "dagger.io/dagger" + "dagger.io/docker" + "dagger.io/docker/compose" +) + +repo: dagger.#Artifact @dagger(input) + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + source: repo + } + + verify: docker.#Command & { + ssh: up.run.ssh + command: #""" + docker container ls | grep "api" | grep "Up" + """# + } + + cleanup: #CleanupCompose & { + context: up.run + ssh: verify.ssh + } +} diff --git a/stdlib/.dagger/env/docker-compose-directory/values.yaml b/stdlib/.dagger/env/docker-compose-directory/values.yaml new file mode 100644 index 00000000..7414c4c2 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-directory/values.yaml @@ -0,0 +1,29 @@ +plan: + module: .dagger/env/docker-compose-directory/plan +name: docker-compose-directory +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:54RfK81pTyk8F52munntMtc34t5fMV83HS+4vhnjYeC203t8AX70NbbxTVOizjI/e+jUjvwabDjrFG/fWfvLvm6kZQQQ1ECg0u71oGdDV4avSdx4mR7YEhUN/Xes/jM+B4B4igDdC25Q6u3DPAOA61e8o/Tv9pRKDpgj6ztKweTdK09wLVguHsuAmBs9lhiMOWWRNWSLZL+N3SxQwb+fZc1lUVyI3Xnth6rvComNdEcJszTrz2mMJNUDM9Zw4OvIXEhiTjByOS+5qqkpl0HOzyX1ktAeU63B0a8PkV90ws/bz1/9IFk6w57owbbJQ6iBXDe4+D8rABPqyYB3XbYzoEAT+u2geBV2e31slhTTJK0OSYIyWY+2sE8fPNXmveFeuxGLGQptTkrUqu21Y3ZQpGYuuEzh+YrpBOP3wXV+HYyMo8YDJIKJECIi7QT8V8bkZ7mbqQQU2M5RxU2/fwBf8LTU5ShLJpPu5jL1obUvqxBOZf7tPVL/5cfYVrjDM25UYqKUMc1N4rGawjJrkRGNi7oH3dc32fZHnRu2,iv:Bcw6vL1YSm1J0aAlsuxB3D4VZKc345Tnuh6vxnUcmSk=,tag:A7mxZNoCXQzMkh9yb/Uhvw==,type:str] + repo: + dir: + path: ./docker/compose/testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBmMjkxUitkQUpYWldlMkdo + Y0R4ZEx2ZVV4WTVic3pzaFBGdGJ3emo5T1hzCllyTXVUMEl5SGx2ekM2eEhrMFpj + MS9wcHRrdnFMWUlTdHdLTTNHZElKZkUKLS0tIDFpWWFoY2JZc25nVE9pbXlOMFpS + MG8yM2VtSldVYzRJZnFsNTJMYXUrWTAKoitUeYU7MDClQo5Rvs/CYcZWzU57QrIk + YrCCEjehmguDoZPKlBowtzwTzNTyTBK3x8hjkj655EPnJIw2P86pjg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-17T13:11:50Z" + mac: ENC[AES256_GCM,data:1x14dBYelWAq3dnOxNVHp/rt2AcKQVejfr/KLuq2PfJqorOO3MD54mBIiX4DVmBak1jzFJ5I4PQxv+7pltHDgYA9NqQaSi6O9zd6c80wKD8NlXDNlLyPpxq1FccX/4yvAyYpxGrvRk0GFbfXpJxWaKE/48Pb0mPQJPdQMYCnA84=,iv:zZsdt2TbExB5c6vsV8PK3yHLfEIICMDjA+lGMJ6rdws=,tag:MHJamBbW+RQ143iAMU5zWQ==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/.dagger/env/docker-compose-mix-context/.gitignore b/stdlib/.dagger/env/docker-compose-mix-context/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-mix-context/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue new file mode 100644 index 00000000..1c2d4bce --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue @@ -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 + } + } + }, + ] +} diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue b/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue new file mode 100644 index 00000000..15c1f901 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue @@ -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 + } +} diff --git a/stdlib/.dagger/env/docker-compose-mix-context/values.yaml b/stdlib/.dagger/env/docker-compose-mix-context/values.yaml new file mode 100644 index 00000000..e4f8343e --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-mix-context/values.yaml @@ -0,0 +1,29 @@ +plan: + module: .dagger/env/docker-compose-mix-context/plan +name: docker-compose-mix-context +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:PFfUg9ViLTNkVbbAUhSk38H3xJwRj2apsxK/pGkHdYbmzSxtwf10R0HcJuRgHY+D/Q8Wy5qNnhByaVePYqpmu28LAMSERcIDqurDX/pDVgyK9dZKCp6Jq+57mVl+PtkyKkYyp/PKWjVI1W6uMSFjjv53OdfUPmygdpcfRiWq2JXRx/SLQtWtfme0QxUPUNVTEnuvmyfA44mZbah6z270rA0/AZyHF1+AKJpY1Dm4y11D1wTamZkAK45EghG0GcUyRjx/PLyIRYzVumcqCUTLMn7frfxjD5ft44C05hL76KJSBEekmsxytj3v7HCvnULEwtsIhcS0imyu139fe9nHPXhTgkJvP2tKZF8P4e65MjHszTema3SUVegCbl5aavms4Z30vRP0kX/sbUVuDktaPMN2bUSBREmbkRBGOKIRHuDDTEgQBRf9eFIMe3Z/kfYjVYRQPiLc+KUhxwXjs43TYebqS+FwzY757h1gvzqdKmtdHK6KI3agmKbgQCmAnvsJEl7C3qlFso8zTgcT0ei2IGHZ86DstMCQFzRU,iv:SgafW/IIOZyyI7uaccDgmERfmiURKX4Z6UGzbRZ5T2s=,tag:XCa3nBhjGch3MjlHRCG4/w==,type:str] + repo: + dir: + path: ./docker/compose/testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMSmROdEtUblF3REhwS3hC + bU9ObTE0aWQzdGJzRlB5WjA0UG5nZFFJTEJjClljQWFYYWNQaFozZGRMcWxyT3p3 + Y0ZVUlZISUNlVkxVSVBqY0RRaGxPN3cKLS0tIGhsUTFCK2ljaWZFekVQMlRSRmtD + bEY3N3ZLTFpUNzZVWVBOK3VNRk9hWlUKd9db3j7FqFW4t7TxFyzudKDPTVqr66v2 + KqedhRYCjF4ZozN0H++xQPH24RBRnwc6Uq0Vm38UYv1ozDN2L/l5DA== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-17T13:12:17Z" + mac: ENC[AES256_GCM,data:dqszDALkWcBoEZKogzVRGZA/L/5ZUrn872KfcXawx/osd7RZXRNI3DhHN10scX7Mu94yIkFBW0V+TBGseFkA/8uZmgS1AEepVf6Z5GB17/kg7tGiFGJFwNIcc2PqpN+1CvK6SYfo2Ro309wUnt+sCIXEwPn9C5XObaAvje1KnZg=,iv:3Xc75g1OFlp6j+mwWWXfyVPE3gXEnLYGza8FdtQ94zc=,tag:dj4Na2g2KEM2Lz8Ws/op/w==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/.dagger/env/docker-compose-simple/.gitignore b/stdlib/.dagger/env/docker-compose-simple/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-simple/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue new file mode 100644 index 00000000..3739d449 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue @@ -0,0 +1,85 @@ +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 + 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 + } + } + }, + ] +} diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue b/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue new file mode 100644 index 00000000..a97505c2 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue @@ -0,0 +1,37 @@ +package compose + +import ( + "dagger.io/docker" + "dagger.io/docker/compose" +) + +TestCompose: { + up: compose.#Up & { + ssh: { + host: "143.198.64.230" + user: "root" + } + composeFile: #""" + version: "3" + + services: + nginx: + image: nginx:alpine + ports: + - 8000:80 + """# + } + + verify: docker.#Command & { + ssh: up.run.ssh + command: #""" + docker container ls | grep "nginx" | grep "Up" + """# + } + + // Can't simply use docker.#Command because we need to keep docker-compose context + cleanup: #CleanupCompose & { + context: up.run + ssh: verify.ssh + } +} diff --git a/stdlib/.dagger/env/docker-compose-simple/values.yaml b/stdlib/.dagger/env/docker-compose-simple/values.yaml new file mode 100644 index 00000000..5bfc5cde --- /dev/null +++ b/stdlib/.dagger/env/docker-compose-simple/values.yaml @@ -0,0 +1,26 @@ +plan: + module: .dagger/env/docker-compose-simple/plan +name: docker-compose-simple +inputs: + TestCompose.up.ssh.key: + secret: ENC[AES256_GCM,data:abxRdizVf/D9A9XI1xnQKaQrwRYHu12Ene3MmyooqxnqLtOB2Y03YtdfL2MAJLB73ulWYAXWOEcefU8+DghnkCQ94EenDNmnbuAJvXOdqgo0g4Uik1jXUpC6D81YQCFQmqTzsNoh0Rom+bKZK8boVVSEyLr7cgjEtAsAfIgns4B0uVe5l5XaHw+vfSXP3hraxZjbXUdv6qPKtkTWzeu2ywvUEzc7zm7XCHXWsZDzuyKaGJThxZu6upiHRuMdsJ7JSNJMdZ9AOAVMTfD0miYFOuj6mdlYshtR+6lWo86i+LKXdILsUi9cerapqvFV+rjN31hS2Y1dY5O0O/rQOhPv7LcbpAKzkQsnY4giKf8oBwfn2v7roA7C+b1P1GeknQZaozckV644mJPLztfukJjhFjZ8qWHkv/jpdetm1FQJSDkBs2o3EqPbZJLFdyvui6g50dNdP48sdzuxONLH8vPwHrkjkUp4QK9mMd/Fhva0G/dgnO49h/pAVqicketnlQnl+V8RUpWAxHVRRAZ4CmGj2M4XtePnPXsTeysi,iv:EftAI98PVgOWaI63T1Isbe0EpjRIxaUYYmAe7i19J8Q=,tag:4OJHMVVfbbY8KNWG4va/pg==,type:str] +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAyMUJoZHN0NVFCd1d1bXUv + ZCtPUmltRmJCcnE3WHhheGRjOE5Yby95Mmd3CmJKTzBQYXNyRHVKcTQrZUNWL3pC + TnNhZmFJeGJCRmJ4UkVMMlZxUnVXV00KLS0tIGN5cWlrdDhGVkVLMlNMNWJVRkEv + ejZLR2dsTFlyQTR4amptL2Npb3R3QTAKpP7FdS2HwfBcCjhHolgDV2aEGII0IUwV + +V3fy0p1JBrhyGif/d2dca7hJGkMv42TgaGy+EHXZWKw+5cbq/XctQ== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-17T11:56:59Z" + mac: ENC[AES256_GCM,data:OPUtKdxQNAB564Zljt7zJ6mITLMpf2qmeGvpMsEGi1Y907wMbBCJ5kgoo1t19nr/gEvyY2zE611dcbs5xEqn47WM1L87VJ+YQOfv2dGFg460LrNGaGgqTS7wxyynnAfRmDHVvIowVps4Qso8QVMOIbbiL/Dyn5ePzoQYQlHhp8s=,iv:XN0T1ukTJRWsvhvRsVUUodkFOfyfVrrV0l3OCQSQ95I=,tag:iK2WvfI+33z7T5p7E/7Tag==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/docker/command.cue b/stdlib/docker/command.cue index 05e24676..e51f1aec 100644 --- a/stdlib/docker/command.cue +++ b/stdlib/docker/command.cue @@ -203,7 +203,7 @@ import ( } "mount": { if ssh == _|_ { - "/var/run/docker.sock": "docker.sock" + "/var/run/docker.sock": from: "docker.sock" } if ssh != _|_ { if ssh.key != _|_ { diff --git a/stdlib/docker/compose/testdata/Dockerfile b/stdlib/docker/compose/testdata/Dockerfile new file mode 100644 index 00000000..25d4c068 --- /dev/null +++ b/stdlib/docker/compose/testdata/Dockerfile @@ -0,0 +1,15 @@ +FROM node:12-alpine + +WORKDIR /app + +COPY package.json package.json + +RUN npm install + +COPY . . + +ENV PORT=8080 + +EXPOSE 8080 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/stdlib/docker/compose/testdata/docker-compose.yaml b/stdlib/docker/compose/testdata/docker-compose.yaml new file mode 100644 index 00000000..908bc744 --- /dev/null +++ b/stdlib/docker/compose/testdata/docker-compose.yaml @@ -0,0 +1,7 @@ +version: "3" + +services: + api: + build: "" + ports: + - "8080:8080" \ No newline at end of file diff --git a/stdlib/docker/compose/testdata/index.ts b/stdlib/docker/compose/testdata/index.ts new file mode 100644 index 00000000..d37fe572 --- /dev/null +++ b/stdlib/docker/compose/testdata/index.ts @@ -0,0 +1,13 @@ +import express from "express"; +import { get } from "env-var"; + + +const app = express(); + +const port: number = get('PORT').required().asPortNumber(); + +app.get('/ping', (req, res) => { + res.status(200).send('pong') +}); + +app.listen(port, '0.0.0.0', () => console.log("Server listen on http://localhost:" + port)); \ No newline at end of file diff --git a/stdlib/docker/compose/testdata/package.json b/stdlib/docker/compose/testdata/package.json new file mode 100644 index 00000000..c2be41f2 --- /dev/null +++ b/stdlib/docker/compose/testdata/package.json @@ -0,0 +1,22 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "A simple api", + "main": "index.ts", + "scripts": { + "build": "tsc", + "start": "ts-node index.ts", + "test": "test" + }, + "author": "Tom Chauveau", + "license": "ISC", + "devDependencies": { + "ts-node": "^8.9.1", + "typescript": "^3.8.3" + }, + "dependencies": { + "@types/express": "^4.17.6", + "env-var": "^6.1.1", + "express": "^4.17.1" + } +} diff --git a/stdlib/docker/compose/testdata/tsconfig.json b/stdlib/docker/compose/testdata/tsconfig.json new file mode 100644 index 00000000..98907427 --- /dev/null +++ b/stdlib/docker/compose/testdata/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "sourceMap": true, + "outDir": "dist", + "strict": true, + "lib": [ + "esnext", + "dom" + ], + "esModuleInterop": true + } +} diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 90548f1b..dba3f033 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -70,6 +70,18 @@ setup() { assert_failure } +@test "docker compose: simple" { + dagger -e docker-compose-simple up +} + +@test "docker compose: directory" { + dagger -e docker-compose-directory up +} + +@test "docker compose: mix-context" { + dagger -e docker-compose-mix-context up +} + @test "docker run: ssh" { dagger -e docker-run-ssh up } diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json b/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json @@ -0,0 +1 @@ +{} From e4ac04c98c676fb03426105915a56e82694589b9 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 25 Jun 2021 13:39:30 +0200 Subject: [PATCH 7/8] Update import to new alpha version Signed-off-by: Tom Chauveau --- docs/reference/universe/README.md | 3 ++- docs/reference/universe/docker/README.md | 4 ++-- docs/reference/universe/docker/compose.md | 4 ++-- .../.dagger/env/docker-compose-directory/plan/cleanup.cue | 4 ++-- .../.dagger/env/docker-compose-directory/plan/compose.cue | 6 +++--- .../.dagger/env/docker-compose-mix-context/plan/cleanup.cue | 4 ++-- .../.dagger/env/docker-compose-mix-context/plan/compose.cue | 6 +++--- stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue | 4 ++-- stdlib/.dagger/env/docker-compose-simple/plan/compose.cue | 4 ++-- stdlib/docker/compose/client.cue | 2 +- stdlib/docker/compose/compose.cue | 4 ++-- 11 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/reference/universe/README.md b/docs/reference/universe/README.md index baff9870..0b469724 100644 --- a/docs/reference/universe/README.md +++ b/docs/reference/universe/README.md @@ -11,7 +11,8 @@ - [aws/s3](./aws/s3.md) - AWS Simple Storage Service - [dagger](./dagger/README.md) - Dagger core types - [dagger/op](./dagger/op.md) - op: low-level operations for Dagger processing pipelines -- [docker](./docker.md) - Docker container operations +- [docker](./docker/README.md) - Docker container operations +- [docker/compose](./docker/compose.md) - - - [gcp](./gcp/README.md) - Google Cloud Platform - [gcp/gcr](./gcp/gcr.md) - Google Container Registry - [gcp/gke](./gcp/gke.md) - Google Kubernetes Engine diff --git a/docs/reference/universe/docker/README.md b/docs/reference/universe/docker/README.md index b465e880..6ec5f28c 100644 --- a/docs/reference/universe/docker/README.md +++ b/docs/reference/universe/docker/README.md @@ -2,12 +2,12 @@ sidebar_label: docker --- -# dagger.io/docker +# alpha.dagger.io/docker Docker container operations ```cue -import "dagger.io/docker" +import "alpha.dagger.io/docker" ``` ## docker.#Build diff --git a/docs/reference/universe/docker/compose.md b/docs/reference/universe/docker/compose.md index 97202b74..f84c1569 100644 --- a/docs/reference/universe/docker/compose.md +++ b/docs/reference/universe/docker/compose.md @@ -2,10 +2,10 @@ sidebar_label: compose --- -# dagger.io/docker/compose +# alpha.dagger.io/docker/compose ```cue -import "dagger.io/docker/compose" +import "alpha.dagger.io/docker/compose" ``` ## compose.#Client diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue index a5a0d1bc..23bde63b 100644 --- a/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue +++ b/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue @@ -3,8 +3,8 @@ package compose import ( "strconv" - "dagger.io/dagger" - "dagger.io/dagger/op" + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" ) #CleanupCompose: { diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue b/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue index f252b14d..48a72dd1 100644 --- a/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue +++ b/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue @@ -1,9 +1,9 @@ package compose import ( - "dagger.io/dagger" - "dagger.io/docker" - "dagger.io/docker/compose" + "alpha.dagger.io/dagger" + "alpha.dagger.io/docker" + "alpha.dagger.io/docker/compose" ) repo: dagger.#Artifact @dagger(input) diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue index 1c2d4bce..58b8a59b 100644 --- a/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue +++ b/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue @@ -3,8 +3,8 @@ package compose import ( "strconv" - "dagger.io/dagger" - "dagger.io/dagger/op" + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" ) #CleanupCompose: { diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue b/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue index 15c1f901..e5808565 100644 --- a/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue +++ b/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue @@ -1,9 +1,9 @@ package compose import ( - "dagger.io/dagger" - "dagger.io/docker" - "dagger.io/docker/compose" + "alpha.dagger.io/dagger" + "alpha.dagger.io/docker" + "alpha.dagger.io/docker/compose" ) repo: dagger.#Artifact diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue index 3739d449..9b9eb4d5 100644 --- a/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue +++ b/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue @@ -3,8 +3,8 @@ package compose import ( "strconv" - "dagger.io/dagger" - "dagger.io/dagger/op" + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" ) #CleanupCompose: { diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue b/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue index a97505c2..1555c2c0 100644 --- a/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue +++ b/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue @@ -1,8 +1,8 @@ package compose import ( - "dagger.io/docker" - "dagger.io/docker/compose" + "alpha.dagger.io/docker" + "alpha.dagger.io/docker/compose" ) TestCompose: { diff --git a/stdlib/docker/compose/client.cue b/stdlib/docker/compose/client.cue index 99eec7ba..504462cf 100644 --- a/stdlib/docker/compose/client.cue +++ b/stdlib/docker/compose/client.cue @@ -1,7 +1,7 @@ package compose import ( - "dagger.io/alpine" + "alpha.dagger.io/alpine" ) // A container image to run the docker-compose client diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index 69f423ea..51a88f81 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -2,8 +2,8 @@ package compose import ( "strconv" - "dagger.io/dagger" - "dagger.io/docker" + "alpha.dagger.io/dagger" + "alpha.dagger.io/docker" ) #Up: { From aaa6f8f3516bef7c81226a9f181630e235aeb412 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 25 Jun 2021 15:40:49 +0200 Subject: [PATCH 8/8] Simplify tests Signed-off-by: Tom Chauveau --- docs/reference/universe/README.md | 2 +- docs/reference/universe/docker.md | 105 ------------------ docs/reference/universe/docker/compose.md | 32 +++--- .../docker-compose-directory/plan/cleanup.cue | 89 --------------- .../docker-compose-directory/plan/compose.cue | 31 ------ .../env/docker-compose-directory/values.yaml | 29 ----- .../env/docker-compose-mix-context/.gitignore | 2 - .../plan/compose.cue | 46 -------- .../docker-compose-mix-context/values.yaml | 29 ----- .../env/docker-compose-simple/.gitignore | 2 - .../docker-compose-simple/plan/cleanup.cue | 85 -------------- .../docker-compose-simple/plan/compose.cue | 37 ------ .../env/docker-compose-simple/values.yaml | 26 ----- .../.gitignore | 0 stdlib/.dagger/env/docker-compose/values.yaml | 34 ++++++ stdlib/docker/compose/compose.cue | 3 +- .../plan => docker/compose/tests}/cleanup.cue | 0 stdlib/docker/compose/tests/compose.cue | 75 +++++++++++++ .../compose/{ => tests}/testdata/Dockerfile | 0 .../{ => tests}/testdata/docker-compose.yaml | 0 .../compose/{ => tests}/testdata/index.ts | 0 .../compose/{ => tests}/testdata/package.json | 0 .../{ => tests}/testdata/tsconfig.json | 0 stdlib/universe.bats | 12 +- .../.dagger/env/default/state/computed.json | 1 - 25 files changed, 131 insertions(+), 509 deletions(-) delete mode 100644 docs/reference/universe/docker.md delete mode 100644 stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue delete mode 100644 stdlib/.dagger/env/docker-compose-directory/plan/compose.cue delete mode 100644 stdlib/.dagger/env/docker-compose-directory/values.yaml delete mode 100644 stdlib/.dagger/env/docker-compose-mix-context/.gitignore delete mode 100644 stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue delete mode 100644 stdlib/.dagger/env/docker-compose-mix-context/values.yaml delete mode 100644 stdlib/.dagger/env/docker-compose-simple/.gitignore delete mode 100644 stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue delete mode 100644 stdlib/.dagger/env/docker-compose-simple/plan/compose.cue delete mode 100644 stdlib/.dagger/env/docker-compose-simple/values.yaml rename stdlib/.dagger/env/{docker-compose-directory => docker-compose}/.gitignore (100%) create mode 100644 stdlib/.dagger/env/docker-compose/values.yaml rename stdlib/{.dagger/env/docker-compose-mix-context/plan => docker/compose/tests}/cleanup.cue (100%) create mode 100644 stdlib/docker/compose/tests/compose.cue rename stdlib/docker/compose/{ => tests}/testdata/Dockerfile (100%) rename stdlib/docker/compose/{ => tests}/testdata/docker-compose.yaml (100%) rename stdlib/docker/compose/{ => tests}/testdata/index.ts (100%) rename stdlib/docker/compose/{ => tests}/testdata/package.json (100%) rename stdlib/docker/compose/{ => tests}/testdata/tsconfig.json (100%) delete mode 100644 tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json diff --git a/docs/reference/universe/README.md b/docs/reference/universe/README.md index 0b469724..27fbc85b 100644 --- a/docs/reference/universe/README.md +++ b/docs/reference/universe/README.md @@ -12,7 +12,7 @@ - [dagger](./dagger/README.md) - Dagger core types - [dagger/op](./dagger/op.md) - op: low-level operations for Dagger processing pipelines - [docker](./docker/README.md) - Docker container operations -- [docker/compose](./docker/compose.md) - - +- [docker/compose](./docker/compose.md) - Docker-compose operations - [gcp](./gcp/README.md) - Google Cloud Platform - [gcp/gcr](./gcp/gcr.md) - Google Container Registry - [gcp/gke](./gcp/gke.md) - Google Kubernetes Engine diff --git a/docs/reference/universe/docker.md b/docs/reference/universe/docker.md deleted file mode 100644 index f146a5a4..00000000 --- a/docs/reference/universe/docker.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -sidebar_label: docker ---- - -# alpha.dagger.io/docker - -Docker container operations - -```cue -import "alpha.dagger.io/docker" -``` - -## docker.#Build - -Build a Docker image from source, using included Dockerfile - -### docker.#Build Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*source* | `dagger.#Artifact` |- | - -### docker.#Build Outputs - -_No output._ - -## docker.#Command - -A container image that can run any docker command - -### docker.#Command Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*command* | `string` |Command to execute | - -### docker.#Command Outputs - -_No output._ - -## docker.#ImageFromDockerfile - -Build a Docker image from the provided Dockerfile contents - -### docker.#ImageFromDockerfile Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*dockerfile* | `string` |Dockerfile passed as a string | -|*context* | `dagger.#Artifact` |Build context | - -### docker.#ImageFromDockerfile Outputs - -_No output._ - -## docker.#Pull - -Pull a docker container - -### docker.#Pull Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*from* | `string` |Remote ref (example: "index.docker.io/alpine:latest") | - -### docker.#Pull Outputs - -_No output._ - -## docker.#Push - -Push a docker image - -### docker.#Push Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*ref* | `string` |Remote ref (example: "index.docker.io/alpine:latest") | -|*source* | `dagger.#Artifact` |Image | - -### docker.#Push Outputs - -_No output._ - -## docker.#Run - -### docker.#Run Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*ssh.host* | `string` |ssh host | -|*ssh.user* | `string` |ssh user | -|*ssh.port* | `*22 \| int` |ssh port | -|*ssh.key* | `dagger.#Secret` |private key | -|*ref* | `string` |Image reference (e.g: nginx:alpine) | -|*run.ssh.host* | `string` |ssh host | -|*run.ssh.user* | `string` |ssh user | -|*run.ssh.port* | `*22 \| int` |ssh port | -|*run.ssh.key* | `dagger.#Secret` |private key | -|*run.command* | `"""\n # Run detach container\n OPTS=""\n \n if [ ! -z "$CONTAINER_NAME" ]; then\n \tOPTS="$OPTS --name $CONTAINER_NAME"\n fi\n \n docker container run -d $OPTS "$IMAGE_REF"\n """` |Command to execute | -|*run.env.IMAGE_REF* | `string` |- | - -### docker.#Run Outputs - -_No output._ diff --git a/docs/reference/universe/docker/compose.md b/docs/reference/universe/docker/compose.md index f84c1569..3cec19a8 100644 --- a/docs/reference/universe/docker/compose.md +++ b/docs/reference/universe/docker/compose.md @@ -4,10 +4,27 @@ sidebar_label: compose # alpha.dagger.io/docker/compose +Docker-compose operations + ```cue import "alpha.dagger.io/docker/compose" ``` +## compose.#App + +### compose.#App Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*registries* | `[]` |Image registries | +|*run.command* | `"""\n if [ -n "$DOCKER_HOSTNAME" ]; then\n \tssh -i /key -fNT -o "StreamLocalBindUnlink=yes" -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME"\n \texport DOCKER_HOST="unix://$(pwd)/docker.sock"\n fi\n \n # Extend session duration\n echo "Host *\\nServerAliveInterval 240" \>\> "$HOME"/.ssh/config\n chmod 600 "$HOME"/.ssh/config\n \n # Move compose\n if [ -d "$SOURCE_DIR" ]; then\n \tif [ -f docker-compose.yaml ]; then\n \t\tcp docker-compose.yaml "$SOURCE_DIR"/docker-compose.yaml\n \tfi\n \tcd "$SOURCE_DIR"\n fi\n \n docker-compose build\n docker-compose up -d\n """` |Command to execute | +|*run.package."docker-compose"* | `true` |- | +|*run.registries* | `[]` |Image registries | + +### compose.#App Outputs + +_No output._ + ## compose.#Client A container image to run the docker-compose client @@ -19,18 +36,3 @@ _No input._ ### compose.#Client Outputs _No output._ - -## compose.#Up - -### compose.#Up Inputs - -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*registries* | `[]` |Image registries | -|*run.command* | `"""\n if [ -n "$DOCKER_HOSTNAME" ]; then\n \tssh -i /key -fNT -o "StreamLocalBindUnlink=yes" -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME"\n \texport DOCKER_HOST="unix://$(pwd)/docker.sock"\n fi\n \n # Extend session duration\n echo "Host *\\nServerAliveInterval 240" \>\> "$HOME"/.ssh/config\n chmod 600 "$HOME"/.ssh/config\n \n # Move compose\n if [ -d "$SOURCE_DIR" ]; then\n \tif [ -f docker-compose.yaml ]; then\n \t\tcp docker-compose.yaml "$SOURCE_DIR"/docker-compose.yaml\n \tfi\n \tcd "$SOURCE_DIR"\n fi\n \n docker-compose build\n docker-compose up -d\n """` |Command to execute | -|*run.package."docker-compose"* | `true` |- | -|*run.registries* | `[]` |Image registries | - -### compose.#Up Outputs - -_No output._ diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue deleted file mode 100644 index 23bde63b..00000000 --- a/stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue +++ /dev/null @@ -1,89 +0,0 @@ -package compose - -import ( - "strconv" - - "alpha.dagger.io/dagger" - "alpha.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 - } - } - }, - ] -} diff --git a/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue b/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue deleted file mode 100644 index 48a72dd1..00000000 --- a/stdlib/.dagger/env/docker-compose-directory/plan/compose.cue +++ /dev/null @@ -1,31 +0,0 @@ -package compose - -import ( - "alpha.dagger.io/dagger" - "alpha.dagger.io/docker" - "alpha.dagger.io/docker/compose" -) - -repo: dagger.#Artifact @dagger(input) - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - source: repo - } - - verify: docker.#Command & { - ssh: up.run.ssh - command: #""" - docker container ls | grep "api" | grep "Up" - """# - } - - cleanup: #CleanupCompose & { - context: up.run - ssh: verify.ssh - } -} diff --git a/stdlib/.dagger/env/docker-compose-directory/values.yaml b/stdlib/.dagger/env/docker-compose-directory/values.yaml deleted file mode 100644 index 7414c4c2..00000000 --- a/stdlib/.dagger/env/docker-compose-directory/values.yaml +++ /dev/null @@ -1,29 +0,0 @@ -plan: - module: .dagger/env/docker-compose-directory/plan -name: docker-compose-directory -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:54RfK81pTyk8F52munntMtc34t5fMV83HS+4vhnjYeC203t8AX70NbbxTVOizjI/e+jUjvwabDjrFG/fWfvLvm6kZQQQ1ECg0u71oGdDV4avSdx4mR7YEhUN/Xes/jM+B4B4igDdC25Q6u3DPAOA61e8o/Tv9pRKDpgj6ztKweTdK09wLVguHsuAmBs9lhiMOWWRNWSLZL+N3SxQwb+fZc1lUVyI3Xnth6rvComNdEcJszTrz2mMJNUDM9Zw4OvIXEhiTjByOS+5qqkpl0HOzyX1ktAeU63B0a8PkV90ws/bz1/9IFk6w57owbbJQ6iBXDe4+D8rABPqyYB3XbYzoEAT+u2geBV2e31slhTTJK0OSYIyWY+2sE8fPNXmveFeuxGLGQptTkrUqu21Y3ZQpGYuuEzh+YrpBOP3wXV+HYyMo8YDJIKJECIi7QT8V8bkZ7mbqQQU2M5RxU2/fwBf8LTU5ShLJpPu5jL1obUvqxBOZf7tPVL/5cfYVrjDM25UYqKUMc1N4rGawjJrkRGNi7oH3dc32fZHnRu2,iv:Bcw6vL1YSm1J0aAlsuxB3D4VZKc345Tnuh6vxnUcmSk=,tag:A7mxZNoCXQzMkh9yb/Uhvw==,type:str] - repo: - dir: - path: ./docker/compose/testdata -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBmMjkxUitkQUpYWldlMkdo - Y0R4ZEx2ZVV4WTVic3pzaFBGdGJ3emo5T1hzCllyTXVUMEl5SGx2ekM2eEhrMFpj - MS9wcHRrdnFMWUlTdHdLTTNHZElKZkUKLS0tIDFpWWFoY2JZc25nVE9pbXlOMFpS - MG8yM2VtSldVYzRJZnFsNTJMYXUrWTAKoitUeYU7MDClQo5Rvs/CYcZWzU57QrIk - YrCCEjehmguDoZPKlBowtzwTzNTyTBK3x8hjkj655EPnJIw2P86pjg== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-17T13:11:50Z" - mac: ENC[AES256_GCM,data:1x14dBYelWAq3dnOxNVHp/rt2AcKQVejfr/KLuq2PfJqorOO3MD54mBIiX4DVmBak1jzFJ5I4PQxv+7pltHDgYA9NqQaSi6O9zd6c80wKD8NlXDNlLyPpxq1FccX/4yvAyYpxGrvRk0GFbfXpJxWaKE/48Pb0mPQJPdQMYCnA84=,iv:zZsdt2TbExB5c6vsV8PK3yHLfEIICMDjA+lGMJ6rdws=,tag:MHJamBbW+RQ143iAMU5zWQ==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/stdlib/.dagger/env/docker-compose-mix-context/.gitignore b/stdlib/.dagger/env/docker-compose-mix-context/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/stdlib/.dagger/env/docker-compose-mix-context/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue b/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue deleted file mode 100644 index e5808565..00000000 --- a/stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue +++ /dev/null @@ -1,46 +0,0 @@ -package compose - -import ( - "alpha.dagger.io/dagger" - "alpha.dagger.io/docker" - "alpha.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 - } -} diff --git a/stdlib/.dagger/env/docker-compose-mix-context/values.yaml b/stdlib/.dagger/env/docker-compose-mix-context/values.yaml deleted file mode 100644 index e4f8343e..00000000 --- a/stdlib/.dagger/env/docker-compose-mix-context/values.yaml +++ /dev/null @@ -1,29 +0,0 @@ -plan: - module: .dagger/env/docker-compose-mix-context/plan -name: docker-compose-mix-context -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:PFfUg9ViLTNkVbbAUhSk38H3xJwRj2apsxK/pGkHdYbmzSxtwf10R0HcJuRgHY+D/Q8Wy5qNnhByaVePYqpmu28LAMSERcIDqurDX/pDVgyK9dZKCp6Jq+57mVl+PtkyKkYyp/PKWjVI1W6uMSFjjv53OdfUPmygdpcfRiWq2JXRx/SLQtWtfme0QxUPUNVTEnuvmyfA44mZbah6z270rA0/AZyHF1+AKJpY1Dm4y11D1wTamZkAK45EghG0GcUyRjx/PLyIRYzVumcqCUTLMn7frfxjD5ft44C05hL76KJSBEekmsxytj3v7HCvnULEwtsIhcS0imyu139fe9nHPXhTgkJvP2tKZF8P4e65MjHszTema3SUVegCbl5aavms4Z30vRP0kX/sbUVuDktaPMN2bUSBREmbkRBGOKIRHuDDTEgQBRf9eFIMe3Z/kfYjVYRQPiLc+KUhxwXjs43TYebqS+FwzY757h1gvzqdKmtdHK6KI3agmKbgQCmAnvsJEl7C3qlFso8zTgcT0ei2IGHZ86DstMCQFzRU,iv:SgafW/IIOZyyI7uaccDgmERfmiURKX4Z6UGzbRZ5T2s=,tag:XCa3nBhjGch3MjlHRCG4/w==,type:str] - repo: - dir: - path: ./docker/compose/testdata -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMSmROdEtUblF3REhwS3hC - bU9ObTE0aWQzdGJzRlB5WjA0UG5nZFFJTEJjClljQWFYYWNQaFozZGRMcWxyT3p3 - Y0ZVUlZISUNlVkxVSVBqY0RRaGxPN3cKLS0tIGhsUTFCK2ljaWZFekVQMlRSRmtD - bEY3N3ZLTFpUNzZVWVBOK3VNRk9hWlUKd9db3j7FqFW4t7TxFyzudKDPTVqr66v2 - KqedhRYCjF4ZozN0H++xQPH24RBRnwc6Uq0Vm38UYv1ozDN2L/l5DA== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-17T13:12:17Z" - mac: ENC[AES256_GCM,data:dqszDALkWcBoEZKogzVRGZA/L/5ZUrn872KfcXawx/osd7RZXRNI3DhHN10scX7Mu94yIkFBW0V+TBGseFkA/8uZmgS1AEepVf6Z5GB17/kg7tGiFGJFwNIcc2PqpN+1CvK6SYfo2Ro309wUnt+sCIXEwPn9C5XObaAvje1KnZg=,iv:3Xc75g1OFlp6j+mwWWXfyVPE3gXEnLYGza8FdtQ94zc=,tag:dj4Na2g2KEM2Lz8Ws/op/w==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/stdlib/.dagger/env/docker-compose-simple/.gitignore b/stdlib/.dagger/env/docker-compose-simple/.gitignore deleted file mode 100644 index 01ec19b0..00000000 --- a/stdlib/.dagger/env/docker-compose-simple/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger state -state/** diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue b/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue deleted file mode 100644 index 9b9eb4d5..00000000 --- a/stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue +++ /dev/null @@ -1,85 +0,0 @@ -package compose - -import ( - "strconv" - - "alpha.dagger.io/dagger" - "alpha.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 - 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 - } - } - }, - ] -} diff --git a/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue b/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue deleted file mode 100644 index 1555c2c0..00000000 --- a/stdlib/.dagger/env/docker-compose-simple/plan/compose.cue +++ /dev/null @@ -1,37 +0,0 @@ -package compose - -import ( - "alpha.dagger.io/docker" - "alpha.dagger.io/docker/compose" -) - -TestCompose: { - up: compose.#Up & { - ssh: { - host: "143.198.64.230" - user: "root" - } - composeFile: #""" - version: "3" - - services: - nginx: - image: nginx:alpine - ports: - - 8000:80 - """# - } - - verify: docker.#Command & { - ssh: up.run.ssh - command: #""" - docker container ls | grep "nginx" | grep "Up" - """# - } - - // Can't simply use docker.#Command because we need to keep docker-compose context - cleanup: #CleanupCompose & { - context: up.run - ssh: verify.ssh - } -} diff --git a/stdlib/.dagger/env/docker-compose-simple/values.yaml b/stdlib/.dagger/env/docker-compose-simple/values.yaml deleted file mode 100644 index 5bfc5cde..00000000 --- a/stdlib/.dagger/env/docker-compose-simple/values.yaml +++ /dev/null @@ -1,26 +0,0 @@ -plan: - module: .dagger/env/docker-compose-simple/plan -name: docker-compose-simple -inputs: - TestCompose.up.ssh.key: - secret: ENC[AES256_GCM,data:abxRdizVf/D9A9XI1xnQKaQrwRYHu12Ene3MmyooqxnqLtOB2Y03YtdfL2MAJLB73ulWYAXWOEcefU8+DghnkCQ94EenDNmnbuAJvXOdqgo0g4Uik1jXUpC6D81YQCFQmqTzsNoh0Rom+bKZK8boVVSEyLr7cgjEtAsAfIgns4B0uVe5l5XaHw+vfSXP3hraxZjbXUdv6qPKtkTWzeu2ywvUEzc7zm7XCHXWsZDzuyKaGJThxZu6upiHRuMdsJ7JSNJMdZ9AOAVMTfD0miYFOuj6mdlYshtR+6lWo86i+LKXdILsUi9cerapqvFV+rjN31hS2Y1dY5O0O/rQOhPv7LcbpAKzkQsnY4giKf8oBwfn2v7roA7C+b1P1GeknQZaozckV644mJPLztfukJjhFjZ8qWHkv/jpdetm1FQJSDkBs2o3EqPbZJLFdyvui6g50dNdP48sdzuxONLH8vPwHrkjkUp4QK9mMd/Fhva0G/dgnO49h/pAVqicketnlQnl+V8RUpWAxHVRRAZ4CmGj2M4XtePnPXsTeysi,iv:EftAI98PVgOWaI63T1Isbe0EpjRIxaUYYmAe7i19J8Q=,tag:4OJHMVVfbbY8KNWG4va/pg==,type:str] -sops: - kms: [] - gcp_kms: [] - azure_kv: [] - hc_vault: [] - age: - - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk - enc: | - -----BEGIN AGE ENCRYPTED FILE----- - YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAyMUJoZHN0NVFCd1d1bXUv - ZCtPUmltRmJCcnE3WHhheGRjOE5Yby95Mmd3CmJKTzBQYXNyRHVKcTQrZUNWL3pC - TnNhZmFJeGJCRmJ4UkVMMlZxUnVXV00KLS0tIGN5cWlrdDhGVkVLMlNMNWJVRkEv - ejZLR2dsTFlyQTR4amptL2Npb3R3QTAKpP7FdS2HwfBcCjhHolgDV2aEGII0IUwV - +V3fy0p1JBrhyGif/d2dca7hJGkMv42TgaGy+EHXZWKw+5cbq/XctQ== - -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-06-17T11:56:59Z" - mac: ENC[AES256_GCM,data:OPUtKdxQNAB564Zljt7zJ6mITLMpf2qmeGvpMsEGi1Y907wMbBCJ5kgoo1t19nr/gEvyY2zE611dcbs5xEqn47WM1L87VJ+YQOfv2dGFg460LrNGaGgqTS7wxyynnAfRmDHVvIowVps4Qso8QVMOIbbiL/Dyn5ePzoQYQlHhp8s=,iv:XN0T1ukTJRWsvhvRsVUUodkFOfyfVrrV0l3OCQSQ95I=,tag:iK2WvfI+33z7T5p7E/7Tag==,type:str] - pgp: [] - encrypted_suffix: secret - version: 3.7.1 diff --git a/stdlib/.dagger/env/docker-compose-directory/.gitignore b/stdlib/.dagger/env/docker-compose/.gitignore similarity index 100% rename from stdlib/.dagger/env/docker-compose-directory/.gitignore rename to stdlib/.dagger/env/docker-compose/.gitignore diff --git a/stdlib/.dagger/env/docker-compose/values.yaml b/stdlib/.dagger/env/docker-compose/values.yaml new file mode 100644 index 00000000..e05bf4f3 --- /dev/null +++ b/stdlib/.dagger/env/docker-compose/values.yaml @@ -0,0 +1,34 @@ +plan: + module: ./docker/compose + package: ./tests +name: docker-compose +inputs: + TestSSH.host: + text: 143.198.64.230 + TestSSH.key: + secret: ENC[AES256_GCM,data:8heZn3UqcB0aV9XAn9uLx9gBcTqbmfNX7voBpYCNCGaX1nustSzKhbR29dxAoETIdfSFPetX2s4cCYbPTqFc6KTyRvfdmI8tXvb5+lin/CkdQJy7cR+RiynLEfbs32EPQilaph+kyGyGBAWAme49g8U2om/QObxCSes+Zn8ihfv7lBkLEj8hen2OC7YwIqjs9V8ozNCJ0zsk+NIk5LkryXdWTaYvgGHOmO/NuWz411L/pF1HieOV1L4Fe6E5hsUun0kVny8GxXQSbVCKle9A9TxD2bs+IBVNAUZVTsrjZYyTjYlNNgTaOqPASS5VDrOtR8csrGJ6GyGxtGrtRdhaoXYQA1zfA7uMfSMNlCwk3VB70P60s0U9tKr3HnRFX6rQdKcUwR2a1zbJ8UmHPy9apsM+tc+m/CAb8dkdu6UyiwvBK+kyPDyBVz4rwyhmtiB7cjw9vXYWX3hbZcE0e3RR4Upqw5NkIIlLfNH7T1fPDmVmIlXQk0wKIZJ//dwdJZyrraA+RRtG5b3PECSojIN3x57LnHdIXfp5drHK,iv:xqGFk9QgC6YwqFODSLRwShf+SMyY4PmtfWt5neHwfSY=,tag:vVZtGty5ehLvYzd8H0+Xsw==,type:str] + TestSSH.user: + text: root + repo: + dir: + path: ./docker/compose/tests/testdata +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMSmROdEtUblF3REhwS3hC + bU9ObTE0aWQzdGJzRlB5WjA0UG5nZFFJTEJjClljQWFYYWNQaFozZGRMcWxyT3p3 + Y0ZVUlZISUNlVkxVSVBqY0RRaGxPN3cKLS0tIGhsUTFCK2ljaWZFekVQMlRSRmtD + bEY3N3ZLTFpUNzZVWVBOK3VNRk9hWlUKd9db3j7FqFW4t7TxFyzudKDPTVqr66v2 + KqedhRYCjF4ZozN0H++xQPH24RBRnwc6Uq0Vm38UYv1ozDN2L/l5DA== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-06-25T13:17:45Z" + mac: ENC[AES256_GCM,data:RclYzWUgBU06881KztfHdaeBtHLOiQZ5xNp0taaxS152rUxyXCXEAFlOu/yqE3RvEoorUp473wDwFUa9DudHidY88YNdfdk5AUuZdsOXW4bRMFPF4eiFugqZJNPepaW1YBDUMeH7XQBN1jyEkFOvzyk2KKQhoUshWyrU5QDR2kc=,iv:MjhUSjzVm6nV2PnSNi346GxkirmF3yAti3Jmb94gLGg=,tag:t4fHAYh60//PlkwUPQh2uA==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index 51a88f81..bff531aa 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -1,3 +1,4 @@ +// Docker-compose operations package compose import ( @@ -6,7 +7,7 @@ import ( "alpha.dagger.io/docker" ) -#Up: { +#App: { ssh?: { // ssh host host: string @dagger(input) diff --git a/stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue b/stdlib/docker/compose/tests/cleanup.cue similarity index 100% rename from stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue rename to stdlib/docker/compose/tests/cleanup.cue diff --git a/stdlib/docker/compose/tests/compose.cue b/stdlib/docker/compose/tests/compose.cue new file mode 100644 index 00000000..32d4caf5 --- /dev/null +++ b/stdlib/docker/compose/tests/compose.cue @@ -0,0 +1,75 @@ +package compose + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/docker" +) + +repo: dagger.#Artifact @dagger(input) + +TestSSH: { + key: dagger.#Secret @dagger(input) + host: string @dagger(input) + user: string @dagger(input) +} + +TestCompose: { + up: #App & { + ssh: { + key: TestSSH.key + host: TestSSH.host + user: TestSSH.user + } + source: repo + } + + verify: docker.#Command & { + ssh: up.run.ssh + command: #""" + docker container ls | grep "api" | grep "Up" + """# + } + + cleanup: #CleanupCompose & { + context: up.run + ssh: verify.ssh + } +} + +TestInlineCompose: { + up: #App & { + ssh: { + key: TestSSH.key + host: TestSSH.host + user: TestSSH.user + } + 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 + } +} diff --git a/stdlib/docker/compose/testdata/Dockerfile b/stdlib/docker/compose/tests/testdata/Dockerfile similarity index 100% rename from stdlib/docker/compose/testdata/Dockerfile rename to stdlib/docker/compose/tests/testdata/Dockerfile diff --git a/stdlib/docker/compose/testdata/docker-compose.yaml b/stdlib/docker/compose/tests/testdata/docker-compose.yaml similarity index 100% rename from stdlib/docker/compose/testdata/docker-compose.yaml rename to stdlib/docker/compose/tests/testdata/docker-compose.yaml diff --git a/stdlib/docker/compose/testdata/index.ts b/stdlib/docker/compose/tests/testdata/index.ts similarity index 100% rename from stdlib/docker/compose/testdata/index.ts rename to stdlib/docker/compose/tests/testdata/index.ts diff --git a/stdlib/docker/compose/testdata/package.json b/stdlib/docker/compose/tests/testdata/package.json similarity index 100% rename from stdlib/docker/compose/testdata/package.json rename to stdlib/docker/compose/tests/testdata/package.json diff --git a/stdlib/docker/compose/testdata/tsconfig.json b/stdlib/docker/compose/tests/testdata/tsconfig.json similarity index 100% rename from stdlib/docker/compose/testdata/tsconfig.json rename to stdlib/docker/compose/tests/testdata/tsconfig.json diff --git a/stdlib/universe.bats b/stdlib/universe.bats index dba3f033..9aff8a76 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -70,16 +70,8 @@ setup() { assert_failure } -@test "docker compose: simple" { - dagger -e docker-compose-simple up -} - -@test "docker compose: directory" { - dagger -e docker-compose-directory up -} - -@test "docker compose: mix-context" { - dagger -e docker-compose-mix-context up +@test "docker compose" { + dagger -e docker-compose up } @test "docker run: ssh" { diff --git a/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json b/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json +++ /dev/null @@ -1 +0,0 @@ -{}