Add compose.#Up test in universe
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
5029b5d815
commit
ae209ee090
107
docs/reference/universe/docker/README.md
Normal file
107
docs/reference/universe/docker/README.md
Normal file
@ -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._
|
36
docs/reference/universe/docker/compose.md
Normal file
36
docs/reference/universe/docker/compose.md
Normal file
@ -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._
|
2
stdlib/.dagger/env/docker-compose-directory/.gitignore
vendored
Normal file
2
stdlib/.dagger/env/docker-compose-directory/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# dagger state
|
||||
state/**
|
89
stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue
vendored
Normal file
89
stdlib/.dagger/env/docker-compose-directory/plan/cleanup.cue
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
#CleanupCompose: {
|
||||
// docker-compose up context
|
||||
context: dagger.#Artifact
|
||||
|
||||
ssh: {
|
||||
// ssh host
|
||||
host: string @dagger(input)
|
||||
|
||||
// ssh user
|
||||
user: string @dagger(input)
|
||||
|
||||
// ssh port
|
||||
port: *22 | int @dagger(input)
|
||||
|
||||
// private key
|
||||
key: dagger.#Secret @dagger(input)
|
||||
|
||||
// fingerprint
|
||||
fingerprint?: string @dagger(input)
|
||||
|
||||
// ssh key passphrase
|
||||
keyPassphrase?: dagger.#Secret @dagger(input)
|
||||
}
|
||||
|
||||
#code: #"""
|
||||
# Export host
|
||||
export DOCKER_HOST="unix://$(pwd)/docker.sock"
|
||||
|
||||
# Start ssh agent
|
||||
eval $(ssh-agent) > /dev/null
|
||||
ssh-add /key > /dev/null
|
||||
|
||||
ssh -i /key -o "StreamLocalBindUnlink=yes" -fNT -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" || true
|
||||
|
||||
# Down
|
||||
if [ -d source ]; then
|
||||
cd /source
|
||||
fi
|
||||
|
||||
docker-compose down -v
|
||||
"""#
|
||||
|
||||
#up: [
|
||||
op.#Load & {from: context},
|
||||
|
||||
op.#WriteFile & {
|
||||
content: #code
|
||||
dest: "/entrypoint.sh"
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/sh",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"/entrypoint.sh",
|
||||
]
|
||||
env: {
|
||||
DOCKER_HOSTNAME: ssh.host
|
||||
DOCKER_USERNAME: ssh.user
|
||||
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
|
||||
if ssh.keyPassphrase != _|_ {
|
||||
SSH_ASKPASS: "/get_passphrase"
|
||||
DISPLAY: "1"
|
||||
}
|
||||
}
|
||||
mount: {
|
||||
if ssh.key != _|_ {
|
||||
"/key": secret: ssh.key
|
||||
}
|
||||
if ssh.keyPassphrase != _|_ {
|
||||
"/passphrase": secret: ssh.keyPassphrase
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
31
stdlib/.dagger/env/docker-compose-directory/plan/compose.cue
vendored
Normal file
31
stdlib/.dagger/env/docker-compose-directory/plan/compose.cue
vendored
Normal file
@ -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
|
||||
}
|
||||
}
|
29
stdlib/.dagger/env/docker-compose-directory/values.yaml
vendored
Normal file
29
stdlib/.dagger/env/docker-compose-directory/values.yaml
vendored
Normal file
@ -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
|
2
stdlib/.dagger/env/docker-compose-mix-context/.gitignore
vendored
Normal file
2
stdlib/.dagger/env/docker-compose-mix-context/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# dagger state
|
||||
state/**
|
89
stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue
vendored
Normal file
89
stdlib/.dagger/env/docker-compose-mix-context/plan/cleanup.cue
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
#CleanupCompose: {
|
||||
// docker-compose up context
|
||||
context: dagger.#Artifact
|
||||
|
||||
ssh: {
|
||||
// ssh host
|
||||
host: string @dagger(input)
|
||||
|
||||
// ssh user
|
||||
user: string @dagger(input)
|
||||
|
||||
// ssh port
|
||||
port: *22 | int @dagger(input)
|
||||
|
||||
// private key
|
||||
key: dagger.#Secret @dagger(input)
|
||||
|
||||
// fingerprint
|
||||
fingerprint?: string @dagger(input)
|
||||
|
||||
// ssh key passphrase
|
||||
keyPassphrase?: dagger.#Secret @dagger(input)
|
||||
}
|
||||
|
||||
#code: #"""
|
||||
# Export host
|
||||
export DOCKER_HOST="unix://$(pwd)/docker.sock"
|
||||
|
||||
# Start ssh agent
|
||||
eval $(ssh-agent) > /dev/null
|
||||
ssh-add /key > /dev/null
|
||||
|
||||
ssh -i /key -o "StreamLocalBindUnlink=yes" -fNT -L "$(pwd)"/docker.sock:/var/run/docker.sock -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" || true
|
||||
|
||||
# Down
|
||||
if [ -d /source ]; then
|
||||
cd /source
|
||||
fi
|
||||
|
||||
docker-compose down -v
|
||||
"""#
|
||||
|
||||
#up: [
|
||||
op.#Load & {from: context},
|
||||
|
||||
op.#WriteFile & {
|
||||
content: #code
|
||||
dest: "/entrypoint.sh"
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/sh",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"/entrypoint.sh",
|
||||
]
|
||||
env: {
|
||||
DOCKER_HOSTNAME: ssh.host
|
||||
DOCKER_USERNAME: ssh.user
|
||||
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
|
||||
if ssh.keyPassphrase != _|_ {
|
||||
SSH_ASKPASS: "/get_passphrase"
|
||||
DISPLAY: "1"
|
||||
}
|
||||
}
|
||||
mount: {
|
||||
if ssh.key != _|_ {
|
||||
"/key": secret: ssh.key
|
||||
}
|
||||
if ssh.keyPassphrase != _|_ {
|
||||
"/passphrase": secret: ssh.keyPassphrase
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
46
stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue
vendored
Normal file
46
stdlib/.dagger/env/docker-compose-mix-context/plan/compose.cue
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/docker"
|
||||
"dagger.io/docker/compose"
|
||||
)
|
||||
|
||||
repo: dagger.#Artifact
|
||||
|
||||
TestCompose: {
|
||||
up: compose.#Up & {
|
||||
ssh: {
|
||||
host: "143.198.64.230"
|
||||
user: "root"
|
||||
}
|
||||
source: repo
|
||||
composeFile: #"""
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
api-mix:
|
||||
build: .
|
||||
environment:
|
||||
PORT: 7000
|
||||
ports:
|
||||
- 7000:7000
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: mix-context
|
||||
"""#
|
||||
}
|
||||
|
||||
verify: docker.#Command & {
|
||||
ssh: up.run.ssh
|
||||
command: #"""
|
||||
docker container ls | grep "api-mix" | grep "Up"
|
||||
"""#
|
||||
}
|
||||
|
||||
cleanup: #CleanupCompose & {
|
||||
context: up.run
|
||||
ssh: verify.ssh
|
||||
}
|
||||
}
|
29
stdlib/.dagger/env/docker-compose-mix-context/values.yaml
vendored
Normal file
29
stdlib/.dagger/env/docker-compose-mix-context/values.yaml
vendored
Normal file
@ -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
|
2
stdlib/.dagger/env/docker-compose-simple/.gitignore
vendored
Normal file
2
stdlib/.dagger/env/docker-compose-simple/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# dagger state
|
||||
state/**
|
85
stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue
vendored
Normal file
85
stdlib/.dagger/env/docker-compose-simple/plan/cleanup.cue
vendored
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
37
stdlib/.dagger/env/docker-compose-simple/plan/compose.cue
vendored
Normal file
37
stdlib/.dagger/env/docker-compose-simple/plan/compose.cue
vendored
Normal file
@ -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
|
||||
}
|
||||
}
|
26
stdlib/.dagger/env/docker-compose-simple/values.yaml
vendored
Normal file
26
stdlib/.dagger/env/docker-compose-simple/values.yaml
vendored
Normal file
@ -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
|
@ -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 != _|_ {
|
||||
|
15
stdlib/docker/compose/testdata/Dockerfile
vendored
Normal file
15
stdlib/docker/compose/testdata/Dockerfile
vendored
Normal file
@ -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"]
|
7
stdlib/docker/compose/testdata/docker-compose.yaml
vendored
Normal file
7
stdlib/docker/compose/testdata/docker-compose.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
api:
|
||||
build: ""
|
||||
ports:
|
||||
- "8080:8080"
|
13
stdlib/docker/compose/testdata/index.ts
vendored
Normal file
13
stdlib/docker/compose/testdata/index.ts
vendored
Normal file
@ -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));
|
22
stdlib/docker/compose/testdata/package.json
vendored
Normal file
22
stdlib/docker/compose/testdata/package.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
}
|
12
stdlib/docker/compose/testdata/tsconfig.json
vendored
Normal file
12
stdlib/docker/compose/testdata/tsconfig.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"strict": true,
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom"
|
||||
],
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
1
tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json
vendored
Normal file
1
tests/stdlib/docker/compose/simple/.dagger/env/default/state/computed.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{}
|
Reference in New Issue
Block a user