From 27a44a9e5836a92f7dd73d305e1b51fa40d5aaf4 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sat, 9 Jan 2021 17:07:39 -0800 Subject: [PATCH 1/4] Fix bug in Env.Walk Signed-off-by: Solomon Hykes --- dagger/env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dagger/env.go b/dagger/env.go index 9513694c..e21980eb 100644 --- a/dagger/env.go +++ b/dagger/env.go @@ -102,7 +102,7 @@ func (env *Env) Walk(ctx context.Context, fn EnvWalkFunc) (*Value, error) { defer debugf("COMPLETE: Env.Walk") // Cueflow cue instance // FIXME: make this cleaner in *Value by keeping intermediary instances - flowInst, err := env.base.CueInst().Fill(env.input.CueInst()) + flowInst, err := env.base.CueInst().Fill(env.input.CueInst().Value()) if err != nil { return nil, err } From 216e8084657e3c80adb7bb2847fda72d0a1674d4 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sat, 9 Jan 2021 17:22:51 -0800 Subject: [PATCH 2/4] Add test to reproduce crash computing examples/simple Signed-off-by: Solomon Hykes --- dagger/script_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dagger/script_test.go b/dagger/script_test.go index 71898fcc..1c24d1a0 100644 --- a/dagger/script_test.go +++ b/dagger/script_test.go @@ -5,6 +5,17 @@ import ( "testing" ) +func TestValidateEmptyValue(t *testing.T) { + cc := &Compiler{} + v, err := cc.Compile("", "#dagger: compute: _") + if err != nil { + t.Fatal(err) + } + if err := v.Get("#dagger.compute").Validate("#Script"); err != nil { + t.Fatal(err) + } +} + func TestLocalScript(t *testing.T) { cc := &Compiler{} src := `[{do: "local", dir: "foo"}]` From 00414449b7d1cb860cc05ad39770e0b76bc1175d Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sat, 9 Jan 2021 17:25:12 -0800 Subject: [PATCH 3/4] Clean up debug messages & comments Signed-off-by: Solomon Hykes --- dagger/client.go | 8 +++++--- dagger/compute.go | 1 - dagger/env.go | 4 ++++ dagger/spec.go | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dagger/client.go b/dagger/client.go index da23e426..0dc4f1b0 100644 --- a/dagger/client.go +++ b/dagger/client.go @@ -90,7 +90,6 @@ func (c *Client) LocalDirs() ([]string, error) { } func (c *Client) BootScript() (*Script, error) { - debugf("compiling boot script: %q\n", c.boot) cc := &Compiler{} src, err := cc.Compile("boot.cue", c.boot) if err != nil { @@ -147,6 +146,7 @@ func (c *Client) buildfn(ctx context.Context, ch chan *bk.SolveStatus, w io.Writ close(ch) return errors.Wrap(err, "serialize boot script") } + debugf("client: assembled boot script: %s\n", bootSource) // Setup solve options opts := bk.SolveOpt{ FrontendAttrs: map[string]string{ @@ -193,7 +193,6 @@ func (c *Client) outputfn(_ context.Context, r io.Reader, out *Value) func() err defer debugf("outputfn complete") tr := tar.NewReader(r) for { - debugf("outputfn: reading next tar entry") h, err := tr.Next() if err == io.EOF { break @@ -301,9 +300,12 @@ func (c *Client) printfn(ctx context.Context, ch, ch2 chan *bk.SolveStatus) func len(status.Logs), ) for _, v := range status.Vertexes { + // FIXME: insert raw buildkit telemetry here (ie for debugging, etc.) + + // IF a buildkit vertex has a valid cue path as name, extract additional info: p := cue.ParsePath(v.Name) if err := p.Err(); err != nil { - debugf("ignoring buildkit vertex %q: not a valid cue path", v.Name) + // Not a valid cue path: skip. continue } n := &Node{ diff --git a/dagger/compute.go b/dagger/compute.go index 787b3d6a..046e0b0a 100644 --- a/dagger/compute.go +++ b/dagger/compute.go @@ -19,7 +19,6 @@ func Compute(ctx context.Context, c bkgw.Client) (r *bkgw.Result, err error) { debugf("execute returned an error. Wrapping...") } }() - debugf("initializing env") // Retrieve boot script form client env, err := NewEnv(ctx, NewSolver(c), getBootScript(c), getInput(c)) if err != nil { diff --git a/dagger/env.go b/dagger/env.go index e21980eb..66edaa11 100644 --- a/dagger/env.go +++ b/dagger/env.go @@ -28,6 +28,7 @@ type Env struct { // Initialize a new environment func NewEnv(ctx context.Context, s Solver, bootsrc, inputsrc string) (*Env, error) { + debugf("NewEnv(boot=%q input=%q)", bootsrc, inputsrc) cc := &Compiler{} // 1. Compile & execute boot script boot, err := cc.CompileScript("boot.cue", bootsrc) @@ -55,6 +56,9 @@ func NewEnv(ctx context.Context, s Solver, bootsrc, inputsrc string) (*Env, erro if _, err := base.Merge(input); err != nil { return nil, errors.Wrap(err, "merge base & input") } + + debugf("ENV: base=%q input=%q", base.JSON(), input.JSON()) + return &Env{ base: base, input: input, diff --git a/dagger/spec.go b/dagger/spec.go index ca2db4ec..f84b93d0 100644 --- a/dagger/spec.go +++ b/dagger/spec.go @@ -18,7 +18,7 @@ func (s Spec) Validate(v *Value, defpath string) (err error) { // FIXME: there is probably a cleaner way to do this. defer func() { if err != nil { - debugf("ERROR while validating %v against %v err=%q", v, defpath, err) + //debugf("ERROR while validating %v against %v err=%q", v, defpath, err) err = fmt.Errorf("%s", cueerrors.Details(err, nil)) } }() @@ -33,7 +33,6 @@ func (s Spec) Validate(v *Value, defpath string) (err error) { if err := merged.Err(); err != nil { return err } - debugf("Validating %v against %v", v, def) if err := merged.Validate(cue.Final()); err != nil { return err } From 4514df1853b2ef6ac6858c91f953a385680235b5 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Sat, 9 Jan 2021 17:32:30 -0800 Subject: [PATCH 4/4] remove broken "dagger create" command Signed-off-by: Solomon Hykes --- cmd/dagger/cmd/create.go | 35 ----------------------------------- cmd/dagger/cmd/root.go | 4 +--- 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 cmd/dagger/cmd/create.go diff --git a/cmd/dagger/cmd/create.go b/cmd/dagger/cmd/create.go deleted file mode 100644 index 72f6c6aa..00000000 --- a/cmd/dagger/cmd/create.go +++ /dev/null @@ -1,35 +0,0 @@ -package cmd - -import ( - "fmt" - "io/ioutil" - "os" - - "dagger.cloud/go/dagger/ui" - "github.com/spf13/cobra" -) - -var createCmd = &cobra.Command{ - Use: "create ENV BASE", - Short: "Create an env", - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - envname := args[0] - base := args[1] - envdir := ".dagger/env/" + envname - if info, err := os.Stat(envdir); err == nil { - if info.IsDir() { - ui.Fatalf("env already exists: %s", envname) - } - } - if err := os.MkdirAll(envdir, 0755); err != nil { - ui.Fatal(err) - } - baseCue := fmt.Sprintf("package env\nimport base \"%s\"\nbase\n", base) - err := ioutil.WriteFile(envdir+"/base.cue", []byte(baseCue), 0644) - if err != nil { - ui.Fatal(err) - } - ui.Info("created environment %q with base %q", envname, base) - }, -} diff --git a/cmd/dagger/cmd/root.go b/cmd/dagger/cmd/root.go index 81a4638f..23a763aa 100644 --- a/cmd/dagger/cmd/root.go +++ b/cmd/dagger/cmd/root.go @@ -14,11 +14,9 @@ func init() { // --debug rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode") // --workspace - rootCmd.PersistentFlags().StringP("workspace", "w", "", "Select workspace") rootCmd.AddCommand( - // Create an env - createCmd, computeCmd, + // Create an env // Change settings on an env // View or edit env serti // settingsCmd,