From eaa965127aa73a63940b924efc9473f309897b10 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 21 Sep 2021 17:19:00 -0700 Subject: [PATCH 1/3] stdlib: added support for local docker socket Signed-off-by: Sam Alba --- stdlib/docker/command.cue | 6 ++++++ stdlib/docker/compose/compose.cue | 11 ++++++++++- stdlib/docker/docker.cue | 13 +++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/stdlib/docker/command.cue b/stdlib/docker/command.cue index e51f1aec..ac28e152 100644 --- a/stdlib/docker/command.cue +++ b/stdlib/docker/command.cue @@ -57,6 +57,9 @@ import ( [string]: true @dagger(input) } + // Mount docker socket + socket?: dagger.#Stream @dagger(input) + // Additional packages to install package: { [string]: true | false | string @dagger(input) @@ -213,6 +216,9 @@ import ( "/keyPassphrase": secret: ssh.keyPassphrase } } + if socket != _|_ { + "/var/run/docker.sock": stream: socket + } for dest, o in mount { "\(dest)": o } diff --git a/stdlib/docker/compose/compose.cue b/stdlib/docker/compose/compose.cue index 77067ec2..85d42052 100644 --- a/stdlib/docker/compose/compose.cue +++ b/stdlib/docker/compose/compose.cue @@ -28,6 +28,9 @@ import ( keyPassphrase?: dagger.#Secret @dagger(input) } + // Mount local docker socket + socket?: dagger.#Stream & dagger.#Input + // Accept either a contaxt, a docker-compose or both together source?: dagger.#Artifact @dagger(input) composeFile?: string @dagger(input) @@ -65,7 +68,13 @@ import ( """# run: docker.#Command & { - "ssh": ssh + if ssh != _|_ { + "ssh": ssh + } + if socket != _|_ { + "socket": socket + } + command: #code package: "docker-compose": true "registries": registries diff --git a/stdlib/docker/docker.cue b/stdlib/docker/docker.cue index 98fabd81..00a2d21e 100644 --- a/stdlib/docker/docker.cue +++ b/stdlib/docker/docker.cue @@ -102,7 +102,7 @@ import ( #Run: { // Connect to a remote SSH server - ssh: { + ssh?: { // ssh host host: dagger.#Input & {string} @@ -122,6 +122,9 @@ import ( keyPassphrase?: dagger.#Input & {dagger.#Secret} } + // Mount local docker socket + socket?: dagger.#Stream & dagger.#Input + // Image reference (e.g: nginx:alpine) ref: dagger.#Input & {string} @@ -147,7 +150,13 @@ import ( """# run: #Command & { - "ssh": ssh + if ssh != _|_ { + "ssh": ssh + } + if socket != _|_ { + "socket": socket + } + command: #command env: { IMAGE_REF: ref From 4ccf030db8c894448368ff04b3889d2d97acd171 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 21 Sep 2021 17:21:32 -0700 Subject: [PATCH 2/3] stdlib: tests local docker socket Signed-off-by: Sam Alba --- stdlib/.dagger/env/docker-run-local/values.yaml | 8 ++++++-- stdlib/docker/tests/run-local/local.cue | 8 ++++++-- stdlib/universe.bats | 5 ++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/stdlib/.dagger/env/docker-run-local/values.yaml b/stdlib/.dagger/env/docker-run-local/values.yaml index f6101056..ff2cc435 100644 --- a/stdlib/.dagger/env/docker-run-local/values.yaml +++ b/stdlib/.dagger/env/docker-run-local/values.yaml @@ -1,6 +1,10 @@ plan: package: ./docker/tests/run-local name: docker-run-local +inputs: + dockersocket: + socket: + unix: /var/run/docker.sock sops: kms: [] gcp_kms: [] @@ -16,8 +20,8 @@ sops: cnh2eHU5TzFjVkNvTzUyczFBL0pwTDQK60+wrLmTaD3Ws5ZAXdqBkMjaVP7Iz69k UrkqkMbaUlvvSKK7dB5MuTGEEN6A1viAGal9ZjDHlSobkNPuE24QEA== -----END AGE ENCRYPTED FILE----- - lastmodified: "2021-07-08T09:54:17Z" - mac: ENC[AES256_GCM,data:Fwvi/c8oNOtB8yUl9R0teUibQQLfTyPjhua2DiNhcAZYT1IJeUXnLl+llAGl8hOl5pR1ZLIgbpW46HW6ZBn3bZND0K5/uZL3CNM5+MLlrHzIxy1xFbXXDLYHH0rbRfGmQtSu2b/JKwTiTfbiPSd6VASFtIvoeTU79hQXE2DVmWk=,iv:iFVZvw4KMLOo/u1IrHMF2xZlER2Oqn2RY6pM78o+FyI=,tag:nXJnewaOGz/URq8o8+uYFg==,type:str] + lastmodified: "2021-09-21T23:13:41Z" + mac: ENC[AES256_GCM,data:jF/Uu0y+uXym4UeXfRmzuZvEkqbk12vzByoiMOk2X/lQ+26x5LzWWwso7/2KjAnDonrKaPLChpaBJE89SIyuLKcU43/ttQ3xZK8TBfj7RWU5hT0Bj1kW2w258LLqcvYSrmHsvzh7aigG561LowJYysoHt4Bt6m66mwZq7wjelqA=,iv:toaSdz6F1oNf5ELSP3/aHLEAzyEAXKLZfxJBoR/aBOY=,tag:2xnNbmSsGTsMD0YT1+valA==,type:str] pgp: [] encrypted_suffix: secret version: 3.7.1 diff --git a/stdlib/docker/tests/run-local/local.cue b/stdlib/docker/tests/run-local/local.cue index 36e4f95f..8eb83866 100644 --- a/stdlib/docker/tests/run-local/local.cue +++ b/stdlib/docker/tests/run-local/local.cue @@ -1,14 +1,18 @@ package docker import ( + "alpha.dagger.io/dagger" "alpha.dagger.io/random" ) +dockersocket: dagger.#Stream & dagger.#Input + suffix: random.#String & { seed: "" } run: #Run & { - name: "daggerci-test-local-\(suffix.out)" - ref: "hello-world" + name: "daggerci-test-local-\(suffix.out)" + ref: "hello-world" + socket: dockersocket } diff --git a/stdlib/universe.bats b/stdlib/universe.bats index cb85c73f..d02aac00 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -76,8 +76,7 @@ setup() { } @test "docker run: local" { - skip "Not implemented yet + missing inputs leading to failure" - # dagger -e docker-run-local up + dagger -e docker-run-local up } @test "docker build" { @@ -257,4 +256,4 @@ setup() { @test "azure-stapp" { skip "Azure CI infra not implemented yet - manually tested and working" #dagger -e azure-stapp up -} \ No newline at end of file +} From 0f6a934fd0916986acb10d3a5e1a054074cf850a Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 21 Sep 2021 17:34:51 -0700 Subject: [PATCH 3/3] docs: updated generated content Signed-off-by: Sam Alba --- docs/reference/docker/README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/docs/reference/docker/README.md b/docs/reference/docker/README.md index 197d3a7b..a8c7cedd 100644 --- a/docs/reference/docker/README.md +++ b/docs/reference/docker/README.md @@ -76,20 +76,12 @@ Push a docker image to a remote registry ### 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 | +| 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.env.IMAGE_REF* | `string` |- | +|*run.registries* | `[]` |Image registries | ### docker.#Run Outputs