From a3db716c0afd72219f39aae53967953f52e00511 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 7 Jan 2022 16:21:06 -0700 Subject: [PATCH] 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" + } + } +}