From 562678779e3b230f5102cd45b5ac9921a6ee2c92 Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 13:48:39 +0100 Subject: [PATCH 1/4] Update `docker.#Dockerfile` to be a 1:1 mirror to `engine.#Dockerfile` Signed-off-by: Vasek - Tom C --- pkg/universe.dagger.io/docker/build.cue | 56 ++++++++++++++++++++----- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/pkg/universe.dagger.io/docker/build.cue b/pkg/universe.dagger.io/docker/build.cue index 9c272b28..2eaccf76 100644 --- a/pkg/universe.dagger.io/docker/build.cue +++ b/pkg/universe.dagger.io/docker/build.cue @@ -61,18 +61,54 @@ import ( // Build step that executes a Dockerfile #Dockerfile: { - // Source directory - source: dagger.#FS + // Source image + input?: #Image - // FIXME: not yet implemented - *{ - // Look for Dockerfile in source at default path - path: "Dockerfile" + // FIXME cannot replace with _source: *engine.#Scratch | input.rootfs + // Got error "$dagger" not found + _source: input.rootfs + if input == _|_ { + _source: engine.#Scratch + } + + // Dockerfile definition or path into source + dockerfile: *{ + path: string | *"Dockerfile" } | { - // Look for Dockerfile in source at a custom path - path: string - } | { - // Custom dockerfile contents contents: string } + + // Registry authentication + // Key must be registry address + auth: [registry=string]: { + username: string + secret: dagger.#Secret + } + + platforms: [...string] + target?: string + buildArg: [string]: string + label: [string]: string + hosts: [string]: string + + _build: engine.#Dockerfile & { + source: _source + "auth": [ for target, creds in auth { + "target": target + creds + }] + "dockerfile": dockerfile + "platforms": platforms + if target != _|_ { + "target": target + } + "buildArg": buildArg + "label": label + "hosts": hosts + } + + output: #Image & { + rootfs: _build.output + config: _build.config + } } From c90be8423e35e363a6abe371d2a5a54c369c978b Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 14:53:06 +0100 Subject: [PATCH 2/4] Add tests on `docker.#Dockerfile` Signed-off-by: Vasek - Tom C --- .../docker/test/build-dockerfile-input.cue | 34 +++++++++++++++++ .../docker/test/build-dockerfile.cue | 37 +++++++++++++++++++ .../docker/test/testdata/Dockerfile | 19 ++++++++++ .../docker/test/testdata/go.mod | 3 ++ .../docker/test/testdata/main.go | 7 ++++ 5 files changed, 100 insertions(+) create mode 100644 pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue create mode 100644 pkg/universe.dagger.io/docker/test/build-dockerfile.cue create mode 100644 pkg/universe.dagger.io/docker/test/testdata/Dockerfile create mode 100644 pkg/universe.dagger.io/docker/test/testdata/go.mod create mode 100644 pkg/universe.dagger.io/docker/test/testdata/main.go diff --git a/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue b/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue new file mode 100644 index 00000000..d8cf7b4e --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue @@ -0,0 +1,34 @@ +package test + +import ( + "dagger.io/dagger" + "dagger.io/dagger/engine" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + inputs: directories: testdata: path: "./testdata" + + actions: { + image: docker.#Build & { + steps: [ + docker.#Dockerfile & { + input: rootfs: inputs.directories.testdata.contents + }, + docker.#Run & { + always: true + script: """ + hello >> /test.txt + """ + }, + ] + } + + verify: engine.#ReadFile & { + input: image.output.rootfs + path: "/test.txt" + } & { + contents: "hello world" + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/build-dockerfile.cue b/pkg/universe.dagger.io/docker/test/build-dockerfile.cue new file mode 100644 index 00000000..eda717cb --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/build-dockerfile.cue @@ -0,0 +1,37 @@ +package test + +import ( + "dagger.io/dagger" + "dagger.io/dagger/engine" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + actions: { + build: docker.#Build & { + steps: [ + docker.#Dockerfile & { + dockerfile: contents: """ + FROM alpine:3.15 + + RUN echo -n hello world >> /test.txt + """ + }, + docker.#Run & { + script: """ + # Verify that docker.#Dockerfile correctly connect output + # into other steps + grep -q "hello world" /test.txt + """ + }, + ] + } + + verify: engine.#ReadFile & { + input: build.output.rootfs + path: "/test.txt" + } & { + contents: "hello world" + } + } +} diff --git a/pkg/universe.dagger.io/docker/test/testdata/Dockerfile b/pkg/universe.dagger.io/docker/test/testdata/Dockerfile new file mode 100644 index 00000000..430a482a --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/testdata/Dockerfile @@ -0,0 +1,19 @@ +### +# STAGE: builder +# Build a simple go program +# GO TO STAGE: app +### +FROM golang:1.17-alpine as builder + +WORKDIR /app + +COPY go.mod . +COPY main.go . + +RUN go build -o hello main.go + +FROM alpine:3.15@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300 + +COPY --from=builder /app/hello /bin/hello + +ENTRYPOINT ["hello"] \ No newline at end of file diff --git a/pkg/universe.dagger.io/docker/test/testdata/go.mod b/pkg/universe.dagger.io/docker/test/testdata/go.mod new file mode 100644 index 00000000..9bacf229 --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/testdata/go.mod @@ -0,0 +1,3 @@ +module test.com + +go 1.17 diff --git a/pkg/universe.dagger.io/docker/test/testdata/main.go b/pkg/universe.dagger.io/docker/test/testdata/main.go new file mode 100644 index 00000000..75b323ab --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/testdata/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Printf("hello world") +} From cc601a4e07b179c7866df152e3dc0f0e2d09fb42 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 17 Feb 2022 17:48:51 +0100 Subject: [PATCH 3/4] Apply Solomon comments - Remove input field - Fix auth consistency - Cleanup test Signed-off-by: Vasek - Tom C --- pkg/universe.dagger.io/cue.mod/pkg/.gitignore | 5 ++ pkg/universe.dagger.io/docker/build.cue | 19 ++--- .../docker/test/build-dockerfile-input.cue | 34 --------- .../docker/test/build-dockerfile.cue | 37 ---------- .../docker/test/dockerfile.cue | 69 +++++++++++++++++++ 5 files changed, 78 insertions(+), 86 deletions(-) create mode 100644 pkg/universe.dagger.io/cue.mod/pkg/.gitignore delete mode 100644 pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue delete mode 100644 pkg/universe.dagger.io/docker/test/build-dockerfile.cue create mode 100644 pkg/universe.dagger.io/docker/test/dockerfile.cue diff --git a/pkg/universe.dagger.io/cue.mod/pkg/.gitignore b/pkg/universe.dagger.io/cue.mod/pkg/.gitignore new file mode 100644 index 00000000..331f139d --- /dev/null +++ b/pkg/universe.dagger.io/cue.mod/pkg/.gitignore @@ -0,0 +1,5 @@ +# generated by dagger +dagger.lock +alpha.dagger.io +dagger.io +universe.dagger.io \ No newline at end of file diff --git a/pkg/universe.dagger.io/docker/build.cue b/pkg/universe.dagger.io/docker/build.cue index 2eaccf76..162315af 100644 --- a/pkg/universe.dagger.io/docker/build.cue +++ b/pkg/universe.dagger.io/docker/build.cue @@ -61,15 +61,7 @@ import ( // Build step that executes a Dockerfile #Dockerfile: { - // Source image - input?: #Image - - // FIXME cannot replace with _source: *engine.#Scratch | input.rootfs - // Got error "$dagger" not found - _source: input.rootfs - if input == _|_ { - _source: engine.#Scratch - } + source: dagger.#FS // Dockerfile definition or path into source dockerfile: *{ @@ -91,12 +83,9 @@ import ( label: [string]: string hosts: [string]: string - _build: engine.#Dockerfile & { - source: _source - "auth": [ for target, creds in auth { - "target": target - creds - }] + _build: dagger.#Dockerfile & { + "source": source + "auth": auth "dockerfile": dockerfile "platforms": platforms if target != _|_ { diff --git a/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue b/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue deleted file mode 100644 index d8cf7b4e..00000000 --- a/pkg/universe.dagger.io/docker/test/build-dockerfile-input.cue +++ /dev/null @@ -1,34 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" -) - -dagger.#Plan & { - inputs: directories: testdata: path: "./testdata" - - actions: { - image: docker.#Build & { - steps: [ - docker.#Dockerfile & { - input: rootfs: inputs.directories.testdata.contents - }, - docker.#Run & { - always: true - script: """ - hello >> /test.txt - """ - }, - ] - } - - verify: engine.#ReadFile & { - input: image.output.rootfs - path: "/test.txt" - } & { - contents: "hello world" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/build-dockerfile.cue b/pkg/universe.dagger.io/docker/test/build-dockerfile.cue deleted file mode 100644 index eda717cb..00000000 --- a/pkg/universe.dagger.io/docker/test/build-dockerfile.cue +++ /dev/null @@ -1,37 +0,0 @@ -package test - -import ( - "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/docker" -) - -dagger.#Plan & { - actions: { - build: docker.#Build & { - steps: [ - docker.#Dockerfile & { - dockerfile: contents: """ - FROM alpine:3.15 - - RUN echo -n hello world >> /test.txt - """ - }, - docker.#Run & { - script: """ - # Verify that docker.#Dockerfile correctly connect output - # into other steps - grep -q "hello world" /test.txt - """ - }, - ] - } - - verify: engine.#ReadFile & { - input: build.output.rootfs - path: "/test.txt" - } & { - contents: "hello world" - } - } -} diff --git a/pkg/universe.dagger.io/docker/test/dockerfile.cue b/pkg/universe.dagger.io/docker/test/dockerfile.cue new file mode 100644 index 00000000..73982fb3 --- /dev/null +++ b/pkg/universe.dagger.io/docker/test/dockerfile.cue @@ -0,0 +1,69 @@ +package docker + +import ( + "dagger.io/dagger" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + inputs: directories: testdata: path: "./testdata" + + actions: tests: dockerfile: { + simple: { + build: docker.#Build & { + steps: [ + docker.#Dockerfile & { + source: dagger.#Scratch + dockerfile: contents: """ + FROM alpine:3.15 + + RUN echo -n hello world >> /test.txt + """ + }, + docker.#Run & { + command: { + name: "/bin/sh" + args: ["-c", """ + # Verify that docker.#Dockerfile correctly connect output + # into other steps + grep -q "hello world" /test.txt + """] + } + }, + ] + } + + verify: dagger.#ReadFile & { + input: build.output.rootfs + path: "/test.txt" + } & { + contents: "hello world" + } + } + + withInput: { + build: docker.#Build & { + steps: [ + docker.#Dockerfile & { + source: inputs.directories.testdata.contents + }, + docker.#Run & { + command: { + name: "/bin/sh" + args: ["-c", """ + hello >> /test.txt + """] + } + }, + ] + } + + verify: dagger.#ReadFile & { + input: build.output.rootfs + path: "/test.txt" + } & { + contents: "hello world" + } + } + } +} From c6da3eeb9e8f99cf9aa51bf7dc99fd19aba2471f Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 18 Mar 2022 12:38:50 +0100 Subject: [PATCH 4/4] Update dockerfile test to use client API Signed-off-by: Vasek - Tom C --- pkg/universe.dagger.io/docker/test/dockerfile.cue | 6 +++--- pkg/universe.dagger.io/docker/test/test.bats | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/universe.dagger.io/docker/test/dockerfile.cue b/pkg/universe.dagger.io/docker/test/dockerfile.cue index 73982fb3..259a86b2 100644 --- a/pkg/universe.dagger.io/docker/test/dockerfile.cue +++ b/pkg/universe.dagger.io/docker/test/dockerfile.cue @@ -6,9 +6,9 @@ import ( ) dagger.#Plan & { - inputs: directories: testdata: path: "./testdata" + client: filesystem: "./testdata": read: contents: dagger.#FS - actions: tests: dockerfile: { + actions: test: dockerfile: { simple: { build: docker.#Build & { steps: [ @@ -45,7 +45,7 @@ dagger.#Plan & { build: docker.#Build & { steps: [ docker.#Dockerfile & { - source: inputs.directories.testdata.contents + source: client.filesystem."./testdata".read.contents }, docker.#Run & { command: { diff --git a/pkg/universe.dagger.io/docker/test/test.bats b/pkg/universe.dagger.io/docker/test/test.bats index f95740d7..bebf70cb 100644 --- a/pkg/universe.dagger.io/docker/test/test.bats +++ b/pkg/universe.dagger.io/docker/test/test.bats @@ -5,5 +5,8 @@ setup() { } @test "docker" { - dagger "do" -p ./ test + dagger "do" -p ./build.cue test + dagger "do" -p ./dockerfile.cue test + dagger "do" -p ./run.cue test + dagger "do" -p ./image.cue test }