Merge pull request #1370 from jlongtine/engine-scratch-not-a-task
Make engine.#Scratch a specialization of #FS, rather than a task
This commit is contained in:
commit
902317f69f
@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
b: #Build & {
|
b: #Build & {
|
||||||
source: engine.#Scratch.output
|
source: engine.#Scratch
|
||||||
}
|
}
|
||||||
|
|
||||||
out: b.output
|
out: b.output
|
||||||
|
@ -115,15 +115,18 @@ func (t *buildTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
solvedRef := ref
|
||||||
|
if ref != nil {
|
||||||
st, err := ref.ToState()
|
st, err := ref.ToState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
solvedRef, err := s.Solve(ctx, st, pctx.Platform.Get())
|
solvedRef, err = s.Solve(ctx, st, pctx.Platform.Get())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Image metadata
|
// Image metadata
|
||||||
meta, ok := res.Metadata[exptypes.ExporterImageConfigKey]
|
meta, ok := res.Metadata[exptypes.ExporterImageConfigKey]
|
||||||
|
@ -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(),
|
|
||||||
})
|
|
||||||
}
|
|
@ -42,9 +42,15 @@ func (fs *FS) State() (llb.State, error) {
|
|||||||
|
|
||||||
func (fs *FS) MarshalCUE() *compiler.Value {
|
func (fs *FS) MarshalCUE() *compiler.Value {
|
||||||
v := compiler.NewValue()
|
v := compiler.NewValue()
|
||||||
|
if fs.result == nil {
|
||||||
|
if err := v.FillPath(fsIDPath, nil); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if err := v.FillPath(fsIDPath, fs.id); err != nil {
|
if err := v.FillPath(fsIDPath, fs.id); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +77,11 @@ func (c *fsContext) FromValue(v *compiler.Value) (*FS, error) {
|
|||||||
c.l.RLock()
|
c.l.RLock()
|
||||||
defer c.l.RUnlock()
|
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()
|
id, err := v.LookupPath(fsIDPath).String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid FS %q: %w", v.Path(), err)
|
return nil, fmt.Errorf("invalid FS %q: %w", v.Path(), err)
|
||||||
|
@ -49,11 +49,7 @@ package engine
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Produce an empty directory
|
// Produce an empty directory
|
||||||
#Scratch: {
|
#Scratch: #FS & {$dagger: fs: _id: null}
|
||||||
$dagger: task: _name: "Scratch"
|
|
||||||
|
|
||||||
output: #FS
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy files from one FS tree to another
|
// Copy files from one FS tree to another
|
||||||
#Copy: {
|
#Copy: {
|
||||||
|
@ -7,7 +7,7 @@ package engine
|
|||||||
// - A directory containing binary artifacts
|
// - A directory containing binary artifacts
|
||||||
// Rule of thumb: if it fits in a tar archive, it fits in a #FS.
|
// Rule of thumb: if it fits in a tar archive, it fits in a #FS.
|
||||||
#FS: {
|
#FS: {
|
||||||
$dagger: fs: _id: string
|
$dagger: fs: _id: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
// A reference to an external secret, for example:
|
// A reference to an external secret, for example:
|
||||||
|
@ -16,12 +16,9 @@ import (
|
|||||||
// Subdirectory tree
|
// Subdirectory tree
|
||||||
output: #FS & copy.output
|
output: #FS & copy.output
|
||||||
|
|
||||||
// Base image
|
|
||||||
scratch: engine.#Scratch
|
|
||||||
|
|
||||||
// Copy action
|
// Copy action
|
||||||
copy: engine.#Copy & {
|
copy: engine.#Copy & {
|
||||||
"input": scratch.output
|
"input": engine.#Scratch
|
||||||
source: {
|
source: {
|
||||||
root: input
|
root: input
|
||||||
"path": path
|
"path": path
|
||||||
|
@ -3,16 +3,12 @@ package main
|
|||||||
import "alpha.dagger.io/europa/dagger/engine"
|
import "alpha.dagger.io/europa/dagger/engine"
|
||||||
|
|
||||||
engine.#Plan & {
|
engine.#Plan & {
|
||||||
actions: {
|
actions: data: engine.#WriteFile & {
|
||||||
scratch: engine.#Scratch
|
input: engine.#Scratch
|
||||||
|
|
||||||
data: engine.#WriteFile & {
|
|
||||||
input: scratch.output
|
|
||||||
path: "/test"
|
path: "/test"
|
||||||
permissions: 0o600
|
permissions: 0o600
|
||||||
contents: "foobar"
|
contents: "foobar"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
outputs: directories: test: {
|
outputs: directories: test: {
|
||||||
contents: actions.data.output
|
contents: actions.data.output
|
||||||
|
@ -92,6 +92,8 @@ setup() {
|
|||||||
@test "task: #Scratch" {
|
@test "task: #Scratch" {
|
||||||
cd "$TESTDIR"/tasks/scratch
|
cd "$TESTDIR"/tasks/scratch
|
||||||
"$DAGGER" --europa up ./scratch.cue -l debug
|
"$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" {
|
@test "task: #Subdir" {
|
||||||
|
@ -10,13 +10,11 @@ engine.#Plan & {
|
|||||||
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch: engine.#Scratch
|
|
||||||
|
|
||||||
exec: engine.#Exec & {
|
exec: engine.#Exec & {
|
||||||
input: image.output
|
input: image.output
|
||||||
mounts: fs: {
|
mounts: fs: {
|
||||||
dest: "/scratch"
|
dest: "/scratch"
|
||||||
contents: scratch.output
|
contents: engine.#Scratch
|
||||||
}
|
}
|
||||||
workdir: "/"
|
workdir: "/"
|
||||||
args: [
|
args: [
|
||||||
|
14
tests/tasks/scratch/scratch_build_scratch.cue
Normal file
14
tests/tasks/scratch/scratch_build_scratch.cue
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"alpha.dagger.io/europa/dagger/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
engine.#Plan & {
|
||||||
|
actions: build: engine.#Build & {
|
||||||
|
source: engine.#Scratch
|
||||||
|
dockerfile: contents: "FROM scratch"
|
||||||
|
// Assert that output is engine.#Scratch
|
||||||
|
output: engine.#Scratch
|
||||||
|
}
|
||||||
|
}
|
23
tests/tasks/scratch/scratch_writefile.cue
Normal file
23
tests/tasks/scratch/scratch_writefile.cue
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user