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 9c272b28..162315af 100644 --- a/pkg/universe.dagger.io/docker/build.cue +++ b/pkg/universe.dagger.io/docker/build.cue @@ -61,18 +61,43 @@ import ( // Build step that executes a Dockerfile #Dockerfile: { - // Source directory source: dagger.#FS - // FIXME: not yet implemented - *{ - // Look for Dockerfile in source at default path - path: "Dockerfile" + // 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: dagger.#Dockerfile & { + "source": source + "auth": auth + "dockerfile": dockerfile + "platforms": platforms + if target != _|_ { + "target": target + } + "buildArg": buildArg + "label": label + "hosts": hosts + } + + output: #Image & { + rootfs: _build.output + config: _build.config + } } 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..259a86b2 --- /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 & { + client: filesystem: "./testdata": read: contents: dagger.#FS + + actions: test: 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: client.filesystem."./testdata".read.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" + } + } + } +} 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 } 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") +}