Merge pull request #730 from TomChv/fix-compose-tests
Add project management in compose.#App definition
This commit is contained in:
commit
d46804f9ca
@ -14,12 +14,14 @@ import "alpha.dagger.io/docker/compose"
|
||||
|
||||
### 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 |
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*name* | `*"source" \| string` |App name (use as COMPOSE_PROJECT_NAME) |
|
||||
|*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.env.COMPOSE_PROJECT_NAME* | `*"source" \| string` |- |
|
||||
|*run.package."docker-compose"* | `true` |- |
|
||||
|*run.registries* | `[]` |Image registries |
|
||||
|
||||
### compose.#App Outputs
|
||||
|
||||
|
@ -32,6 +32,9 @@ import (
|
||||
source?: dagger.#Artifact @dagger(input)
|
||||
composeFile?: string @dagger(input)
|
||||
|
||||
// App name (use as COMPOSE_PROJECT_NAME)
|
||||
name: *"source" | string @dagger(input)
|
||||
|
||||
// Image registries
|
||||
registries: [...{
|
||||
target?: string
|
||||
@ -74,6 +77,7 @@ import (
|
||||
}
|
||||
env: {
|
||||
COMPOSE_HTTP_TIMEOUT: strconv.FormatInt(200, 10)
|
||||
COMPOSE_PROJECT_NAME: name
|
||||
if source != _|_ {
|
||||
SOURCE_DIR: "source"
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import (
|
||||
// docker-compose up context
|
||||
context: dagger.#Artifact
|
||||
|
||||
// App name (use as COMPOSE_PROJECT_NAME)
|
||||
name: *"source" | string
|
||||
|
||||
ssh: {
|
||||
// ssh host
|
||||
host: string @dagger(input)
|
||||
@ -68,9 +71,10 @@ import (
|
||||
"/entrypoint.sh",
|
||||
]
|
||||
env: {
|
||||
DOCKER_HOSTNAME: ssh.host
|
||||
DOCKER_USERNAME: ssh.user
|
||||
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
|
||||
DOCKER_HOSTNAME: ssh.host
|
||||
DOCKER_USERNAME: ssh.user
|
||||
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
|
||||
COMPOSE_PROJECT_NAME: name
|
||||
if ssh.keyPassphrase != _|_ {
|
||||
SSH_ASKPASS: "/get_passphrase"
|
||||
DISPLAY: "1"
|
||||
|
@ -3,6 +3,7 @@ package compose
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/docker"
|
||||
"alpha.dagger.io/random"
|
||||
)
|
||||
|
||||
repo: dagger.#Artifact @dagger(input)
|
||||
@ -14,6 +15,10 @@ TestSSH: {
|
||||
}
|
||||
|
||||
TestCompose: {
|
||||
suffix: random.#String & {seed: "cmp"}
|
||||
|
||||
name: "compose_test_\(suffix.out)"
|
||||
|
||||
up: #App & {
|
||||
ssh: {
|
||||
key: TestSSH.key
|
||||
@ -21,22 +26,28 @@ TestCompose: {
|
||||
user: TestSSH.user
|
||||
}
|
||||
source: repo
|
||||
"name": name
|
||||
}
|
||||
|
||||
verify: docker.#Command & {
|
||||
ssh: up.run.ssh
|
||||
ssh: up.run.ssh
|
||||
command: #"""
|
||||
docker container ls | grep "api" | grep "Up"
|
||||
docker container ls | grep "\#(name)_api" | grep "Up"
|
||||
"""#
|
||||
}
|
||||
|
||||
cleanup: #CleanupCompose & {
|
||||
context: up.run
|
||||
"name": name
|
||||
ssh: verify.ssh
|
||||
}
|
||||
}
|
||||
|
||||
TestInlineCompose: {
|
||||
suffix: random.#String & {seed: "cmp-inline"}
|
||||
|
||||
name: "inline_test_\(suffix.out)"
|
||||
|
||||
up: #App & {
|
||||
ssh: {
|
||||
key: TestSSH.key
|
||||
@ -44,6 +55,7 @@ TestInlineCompose: {
|
||||
user: TestSSH.user
|
||||
}
|
||||
source: repo
|
||||
"name": name
|
||||
composeFile: #"""
|
||||
version: "3"
|
||||
|
||||
@ -54,22 +66,19 @@ TestInlineCompose: {
|
||||
PORT: 7000
|
||||
ports:
|
||||
- 7000:7000
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: mix-context
|
||||
"""#
|
||||
}
|
||||
|
||||
verify: docker.#Command & {
|
||||
ssh: up.run.ssh
|
||||
ssh: up.run.ssh
|
||||
command: #"""
|
||||
docker container ls | grep "api-mix" | grep "Up"
|
||||
docker container ls | grep "\#(name)_api-mix" | grep "Up"
|
||||
"""#
|
||||
}
|
||||
|
||||
cleanup: #CleanupCompose & {
|
||||
context: up.run
|
||||
"name": name
|
||||
ssh: verify.ssh
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user