Ensure we can Marshall #Scratch as CUE

Signed-off-by: Joel Longtine <joel@dagger.io>
This commit is contained in:
Joel Longtine 2022-01-07 16:21:06 -07:00
parent 6a7b5f3337
commit a3db716c0a
5 changed files with 70 additions and 9 deletions

View File

@ -115,15 +115,20 @@ func (t *buildTask) dockerfile(ctx context.Context, pctx *plancontext.Context, s
return nil, err return nil, err
} }
var solvedRef bkgw.Reference
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
} }
} else {
solvedRef = ref
}
// Image metadata // Image metadata
meta, ok := res.Metadata[exptypes.ExporterImageConfigKey] meta, ok := res.Metadata[exptypes.ExporterImageConfigKey]

View File

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

View File

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

View File

@ -0,0 +1,25 @@
package main
import (
"alpha.dagger.io/europa/dagger/engine"
)
engine.#Plan & {
actions: {
write: engine.#WriteFile & {
input: engine.#Scratch
path: "/.dockerignore"
contents: "Dockerfile"
permissions: 700
}
build: engine.#Build & {
source: write.output
dockerfile: contents: """
FROM scratch
"""
// Assert that output is engine.#Scratch
output: engine.#Scratch
}
}
}

View 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"
}
}
}