From 3e14920062d88949818b72e0ef907c8e2adf8c76 Mon Sep 17 00:00:00 2001 From: Kevin Poirot Date: Tue, 14 Sep 2021 09:54:09 +0200 Subject: [PATCH 1/2] Update Docker #Build to incorporate image from Dockerfile Signed-off-by: Kevin Poirot --- docs/reference/docker/README.md | 24 ++++------------- stdlib/docker/docker.cue | 26 ++++++------------- stdlib/docker/tests/build/dockerfile.cue | 4 +-- .../docker/tests/push-invalid-creds/push.cue | 4 +-- .../docker/tests/push-multi-registry/push.cue | 4 +-- stdlib/docker/tests/push/push.cue | 4 +-- 6 files changed, 21 insertions(+), 45 deletions(-) diff --git a/docs/reference/docker/README.md b/docs/reference/docker/README.md index b59545de..197d3a7b 100644 --- a/docs/reference/docker/README.md +++ b/docs/reference/docker/README.md @@ -12,13 +12,14 @@ import "alpha.dagger.io/docker" ## docker.#Build -Build a Docker image from source, using included Dockerfile +Build a Docker image from source ### docker.#Build Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*source* | `dagger.#Artifact` |- | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*source* | `dagger.#Artifact` |Build context | +|*dockerfile* | `*null \| string` |Dockerfile passed as a string | ### docker.#Build Outputs @@ -39,21 +40,6 @@ A container image that can run any docker command _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 diff --git a/stdlib/docker/docker.cue b/stdlib/docker/docker.cue index 814e68e9..98fabd81 100644 --- a/stdlib/docker/docker.cue +++ b/stdlib/docker/docker.cue @@ -6,15 +6,22 @@ import ( "alpha.dagger.io/dagger/op" ) -// Build a Docker image from source, using included Dockerfile +// Build a Docker image from source #Build: { + // Build context source: dagger.#Input & {dagger.#Artifact} + // Dockerfile passed as a string + dockerfile: dagger.#Input & {*null | string} + args?: [string]: string #up: [ op.#DockerBuild & { context: source + if dockerfile != null { + "dockerfile": dockerfile + } if args != _|_ { buildArg: args } @@ -150,20 +157,3 @@ import ( } } } - -// Build a Docker image from the provided Dockerfile contents -// FIXME: incorporate into #Build -#ImageFromDockerfile: { - // Dockerfile passed as a string - dockerfile: dagger.#Input & {string} - - // Build context - context: dagger.#Input & {dagger.#Artifact} - - #up: [ - op.#DockerBuild & { - "context": context - "dockerfile": dockerfile - }, - ] -} diff --git a/stdlib/docker/tests/build/dockerfile.cue b/stdlib/docker/tests/build/dockerfile.cue index 894f2b66..bd1b8875 100644 --- a/stdlib/docker/tests/build/dockerfile.cue +++ b/stdlib/docker/tests/build/dockerfile.cue @@ -31,12 +31,12 @@ TestBuild: { TestSourceImageFromDockerfile: dagger.#Artifact @dagger(input) TestImageFromDockerfile: { - image: #ImageFromDockerfile & { + image: #Build & { dockerfile: """ FROM alpine COPY test.txt /test.txt """ - context: TestSourceImageFromDockerfile + source: TestSourceImageFromDockerfile } verify: #up: [ diff --git a/stdlib/docker/tests/push-invalid-creds/push.cue b/stdlib/docker/tests/push-invalid-creds/push.cue index eab359d2..770810e0 100644 --- a/stdlib/docker/tests/push-invalid-creds/push.cue +++ b/stdlib/docker/tests/push-invalid-creds/push.cue @@ -17,12 +17,12 @@ TestPush: { target: "daggerio/ci-test:\(tag.out)" - image: #ImageFromDockerfile & { + image: #Build & { dockerfile: """ FROM alpine RUN echo "test" > /test.txt """ - context: "" + source: "" } push: #Push & { diff --git a/stdlib/docker/tests/push-multi-registry/push.cue b/stdlib/docker/tests/push-multi-registry/push.cue index 53c14707..f9228c56 100644 --- a/stdlib/docker/tests/push-multi-registry/push.cue +++ b/stdlib/docker/tests/push-multi-registry/push.cue @@ -18,12 +18,12 @@ TestResources: { // Seed is used to force buildkit execution and not simply use a previous generated string. suffix: random.#String & {seed: "docker multi registry"} - image: #ImageFromDockerfile & { + image: #Build & { dockerfile: """ FROM alpine RUN echo "test" > /test.txt """ - context: "" + source: "" } } diff --git a/stdlib/docker/tests/push/push.cue b/stdlib/docker/tests/push/push.cue index 7cd6d916..5cfc6f9c 100644 --- a/stdlib/docker/tests/push/push.cue +++ b/stdlib/docker/tests/push/push.cue @@ -17,12 +17,12 @@ TestPush: { target: "daggerio/ci-test:\(tag.out)" - image: #ImageFromDockerfile & { + image: #Build & { dockerfile: """ FROM alpine RUN echo "test" > /test.txt """ - context: "" + source: "" } push: #Push & { From a364307f0e6a6b7e5e0fd0c048f19197f83aebc8 Mon Sep 17 00:00:00 2001 From: Kevin Poirot Date: Tue, 14 Sep 2021 10:00:00 +0200 Subject: [PATCH 2/2] Add test build with args to Docker #Build Signed-off-by: Kevin Poirot --- stdlib/docker/tests/build/dockerfile.cue | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/stdlib/docker/tests/build/dockerfile.cue b/stdlib/docker/tests/build/dockerfile.cue index bd1b8875..7928dafe 100644 --- a/stdlib/docker/tests/build/dockerfile.cue +++ b/stdlib/docker/tests/build/dockerfile.cue @@ -28,6 +28,34 @@ TestBuild: { ] } +TestBuildWithArgs: { + image: #Build & { + dockerfile: """ + FROM alpine + ARG TEST + ENV TEST=$TEST + RUN echo "$TEST" > /test.txt + """ + source: "" + args: TEST: "test" + } + + verify: #up: [ + op.#Load & { + from: image + }, + + op.#Exec & { + always: true + args: [ + "sh", "-c", """ + grep -q "test" /test.txt + """, + ] + }, + ] +} + TestSourceImageFromDockerfile: dagger.#Artifact @dagger(input) TestImageFromDockerfile: {