From 2745e1ae2e9a5250db3de2a78a1bb08bfef24ae5 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 13 Jan 2022 11:31:08 -0700 Subject: [PATCH] refactored Signed-off-by: Richard Jones --- pkg/dagger.io/dagger/engine/image.cue | 43 +++++++++---------- plan/task/dockerfile.go | 18 +------- tests/tasks.bats | 4 +- tests/tasks/dockerfile/build_args.cue | 2 +- tests/tasks/dockerfile/cue.mod/pkg/.gitignore | 2 + tests/tasks/dockerfile/dockerfile_path.cue | 2 +- tests/tasks/dockerfile/image_config.cue | 2 +- tests/tasks/dockerfile/inlined_dockerfile.cue | 2 +- tests/tasks/dockerfile/labels.cue | 2 +- tests/tasks/dockerfile/platform.cue | 2 +- 10 files changed, 31 insertions(+), 48 deletions(-) diff --git a/pkg/dagger.io/dagger/engine/image.cue b/pkg/dagger.io/dagger/engine/image.cue index f0e9ac39..7d2c3a62 100644 --- a/pkg/dagger.io/dagger/engine/image.cue +++ b/pkg/dagger.io/dagger/engine/image.cue @@ -68,38 +68,35 @@ package engine config: #ImageConfig } -// Build a container image using buildkit +// Build a container image using a Dockerfile #Dockerfile: { $dagger: task: _name: "Dockerfile" // Source directory to build source: #FS - { - frontend: "dockerfile" - dockerfile: { - path: string | *"Dockerfile" - } | { - contents: string - } - // Authentication - auth: [...{ - target: string - username: string - secret: string | #Secret - }] - - // FIXME: options ported from op.#DockerBuild - platforms?: [...string] - target?: string - buildArg?: [string]: string - label?: [string]: string - hosts?: [string]: string + *{ + path: string | *"Dockerfile" + } | { + contents: string } - // Root filesystem produced by build + // Authentication + auth: [...{ + target: string + username: string + secret: string | #Secret + }] + + platforms?: [...string] + target?: string + buildArg?: [string]: string + label?: [string]: string + hosts?: [string]: string + + // Root filesystem produced output: #FS - // Container image config produced by build + // Container image config produced config: #ImageConfig } diff --git a/plan/task/dockerfile.go b/plan/task/dockerfile.go index b7a9c3f7..dae8d9a7 100644 --- a/plan/task/dockerfile.go +++ b/plan/task/dockerfile.go @@ -29,20 +29,6 @@ type dockerfileTask struct { } func (t *dockerfileTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { - frontend, err := v.Lookup("frontend").String() - if err != nil { - return nil, err - } - - switch frontend { - case "dockerfile": - return t.dockerfile(ctx, pctx, s, v) - default: - return nil, fmt.Errorf("unsupported frontend %q", frontend) - } -} - -func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { lg := log.Ctx(ctx) // Read auth info @@ -74,7 +60,7 @@ func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Conte dockerfileDef := contextDef // Support inlined dockerfile - if dockerfile := v.Lookup("dockerfile.contents"); dockerfile.Exists() { + if dockerfile := v.Lookup("contents"); dockerfile.Exists() { contents, err := dockerfile.String() if err != nil { return nil, err @@ -147,7 +133,7 @@ func (t *dockerfileTask) dockerfile(ctx context.Context, pctx *plancontext.Conte func (t *dockerfileTask) dockerBuildOpts(v *compiler.Value, pctx *plancontext.Context) (map[string]string, error) { opts := map[string]string{} - if dockerfilePath := v.Lookup("dockerfile.path"); dockerfilePath.Exists() { + if dockerfilePath := v.Lookup("path"); dockerfilePath.Exists() { filename, err := dockerfilePath.String() if err != nil { return nil, err diff --git a/tests/tasks.bats b/tests/tasks.bats index 26b3f76e..49d8b792 100644 --- a/tests/tasks.bats +++ b/tests/tasks.bats @@ -85,9 +85,7 @@ setup() { "$DAGGER" --europa up ./image_config.cue "$DAGGER" --europa up ./labels.cue "$DAGGER" --europa up ./platform.cue - - cd "$TESTDIR" - "$DAGGER" --europa up ./tasks/dockerfile/build_auth.cue + "$DAGGER" --europa up ./build_auth.cue } @test "task: #Scratch" { cd "$TESTDIR"/tasks/scratch diff --git a/tests/tasks/dockerfile/build_args.cue b/tests/tasks/dockerfile/build_args.cue index 7a0fa1df..d99542b3 100644 --- a/tests/tasks/dockerfile/build_args.cue +++ b/tests/tasks/dockerfile/build_args.cue @@ -9,7 +9,7 @@ engine.#Plan & { actions: build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: contents: """ + contents: """ FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d ARG TEST=foo RUN test "${TEST}" = "bar" diff --git a/tests/tasks/dockerfile/cue.mod/pkg/.gitignore b/tests/tasks/dockerfile/cue.mod/pkg/.gitignore index 2d4dc1ae..c88aae2e 100644 --- a/tests/tasks/dockerfile/cue.mod/pkg/.gitignore +++ b/tests/tasks/dockerfile/cue.mod/pkg/.gitignore @@ -1,3 +1,5 @@ # generated by dagger alpha.dagger.io +dagger.io dagger.lock +universe.dagger.io \ No newline at end of file diff --git a/tests/tasks/dockerfile/dockerfile_path.cue b/tests/tasks/dockerfile/dockerfile_path.cue index c15a12fc..42a121dc 100644 --- a/tests/tasks/dockerfile/dockerfile_path.cue +++ b/tests/tasks/dockerfile/dockerfile_path.cue @@ -10,7 +10,7 @@ engine.#Plan & { actions: { build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: path: "./dockerfilepath/Dockerfile.custom" + path: "./dockerfilepath/Dockerfile.custom" } verify: engine.#Exec & { diff --git a/tests/tasks/dockerfile/image_config.cue b/tests/tasks/dockerfile/image_config.cue index a9d399ad..668c0cca 100644 --- a/tests/tasks/dockerfile/image_config.cue +++ b/tests/tasks/dockerfile/image_config.cue @@ -11,7 +11,7 @@ engine.#Plan & { // FIXME: this doesn't test anything beside not crashing build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: contents: """ + contents: """ FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d ENV test foobar CMD /test-cmd diff --git a/tests/tasks/dockerfile/inlined_dockerfile.cue b/tests/tasks/dockerfile/inlined_dockerfile.cue index c14771fc..0dab63d2 100644 --- a/tests/tasks/dockerfile/inlined_dockerfile.cue +++ b/tests/tasks/dockerfile/inlined_dockerfile.cue @@ -10,7 +10,7 @@ engine.#Plan & { actions: { build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: contents: """ + contents: """ FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d RUN echo foobar > /output """ diff --git a/tests/tasks/dockerfile/labels.cue b/tests/tasks/dockerfile/labels.cue index 403314f9..dd3f921a 100644 --- a/tests/tasks/dockerfile/labels.cue +++ b/tests/tasks/dockerfile/labels.cue @@ -11,7 +11,7 @@ engine.#Plan & { // FIXME: this doesn't test anything beside not crashing build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: contents: """ + contents: """ FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d """ label: FOO: "bar" diff --git a/tests/tasks/dockerfile/platform.cue b/tests/tasks/dockerfile/platform.cue index eeddcb38..0fed8a60 100644 --- a/tests/tasks/dockerfile/platform.cue +++ b/tests/tasks/dockerfile/platform.cue @@ -11,7 +11,7 @@ engine.#Plan & { // FIXME: this doesn't test anything beside not crashing build: engine.#Dockerfile & { source: inputs.directories.testdata.contents - dockerfile: contents: """ + contents: """ FROM alpine:latest@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d """ platforms: ["linux/amd64"]