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