From 131551f9cd650efe8a2edc51f4fd50a699c35373 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 24 Nov 2021 16:24:04 -0800 Subject: [PATCH] runtime: support for context imports Signed-off-by: Andrea Luzzardi --- plan/task/import.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 plan/task/import.go diff --git a/plan/task/import.go b/plan/task/import.go new file mode 100644 index 00000000..40b4e2f9 --- /dev/null +++ b/plan/task/import.go @@ -0,0 +1,37 @@ +package task + +import ( + "context" + "fmt" + "os" + + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/plancontext" + "go.dagger.io/dagger/solver" +) + +func init() { + Register("Import", func() Task { return &importTask{} }) +} + +type importTask struct { +} + +func (c importTask) Run(ctx context.Context, pctx *plancontext.Context, _ solver.Solver, v *compiler.Value) (*compiler.Value, error) { + var dir *plancontext.Directory + + if err := v.Decode(&dir); err != nil { + return nil, err + } + + // Check that directory exists + if _, err := os.Stat(dir.Path); os.IsNotExist(err) { + return nil, fmt.Errorf("%q dir doesn't exist", dir.Path) + } + + id := pctx.Directories.Register(dir) + return compiler.Compile("", fmt.Sprintf( + `fs: #up: [{do: "local", id: %q}]`, + id, + )) +}