From c90be8423e35e363a6abe371d2a5a54c369c978b Mon Sep 17 00:00:00 2001 From: Vasek - Tom C Date: Fri, 28 Jan 2022 14:53:06 +0100 Subject: [PATCH] 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") +}