diff --git a/client/client.go b/client/client.go index e4e339a8..8cbc279d 100644 --- a/client/client.go +++ b/client/client.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "path/filepath" "strings" "sync" @@ -116,13 +115,9 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment. lg := log.Ctx(ctx) // Scan local dirs to grant access - localdirs := env.LocalDirs() - for label, dir := range localdirs { - abs, err := filepath.Abs(dir) - if err != nil { - return err - } - localdirs[label] = abs + localdirs, err := env.LocalDirs() + if err != nil { + return err } // buildkit auth provider (registry) diff --git a/environment/environment.go b/environment/environment.go index 77200d4b..01aa6413 100644 --- a/environment/environment.go +++ b/environment/environment.go @@ -3,6 +3,7 @@ package environment import ( "context" "fmt" + "path/filepath" "cuelang.org/go/cue" cueflow "cuelang.org/go/tools/flow" @@ -75,10 +76,11 @@ func (e *Environment) Computed() *compiler.Value { // and return all referenced directory names. // This is used by clients to grant access to local directories when they are referenced // by user-specified scripts. -func (e *Environment) LocalDirs() map[string]string { +func (e *Environment) LocalDirs() (map[string]string, error) { dirs := map[string]string{} - localdirs := func(code *compiler.Value) { - Analyze( + + localdirs := func(code *compiler.Value) error { + return Analyze( func(op *compiler.Value) error { do, err := op.Lookup("do").String() if err != nil { @@ -91,7 +93,12 @@ func (e *Environment) LocalDirs() map[string]string { if err != nil { return err } - dirs[dir] = dir + abs, err := filepath.Abs(dir) + if err != nil { + return err + } + + dirs[dir] = abs return nil }, code, @@ -101,10 +108,10 @@ func (e *Environment) LocalDirs() map[string]string { // FIXME: use a common `flow` instance to avoid rescanning the tree. src := compiler.NewValue() if err := src.FillPath(cue.MakePath(), e.plan); err != nil { - return nil + return nil, err } if err := src.FillPath(cue.MakePath(), e.input); err != nil { - return nil + return nil, err } flow := cueflow.New( &cueflow.Config{}, @@ -112,11 +119,12 @@ func (e *Environment) LocalDirs() map[string]string { newTaskFunc(noOpRunner), ) for _, t := range flow.Tasks() { - v := compiler.Wrap(t.Value()) - localdirs(v.Lookup("#up")) + if err := localdirs(compiler.Wrap(t.Value())); err != nil { + return nil, err + } } - return dirs + return dirs, nil } // Up missing values in environment configuration, and write them to state. diff --git a/environment/pipeline.go b/environment/pipeline.go index e2801b0e..0fcdf0c9 100644 --- a/environment/pipeline.go +++ b/environment/pipeline.go @@ -113,7 +113,7 @@ func ops(code *compiler.Value) ([]*compiler.Value, error) { if err != nil { panic(err) } - return nil, fmt.Errorf("not executable: %s", source) + return nil, fmt.Errorf("not executable: %s (%s)", source, code.Path().String()) } return ops, nil } @@ -121,7 +121,9 @@ func ops(code *compiler.Value) ([]*compiler.Value, error) { func Analyze(fn func(*compiler.Value) error, code *compiler.Value) error { ops, err := ops(code) if err != nil { - return err + // Ignore CUE errors when analyzing. This might be because the value is + // not concrete since static analysis runs before pipelines are executed. + return nil } for _, op := range ops { if err := analyzeOp(fn, op); err != nil { diff --git a/stdlib/docker/command.cue b/stdlib/docker/command.cue index 5d69a2fa..4059dacc 100644 --- a/stdlib/docker/command.cue +++ b/stdlib/docker/command.cue @@ -205,9 +205,6 @@ import ( } } "mount": { - if ssh == _|_ { - "/var/run/docker.sock": from: "docker.sock" - } if ssh != _|_ { if ssh.key != _|_ { "/key": secret: ssh.key diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 7c11b275..4a42172b 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -144,6 +144,9 @@ setup() { # Copy deployment to sandbox copy_to_sandbox kubernetes-deployment kubernetes + # Query + dagger --project "$DAGGER_SANDBOX" -e kubernetes-deployment query + # Set kubeconfig dagger --project "$DAGGER_SANDBOX" -e kubernetes-deployment input text TestKubeconfig -f "$HOME"/.kube/config diff --git a/tests/compute/dependencies/interpolation/main.cue b/tests/compute/dependencies/interpolation/main.cue index 9a27b6db..1931c28d 100644 --- a/tests/compute/dependencies/interpolation/main.cue +++ b/tests/compute/dependencies/interpolation/main.cue @@ -1,23 +1,22 @@ package testing +import "alpha.dagger.io/dagger/op" + A: { result: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo '{"result": "from A"}' > /tmp/out """, ] dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" @@ -29,20 +28,17 @@ B: { result: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo "{\\"result\\": \\"dependency \(A.result)\\"}" > /tmp/out """, ] dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" diff --git a/tests/compute/dependencies/simple/main.cue b/tests/compute/dependencies/simple/main.cue index 445192a6..a1cb264e 100644 --- a/tests/compute/dependencies/simple/main.cue +++ b/tests/compute/dependencies/simple/main.cue @@ -1,23 +1,21 @@ package testing +import "alpha.dagger.io/dagger/op" + A: { result: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo '{"result": "from A"}' > /tmp/out """, ] - dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" @@ -29,12 +27,10 @@ B: { result: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { env: DATA: A.result args: ["sh", "-c", """ echo "{\\"result\\": \\"dependency $DATA\\"}" > /tmp/out @@ -42,8 +38,7 @@ B: { ] dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" diff --git a/tests/compute/dependencies/unmarshal/main.cue b/tests/compute/dependencies/unmarshal/main.cue index 698d159a..f69f0e76 100644 --- a/tests/compute/dependencies/unmarshal/main.cue +++ b/tests/compute/dependencies/unmarshal/main.cue @@ -1,25 +1,25 @@ package testing -import "encoding/json" +import ( + "encoding/json" + "alpha.dagger.io/dagger/op" +) A: { string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo '{"hello": "world"}' > /tmp/out """, ] dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "string" @@ -33,20 +33,17 @@ B: { result: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo "{\\"result\\": \\"unmarshalled.hello=\(unmarshalled.hello)\\"}" > /tmp/out """, ] dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" diff --git a/tests/compute/input/default/main.cue b/tests/compute/input/default/main.cue index 29cc48df..fef29dac 100644 --- a/tests/compute/input/default/main.cue +++ b/tests/compute/input/default/main.cue @@ -1,25 +1,24 @@ package testing +import "alpha.dagger.io/dagger/op" + X1=in: string | *"default input" test: { string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo -n "received: \(X1)" > /out """] // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 dir: "/" }, - { - do: "export" + op.#Export & { source: "/out" format: "string" }, diff --git a/tests/compute/input/simple/main.cue b/tests/compute/input/simple/main.cue index 5e71cc43..26ef7266 100644 --- a/tests/compute/input/simple/main.cue +++ b/tests/compute/input/simple/main.cue @@ -1,25 +1,24 @@ package testing +import "alpha.dagger.io/dagger/op" + X1=in: string test: { string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo -n "received: \(X1)" > /out """] // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 dir: "/" }, - { - do: "export" + op.#Export & { source: "/out" format: "string" }, diff --git a/tests/compute/success/overload/flat/main.cue b/tests/compute/success/overload/flat/main.cue index 03cb52ed..8fd9e6ab 100644 --- a/tests/compute/success/overload/flat/main.cue +++ b/tests/compute/success/overload/flat/main.cue @@ -1,17 +1,19 @@ package testing +import "alpha.dagger.io/dagger/op" + new_prop: "lala" #new_def: "lala" new_prop_too: string #new_def_too: string -#up: [{ - do: "fetch-container" - ref: "busybox" -}, - { - do: "exec" +#up: [ + op.#FetchContainer & { + ref: "busybox" + }, + op.#Exec & { args: ["true"] dir: "/" - }] + }, +] diff --git a/tests/compute/success/overload/wrapped/main.cue b/tests/compute/success/overload/wrapped/main.cue index 3fe6e1dc..76256287 100644 --- a/tests/compute/success/overload/wrapped/main.cue +++ b/tests/compute/success/overload/wrapped/main.cue @@ -1,5 +1,7 @@ package testing +import "alpha.dagger.io/dagger/op" + foo: { new_prop: "lala" #new_def: "lala" @@ -7,13 +9,13 @@ foo: { new_prop_too: string #new_def_too: string - #up: [{ - do: "fetch-container" - ref: "busybox" - }, - { - do: "exec" + #up: [ + op.#FetchContainer & { + ref: "busybox" + }, + op.#Exec & { args: ["true"] dir: "/" - }] + }, + ] } diff --git a/tests/compute/success/simple/main.cue b/tests/compute/success/simple/main.cue index 09956ed1..165f52bf 100644 --- a/tests/compute/success/simple/main.cue +++ b/tests/compute/success/simple/main.cue @@ -1,12 +1,12 @@ package testing +import "alpha.dagger.io/dagger/op" + #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "busybox" }, - { - do: "exec" + op.#Exec & { args: ["true"] dir: "/" }, diff --git a/tests/ops/exec/undefined/with_pkg_def/cue.mod/pkg/test.dagger.io/def/main.cue b/tests/ops/exec/undefined/with_pkg_def/cue.mod/pkg/test.dagger.io/def/main.cue index c7139a34..2221be30 100644 --- a/tests/ops/exec/undefined/with_pkg_def/cue.mod/pkg/test.dagger.io/def/main.cue +++ b/tests/ops/exec/undefined/with_pkg_def/cue.mod/pkg/test.dagger.io/def/main.cue @@ -1,15 +1,14 @@ package def +import "alpha.dagger.io/dagger/op" + #dang: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" - dir: "/" + op.#Exec & { args: ["sh", "-c", """ echo success """] diff --git a/tests/ops/exec/undefined/with_pkg_mandatory/cue.mod/pkg/test.dagger.io/nonoptional/main.cue b/tests/ops/exec/undefined/with_pkg_mandatory/cue.mod/pkg/test.dagger.io/nonoptional/main.cue index 494701ae..1b3443f2 100644 --- a/tests/ops/exec/undefined/with_pkg_mandatory/cue.mod/pkg/test.dagger.io/nonoptional/main.cue +++ b/tests/ops/exec/undefined/with_pkg_mandatory/cue.mod/pkg/test.dagger.io/nonoptional/main.cue @@ -1,15 +1,14 @@ package nonoptional +import "alpha.dagger.io/dagger/op" + dang: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" - dir: "/" + op.#Exec & { args: ["sh", "-c", """ echo "This test SHOULD fail, because this SHOULD be executed" exit 1 diff --git a/tests/ops/exec/undefined/with_pkg_optional/cue.mod/pkg/test.dagger.io/optional/main.cue b/tests/ops/exec/undefined/with_pkg_optional/cue.mod/pkg/test.dagger.io/optional/main.cue index be6b1a70..d366784e 100644 --- a/tests/ops/exec/undefined/with_pkg_optional/cue.mod/pkg/test.dagger.io/optional/main.cue +++ b/tests/ops/exec/undefined/with_pkg_optional/cue.mod/pkg/test.dagger.io/optional/main.cue @@ -1,15 +1,14 @@ package optional +import "alpha.dagger.io/dagger/op" + dang?: string #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" - dir: "/" + op.#Exec & { args: ["sh", "-c", """ echo success """] diff --git a/tests/ops/export/json/main.cue b/tests/ops/export/json/main.cue index 5ee735d8..05a13d0e 100644 --- a/tests/ops/export/json/main.cue +++ b/tests/ops/export/json/main.cue @@ -44,20 +44,16 @@ TestExportList: { [...string] #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo '["milk", "pumpkin pie", "eggs", "juice"]' > /tmp/out """, ] - dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "json" diff --git a/tests/ops/export/yaml/main.cue b/tests/ops/export/yaml/main.cue index fca9b8e5..85478454 100644 --- a/tests/ops/export/yaml/main.cue +++ b/tests/ops/export/yaml/main.cue @@ -27,22 +27,17 @@ TestExportList: { [...string] #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo "--- # Shopping list [milk, pumpkin pie, eggs, juice]" > /tmp/out """, ] - // XXX Blocked by https://github.com/blocklayerhq/dagger/issues/19 - dir: "/" }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "yaml" @@ -51,19 +46,16 @@ TestExportList: { } TestExportMap: #up: [ - { - do: "fetch-container" + op.#FetchContainer & { ref: "alpine" }, - { - do: "exec" + op.#Exec & { args: ["sh", "-c", """ echo something: something > /tmp/out """, ] }, - { - do: "export" + op.#Export & { // Source path in the container source: "/tmp/out" format: "yaml"