From 3003b31be31b37e0cc463c9f1b4b825176b8c08e Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 15:43:58 -0700 Subject: [PATCH 1/7] Make engine.#Scratch a specialization of #FS, rather than a task Signed-off-by: Joel Longtine --- europa-universe/yarn/tests/simple/simple.cue | 2 +- plan/task/scratch.go | 24 -------------------- plancontext/fs.go | 5 ++++ stdlib/europa/dagger/engine/fs.cue | 6 +---- stdlib/europa/dagger/engine/types.cue | 2 +- stdlib/europa/dagger/utils.cue | 5 +--- tests/cue.mod/module.cue | 1 + tests/cue.mod/pkg/.gitignore | 3 +++ tests/plan/outputs/outputs.cue | 4 +--- tests/tasks/scratch/scratch.cue | 4 +--- 10 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 plan/task/scratch.go create mode 100644 tests/cue.mod/module.cue create mode 100644 tests/cue.mod/pkg/.gitignore diff --git a/europa-universe/yarn/tests/simple/simple.cue b/europa-universe/yarn/tests/simple/simple.cue index ce8771b8..19d771b1 100644 --- a/europa-universe/yarn/tests/simple/simple.cue +++ b/europa-universe/yarn/tests/simple/simple.cue @@ -5,7 +5,7 @@ import ( ) b: #Build & { - source: engine.#Scratch.output + source: engine.#Scratch } out: b.output diff --git a/plan/task/scratch.go b/plan/task/scratch.go deleted file mode 100644 index 5c01d626..00000000 --- a/plan/task/scratch.go +++ /dev/null @@ -1,24 +0,0 @@ -package task - -import ( - "context" - - "go.dagger.io/dagger/compiler" - "go.dagger.io/dagger/plancontext" - "go.dagger.io/dagger/solver" -) - -func init() { - Register("Scratch", func() Task { return &scratchTask{} }) -} - -type scratchTask struct { -} - -func (t *scratchTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { - fs := pctx.FS.New(nil) - - return compiler.NewValue().FillFields(map[string]interface{}{ - "output": fs.MarshalCUE(), - }) -} diff --git a/plancontext/fs.go b/plancontext/fs.go index a8f4009f..a0b712fd 100644 --- a/plancontext/fs.go +++ b/plancontext/fs.go @@ -71,6 +71,11 @@ func (c *fsContext) FromValue(v *compiler.Value) (*FS, error) { c.l.RLock() defer c.l.RUnlock() + // This is #Scratch, so we'll return an empty FS + if v.LookupPath(fsIDPath).Kind() == cue.NullKind { + return &FS{}, nil + } + id, err := v.LookupPath(fsIDPath).String() if err != nil { return nil, fmt.Errorf("invalid FS %q: %w", v.Path(), err) diff --git a/stdlib/europa/dagger/engine/fs.cue b/stdlib/europa/dagger/engine/fs.cue index ff4d1d7a..bba15ec3 100644 --- a/stdlib/europa/dagger/engine/fs.cue +++ b/stdlib/europa/dagger/engine/fs.cue @@ -49,11 +49,7 @@ package engine } // Produce an empty directory -#Scratch: { - $dagger: task: _name: "Scratch" - - output: #FS -} +#Scratch: {$dagger: fs: _id: null} // Copy files from one FS tree to another #Copy: { diff --git a/stdlib/europa/dagger/engine/types.cue b/stdlib/europa/dagger/engine/types.cue index 7296f3fb..4c13245c 100644 --- a/stdlib/europa/dagger/engine/types.cue +++ b/stdlib/europa/dagger/engine/types.cue @@ -7,7 +7,7 @@ package engine // - A directory containing binary artifacts // Rule of thumb: if it fits in a tar archive, it fits in a #FS. #FS: { - $dagger: fs: _id: string + $dagger: fs: _id: string | null } // A reference to an external secret, for example: diff --git a/stdlib/europa/dagger/utils.cue b/stdlib/europa/dagger/utils.cue index b69f7b96..2f8a9f0a 100644 --- a/stdlib/europa/dagger/utils.cue +++ b/stdlib/europa/dagger/utils.cue @@ -16,12 +16,9 @@ import ( // Subdirectory tree output: #FS & copy.output - // Base image - scratch: engine.#Scratch - // Copy action copy: engine.#Copy & { - "input": scratch.output + "input": engine.#Scratch source: { root: input "path": path diff --git a/tests/cue.mod/module.cue b/tests/cue.mod/module.cue new file mode 100644 index 00000000..f8af9cef --- /dev/null +++ b/tests/cue.mod/module.cue @@ -0,0 +1 @@ +module: "" diff --git a/tests/cue.mod/pkg/.gitignore b/tests/cue.mod/pkg/.gitignore new file mode 100644 index 00000000..2d4dc1ae --- /dev/null +++ b/tests/cue.mod/pkg/.gitignore @@ -0,0 +1,3 @@ +# generated by dagger +alpha.dagger.io +dagger.lock diff --git a/tests/plan/outputs/outputs.cue b/tests/plan/outputs/outputs.cue index 30101e8f..962d36aa 100644 --- a/tests/plan/outputs/outputs.cue +++ b/tests/plan/outputs/outputs.cue @@ -4,10 +4,8 @@ import "alpha.dagger.io/europa/dagger/engine" engine.#Plan & { actions: { - scratch: engine.#Scratch - data: engine.#WriteFile & { - input: scratch.output + input: engine.#Scratch path: "/test" permissions: 0o600 contents: "foobar" diff --git a/tests/tasks/scratch/scratch.cue b/tests/tasks/scratch/scratch.cue index 10bf890b..cf69b5c8 100644 --- a/tests/tasks/scratch/scratch.cue +++ b/tests/tasks/scratch/scratch.cue @@ -10,13 +10,11 @@ engine.#Plan & { source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" } - scratch: engine.#Scratch - exec: engine.#Exec & { input: image.output mounts: fs: { dest: "/scratch" - contents: scratch.output + contents: engine.#Scratch } workdir: "/" args: [ From 6a7b5f3337bfe91b3b5b04bc8fd0c06eb8ea0ccc Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 15:50:24 -0700 Subject: [PATCH 2/7] cue fmt Signed-off-by: Joel Longtine --- tests/plan/outputs/outputs.cue | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/plan/outputs/outputs.cue b/tests/plan/outputs/outputs.cue index 962d36aa..455b4af8 100644 --- a/tests/plan/outputs/outputs.cue +++ b/tests/plan/outputs/outputs.cue @@ -3,13 +3,11 @@ package main import "alpha.dagger.io/europa/dagger/engine" engine.#Plan & { - actions: { - data: engine.#WriteFile & { - input: engine.#Scratch - path: "/test" - permissions: 0o600 - contents: "foobar" - } + actions: data: engine.#WriteFile & { + input: engine.#Scratch + path: "/test" + permissions: 0o600 + contents: "foobar" } outputs: directories: test: { From a3db716c0afd72219f39aae53967953f52e00511 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 16:21:06 -0700 Subject: [PATCH 3/7] Ensure we can Marshall #Scratch as CUE Signed-off-by: Joel Longtine --- plan/task/build.go | 19 ++++++++------ plancontext/fs.go | 10 ++++++-- tests/tasks.bats | 2 ++ tests/tasks/scratch/scratch_build_scratch.cue | 25 +++++++++++++++++++ tests/tasks/scratch/scratch_writefile.cue | 23 +++++++++++++++++ 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 tests/tasks/scratch/scratch_build_scratch.cue create mode 100644 tests/tasks/scratch/scratch_writefile.cue diff --git a/plan/task/build.go b/plan/task/build.go index 503c6d5f..94228600 100644 --- a/plan/task/build.go +++ b/plan/task/build.go @@ -115,14 +115,19 @@ func (t *buildTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s return nil, err } - st, err := ref.ToState() - if err != nil { - return nil, err - } + var solvedRef bkgw.Reference + if ref != nil { + st, err := ref.ToState() + if err != nil { + return nil, err + } - solvedRef, err := s.Solve(ctx, st, pctx.Platform.Get()) - if err != nil { - return nil, err + solvedRef, err = s.Solve(ctx, st, pctx.Platform.Get()) + if err != nil { + return nil, err + } + } else { + solvedRef = ref } // Image metadata diff --git a/plancontext/fs.go b/plancontext/fs.go index a0b712fd..c4adb419 100644 --- a/plancontext/fs.go +++ b/plancontext/fs.go @@ -42,8 +42,14 @@ func (fs *FS) State() (llb.State, error) { func (fs *FS) MarshalCUE() *compiler.Value { v := compiler.NewValue() - if err := v.FillPath(fsIDPath, fs.id); err != nil { - panic(err) + if fs.result == nil { + if err := v.FillPath(fsIDPath, nil); err != nil { + panic(err) + } + } else { + if err := v.FillPath(fsIDPath, fs.id); err != nil { + panic(err) + } } return v } diff --git a/tests/tasks.bats b/tests/tasks.bats index c93a408e..79b98601 100644 --- a/tests/tasks.bats +++ b/tests/tasks.bats @@ -92,6 +92,8 @@ setup() { @test "task: #Scratch" { cd "$TESTDIR"/tasks/scratch "$DAGGER" --europa up ./scratch.cue -l debug + "$DAGGER" --europa up ./scratch_build_scratch.cue -l debug + "$DAGGER" --europa up ./scratch_writefile.cue -l debug } @test "task: #Subdir" { diff --git a/tests/tasks/scratch/scratch_build_scratch.cue b/tests/tasks/scratch/scratch_build_scratch.cue new file mode 100644 index 00000000..ec89f6aa --- /dev/null +++ b/tests/tasks/scratch/scratch_build_scratch.cue @@ -0,0 +1,25 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + actions: { + write: engine.#WriteFile & { + input: engine.#Scratch + path: "/.dockerignore" + contents: "Dockerfile" + permissions: 700 + } + + build: engine.#Build & { + source: write.output + dockerfile: contents: """ + FROM scratch + """ + // Assert that output is engine.#Scratch + output: engine.#Scratch + } + } +} diff --git a/tests/tasks/scratch/scratch_writefile.cue b/tests/tasks/scratch/scratch_writefile.cue new file mode 100644 index 00000000..6ac4c12f --- /dev/null +++ b/tests/tasks/scratch/scratch_writefile.cue @@ -0,0 +1,23 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + actions: { + write: engine.#WriteFile & { + input: engine.#Scratch + path: "/testing" + contents: "1,2,3" + permissions: 700 + } + readfile: engine.#ReadFile & { + input: write.output + path: "/testing" + } & { + // assert result + contents: "1,2,3" + } + } +} From 4d4fbb20b588141ee679af9c627407b64ed9b468 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 16:26:17 -0700 Subject: [PATCH 4/7] Actually unify with `#FS` Signed-off-by: Joel Longtine --- stdlib/europa/dagger/engine/fs.cue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/europa/dagger/engine/fs.cue b/stdlib/europa/dagger/engine/fs.cue index bba15ec3..38589afd 100644 --- a/stdlib/europa/dagger/engine/fs.cue +++ b/stdlib/europa/dagger/engine/fs.cue @@ -49,7 +49,7 @@ package engine } // Produce an empty directory -#Scratch: {$dagger: fs: _id: null} +#Scratch: #FS & {$dagger: fs: _id: null} // Copy files from one FS tree to another #Copy: { From a184fe6fce8b1e5be398c096a55e377f2a2d65f1 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 16:41:36 -0700 Subject: [PATCH 5/7] Smaller, cleaner test Signed-off-by: Joel Longtine --- tests/tasks/scratch/scratch_build_scratch.cue | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/tasks/scratch/scratch_build_scratch.cue b/tests/tasks/scratch/scratch_build_scratch.cue index ec89f6aa..8eb1e08e 100644 --- a/tests/tasks/scratch/scratch_build_scratch.cue +++ b/tests/tasks/scratch/scratch_build_scratch.cue @@ -6,18 +6,10 @@ import ( engine.#Plan & { actions: { - write: engine.#WriteFile & { - input: engine.#Scratch - path: "/.dockerignore" - contents: "Dockerfile" - permissions: 700 - } build: engine.#Build & { - source: write.output - dockerfile: contents: """ - FROM scratch - """ + source: engine.#Scratch + dockerfile: contents: "FROM scratch" // Assert that output is engine.#Scratch output: engine.#Scratch } From 62b58f7e39fc0cef3f0b290464da20430e731747 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 16:46:43 -0700 Subject: [PATCH 6/7] cue fmt Signed-off-by: Joel Longtine --- tests/tasks/scratch/scratch_build_scratch.cue | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/tasks/scratch/scratch_build_scratch.cue b/tests/tasks/scratch/scratch_build_scratch.cue index 8eb1e08e..fb0473c1 100644 --- a/tests/tasks/scratch/scratch_build_scratch.cue +++ b/tests/tasks/scratch/scratch_build_scratch.cue @@ -5,13 +5,10 @@ import ( ) engine.#Plan & { - actions: { - - build: engine.#Build & { - source: engine.#Scratch - dockerfile: contents: "FROM scratch" - // Assert that output is engine.#Scratch - output: engine.#Scratch - } + actions: build: engine.#Build & { + source: engine.#Scratch + dockerfile: contents: "FROM scratch" + // Assert that output is engine.#Scratch + output: engine.#Scratch } } From 83d6f52e107b8052acd394c463e4c206d7fe70d6 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 21:32:15 -0700 Subject: [PATCH 7/7] Fix nits + cue.mod I let slip through Signed-off-by: Joel Longtine --- plan/task/build.go | 4 +--- tests/cue.mod/module.cue | 1 - tests/cue.mod/pkg/.gitignore | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 tests/cue.mod/module.cue delete mode 100644 tests/cue.mod/pkg/.gitignore diff --git a/plan/task/build.go b/plan/task/build.go index 94228600..a7fe22f3 100644 --- a/plan/task/build.go +++ b/plan/task/build.go @@ -115,7 +115,7 @@ func (t *buildTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s return nil, err } - var solvedRef bkgw.Reference + solvedRef := ref if ref != nil { st, err := ref.ToState() if err != nil { @@ -126,8 +126,6 @@ func (t *buildTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s if err != nil { return nil, err } - } else { - solvedRef = ref } // Image metadata diff --git a/tests/cue.mod/module.cue b/tests/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/tests/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/tests/cue.mod/pkg/.gitignore b/tests/cue.mod/pkg/.gitignore deleted file mode 100644 index 2d4dc1ae..00000000 --- a/tests/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# generated by dagger -alpha.dagger.io -dagger.lock