From a90ff8ab9400c1acfec742b6fcb26f820c1592b3 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Tue, 21 Dec 2021 10:42:05 -0700 Subject: [PATCH] Allow for nil buildkit References Signed-off-by: Joel Longtine --- plan/task/copy.go | 4 ++-- plan/task/exec.go | 4 ++-- plan/task/scratch.go | 9 +-------- plan/task/writefile.go | 2 +- plancontext/fs.go | 12 ++++++++++++ tests/tasks/scratch/scratch.cue | 4 ++-- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plan/task/copy.go b/plan/task/copy.go index 0aff6262..81182c01 100644 --- a/plan/task/copy.go +++ b/plan/task/copy.go @@ -24,7 +24,7 @@ func (t *copyTask) Run(ctx context.Context, pctx *plancontext.Context, s solver. return nil, err } - inputState, err := input.Result().ToState() + inputState, err := input.State() if err != nil { return nil, err } @@ -34,7 +34,7 @@ func (t *copyTask) Run(ctx context.Context, pctx *plancontext.Context, s solver. return nil, err } - sourceState, err := sourceRoot.Result().ToState() + sourceState, err := sourceRoot.State() if err != nil { return nil, err } diff --git a/plan/task/exec.go b/plan/task/exec.go index 9ab12066..dd55ed93 100644 --- a/plan/task/exec.go +++ b/plan/task/exec.go @@ -26,7 +26,7 @@ func (t execTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.S if err != nil { return nil, err } - st, err := input.Result().ToState() + st, err := input.State() if err != nil { return nil, err } @@ -246,7 +246,7 @@ func (t *execTask) mountFS(pctx *plancontext.Context, dest string, mnt *compiler } } - st, err := contents.Result().ToState() + st, err := contents.State() if err != nil { return nil, err } diff --git a/plan/task/scratch.go b/plan/task/scratch.go index e27a5da4..5c01d626 100644 --- a/plan/task/scratch.go +++ b/plan/task/scratch.go @@ -3,7 +3,6 @@ package task import ( "context" - "github.com/moby/buildkit/client/llb" "go.dagger.io/dagger/compiler" "go.dagger.io/dagger/plancontext" "go.dagger.io/dagger/solver" @@ -17,13 +16,7 @@ type scratchTask struct { } func (t *scratchTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { - st := llb.Scratch() - result, err := s.Solve(ctx, st, pctx.Platform.Get()) - if err != nil { - return nil, err - } - - fs := pctx.FS.New(result) + fs := pctx.FS.New(nil) return compiler.NewValue().FillFields(map[string]interface{}{ "output": fs.MarshalCUE(), diff --git a/plan/task/writefile.go b/plan/task/writefile.go index f92fb8b2..edcedfa5 100644 --- a/plan/task/writefile.go +++ b/plan/task/writefile.go @@ -60,7 +60,7 @@ func (t *writeFileTask) Run(ctx context.Context, pctx *plancontext.Context, s so return nil, err } - inputState, err := input.Result().ToState() + inputState, err := input.State() if err != nil { return nil, err diff --git a/plancontext/fs.go b/plancontext/fs.go index fd094724..72cca3ac 100644 --- a/plancontext/fs.go +++ b/plancontext/fs.go @@ -6,6 +6,7 @@ import ( "cuelang.org/go/cue" "github.com/google/uuid" + "github.com/moby/buildkit/client/llb" bkgw "github.com/moby/buildkit/frontend/gateway/client" "go.dagger.io/dagger/compiler" "go.dagger.io/dagger/stdlib" @@ -32,6 +33,17 @@ func (fs *FS) Result() bkgw.Reference { return fs.result } +// func (fs *FS) FS() *solver.BuildkitFS { +// return solver.NewBuildkitFS(fs.result) +// } + +func (fs *FS) State() (llb.State, error) { + if fs.Result() == nil { + return llb.State{}, nil + } + return fs.Result().ToState() +} + func (fs *FS) MarshalCUE() *compiler.Value { v := compiler.NewValue() if err := v.FillPath(fsIDPath, fs.id); err != nil { diff --git a/tests/tasks/scratch/scratch.cue b/tests/tasks/scratch/scratch.cue index 2d1472c0..10bf890b 100644 --- a/tests/tasks/scratch/scratch.cue +++ b/tests/tasks/scratch/scratch.cue @@ -22,10 +22,10 @@ engine.#Plan & { args: [ "sh", "-c", #""" - ls -al + test "$(ls -A /)" != "" + test "$(ls -A /scratch)" = "" """#, ] } - } }