Make engine.#Scratch a specialization of #FS, rather than a task

Signed-off-by: Joel Longtine <joel@dagger.io>
This commit is contained in:
Joel Longtine 2022-01-07 15:43:58 -07:00
parent 80a42be174
commit 3003b31be3
10 changed files with 15 additions and 41 deletions

View File

@ -5,7 +5,7 @@ import (
)
b: #Build & {
source: engine.#Scratch.output
source: engine.#Scratch
}
out: b.output

View File

@ -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(),
})
}

View File

@ -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)

View File

@ -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: {

View File

@ -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:

View File

@ -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

1
tests/cue.mod/module.cue Normal file
View File

@ -0,0 +1 @@
module: ""

3
tests/cue.mod/pkg/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# generated by dagger
alpha.dagger.io
dagger.lock

View File

@ -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"

View File

@ -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: [