diff --git a/plan/task/outputdirectory.go b/plan/task/outputdirectory.go new file mode 100644 index 00000000..82ad41c6 --- /dev/null +++ b/plan/task/outputdirectory.go @@ -0,0 +1,43 @@ +package task + +import ( + "context" + + bk "github.com/moby/buildkit/client" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/plancontext" + "go.dagger.io/dagger/solver" +) + +func init() { + Register("OutputDirectory", func() Task { return &outputDirectoryTask{} }) +} + +type outputDirectoryTask struct { +} + +func (c outputDirectoryTask) Run(ctx context.Context, pctx *plancontext.Context, s solver.Solver, v *compiler.Value) (*compiler.Value, error) { + contents, err := pctx.FS.FromValue(v.Lookup("contents")) + if err != nil { + return nil, err + } + + dest, err := v.Lookup("dest").String() + if err != nil { + return nil, err + } + + st, err := contents.Result().ToState() + if err != nil { + return nil, err + } + _, err = s.Export(ctx, st, nil, bk.ExportEntry{ + Type: bk.ExporterLocal, + OutputDir: dest, + }, pctx.Platform.Get()) + if err != nil { + return nil, err + } + + return compiler.NewValue(), nil +} diff --git a/stdlib/europa/dagger/engine/plan.cue b/stdlib/europa/dagger/engine/plan.cue index 7cbd67fb..311cba1c 100644 --- a/stdlib/europa/dagger/engine/plan.cue +++ b/stdlib/europa/dagger/engine/plan.cue @@ -82,7 +82,7 @@ _#inputSecret: { } _#outputDirectory: { - @dagger(notimplemented) + $dagger: task: _name: "OutputDirectory" // Filesystem contents to export // Reference an #FS field produced by an action diff --git a/tests/plan.bats b/tests/plan.bats index e7e6b4e1..c5a92ce1 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -69,3 +69,11 @@ setup() { assert_failure assert_output --partial 'failed: exec: "rtyet": executable file not found' } + +@test "plan/outputs" { + cd "$TESTDIR"/plan/outputs + + rm -f "./out/test" + "$DAGGER" --europa up ./outputs.cue + assert [ -f "./out/test" ] +} diff --git a/tests/plan/outputs/.gitignore b/tests/plan/outputs/.gitignore new file mode 100644 index 00000000..1fcb1529 --- /dev/null +++ b/tests/plan/outputs/.gitignore @@ -0,0 +1 @@ +out diff --git a/tests/plan/outputs/outputs.cue b/tests/plan/outputs/outputs.cue new file mode 100644 index 00000000..086b6239 --- /dev/null +++ b/tests/plan/outputs/outputs.cue @@ -0,0 +1,21 @@ +package main + +import "alpha.dagger.io/europa/dagger/engine" + +engine.#Plan & { + actions: { + scratch: engine.#Scratch + + data: engine.#WriteFile & { + input: scratch.output + path: "/test" + mode: 0o600 + contents: "foobar" + } + } + + outputs: directories: test: { + contents: actions.data.output + dest: "./out" + } +}