Merge pull request #1023 from talentedmrjones/docker-run-publish

Adds support for ports to docker.#Run
This commit is contained in:
Sam Alba 2021-09-29 17:08:33 -07:00 committed by GitHub
commit 999456f12a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 1 deletions

View File

@ -79,7 +79,7 @@ Push a docker image to a remote registry
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*ref* | `string` |Image reference (e.g: nginx:alpine) |
|*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.command* | `"""\n # Run detach container\n OPTS=""\n \n if [ ! -z "$CONTAINER_NAME" ]; then\n \tOPTS="$OPTS --name $CONTAINER_NAME"\n fi\n \n if [ ! -z "$CONTAINER_PORTS" ]; then\n \tOPTS="$OPTS -p $CONTAINER_PORTS"\n fi\n \n docker container run -d $OPTS "$IMAGE_REF"\n """` |Command to execute |
|*run.env.IMAGE_REF* | `string` |- |
|*run.registries* | `[]` |Image registries |

View File

@ -0,0 +1,2 @@
# dagger state
state/**

View File

@ -0,0 +1,23 @@
plan:
package: ./docker/tests/run-ports
name: docker-run-ports
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBpbHY3ZzZjWWdRcVd5UUdT
eFI4UmhTUkd6a0lscDZ3SzVFT2NiSzFRUHhFCnRsRXorSFhjano1WTcrYjlGZElm
S2o1V005SlpSbHBmbjJNZ1I3VTRXVGMKLS0tIEdlMThjcmNGK3VJdXV4anNud21x
TS80V3BnN3BaeDFTRjNBRTAwbWRKcWcK1rH2zWxTQsbSgOs9Ys89ZCP7kVOm1wFe
Kv849q+QOvIy9JPYkGgV16Yr3ijFF7z/h0PCicZRI76WYV/3JnbYmg==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2021-09-28T15:06:47Z"
mac: ENC[AES256_GCM,data:WF2X4RCio9x459Fv4XK/P933cS9uac3kHA2+kfaft++ndxbHOY0zmOhUvNMmzLtJNTXL7oBADWIIqIiFbaaC0pC+xGq1th+woR3LvAVQi5J0rlDTcdMDPT03KOPdOmsXFDow5jzyn8vPsC59VCys0ZmEnmnHIGufnFy2qKVV0bM=,iv:GUrSk66zhDqxx+rVM9zMDfmcaDBSOOMIeCSViS2cuLU=,tag:rgCoWe//hn8xmeRmbc5ybQ==,type:str]
pgp: []
encrypted_suffix: secret
version: 3.7.1

View File

@ -2,6 +2,7 @@
package docker
import (
"strings"
"alpha.dagger.io/dagger"
"alpha.dagger.io/dagger/op"
)
@ -138,6 +139,9 @@ import (
secret: dagger.#Secret
} & dagger.#Input
// local ports
ports?: [...string]
#command: #"""
# Run detach container
OPTS=""
@ -146,6 +150,10 @@ import (
OPTS="$OPTS --name $CONTAINER_NAME"
fi
if [ ! -z "$CONTAINER_PORTS" ]; then
OPTS="$OPTS -p $CONTAINER_PORTS"
fi
docker container run -d $OPTS "$IMAGE_REF"
"""#
@ -163,6 +171,10 @@ import (
if name != _|_ {
CONTAINER_NAME: name
}
if ports != _|_ {
CONTAINER_PORTS: strings.Join(ports, " -p ")
}
}
}
}

View File

@ -0,0 +1,17 @@
package docker
import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/random"
)
suffix: random.#String & {
seed: ""
}
run: #Run & {
name: "daggerci-test-ports-\(suffix.out)"
ref: "nginx"
socket: dagger.#Stream & {unix: "/var/run/docker.sock"}
ports: ["8080:80"]
}

View File

@ -79,6 +79,15 @@ setup() {
dagger -e docker-run-local up
}
@test "docker run: ports" {
dagger -e docker-run-ports up
CONTAINER=$(docker container ls -q --filter "name=daggerci-test-ports-*")
until docker inspect --format "{{json .State.Status }}" "$CONTAINER" | grep -m 1 "running"; do sleep 1 ; done
run curl -f -LI http://localhost:8080
assert_output --partial '200 OK'
docker stop "$CONTAINER" && docker rm "$CONTAINER"
}
@test "docker build" {
dagger -e docker-build up
}