diff --git a/dagger/client.go b/dagger/client.go index 399166e9..fdf422d0 100644 --- a/dagger/client.go +++ b/dagger/client.go @@ -60,8 +60,8 @@ func NewClient(ctx context.Context, host string) (*Client, error) { }, nil } -// FIXME: return completed *Env, instead of *compiler.Value -func (c *Client) Up(ctx context.Context, env *Route) (*compiler.Value, error) { +// FIXME: return completed *Route, instead of *compiler.Value +func (c *Client) Up(ctx context.Context, route *Route) (*compiler.Value, error) { lg := log.Ctx(ctx) eg, gctx := errgroup.WithContext(ctx) @@ -78,7 +78,7 @@ func (c *Client) Up(ctx context.Context, env *Route) (*compiler.Value, error) { outr, outw := io.Pipe() eg.Go(func() error { defer outw.Close() - return c.buildfn(gctx, env, events, outw) + return c.buildfn(gctx, route, events, outw) }) // Spawn output retriever @@ -95,11 +95,11 @@ func (c *Client) Up(ctx context.Context, env *Route) (*compiler.Value, error) { return out, compiler.Err(eg.Wait()) } -func (c *Client) buildfn(ctx context.Context, env *Route, ch chan *bk.SolveStatus, w io.WriteCloser) error { +func (c *Client) buildfn(ctx context.Context, route *Route, ch chan *bk.SolveStatus, w io.WriteCloser) error { lg := log.Ctx(ctx) // Scan local dirs to grant access - localdirs := env.LocalDirs() + localdirs := route.LocalDirs() for label, dir := range localdirs { abs, err := filepath.Abs(dir) if err != nil { @@ -132,24 +132,24 @@ func (c *Client) buildfn(ctx context.Context, env *Route, ch chan *bk.SolveStatu s := NewSolver(c.c, gw, ch) lg.Debug().Msg("loading configuration") - if err := env.Update(ctx, s); err != nil { + if err := route.LoadLayout(ctx, s); err != nil { return nil, err } // Compute output overlay - lg.Debug().Msg("computing env") - if err := env.Up(ctx, s, nil); err != nil { + lg.Debug().Msg("computing route") + if err := route.Up(ctx, s, nil); err != nil { return nil, err } - // Export env to a cue directory + // Export route to a cue directory // FIXME: this should be elsewhere - lg.Debug().Msg("exporting env") - span, _ := opentracing.StartSpanFromContext(ctx, "Env.Export") + lg.Debug().Msg("exporting route") + span, _ := opentracing.StartSpanFromContext(ctx, "Route.Export") defer span.Finish() st := llb.Scratch().File( - llb.Mkfile("state.cue", 0600, env.State().JSON()), + llb.Mkfile("state.cue", 0600, route.State().JSON()), llb.WithCustomName("[internal] serializing state to JSON"), ) ref, err := s.Solve(ctx, st) @@ -178,7 +178,7 @@ func (c *Client) buildfn(ctx context.Context, env *Route, ch chan *bk.SolveStatu func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, error) { lg := log.Ctx(ctx) - // FIXME: merge this into env output. + // FIXME: merge this into route output. out := compiler.EmptyStruct() tr := tar.NewReader(r) diff --git a/dagger/compiler/value.go b/dagger/compiler/value.go index 0314cfdc..d0ee9477 100644 --- a/dagger/compiler/value.go +++ b/dagger/compiler/value.go @@ -123,11 +123,6 @@ func (v *Value) Int64() (int64, error) { return v.val.Int64() } -func (v *Value) SourceUnsafe() string { - s, _ := v.SourceString() - return s -} - // Proxy function to the underlying cue.Value func (v *Value) Path() cue.Path { return v.val.Path() @@ -236,12 +231,6 @@ func (v *Value) Source() ([]byte, error) { return cueformat.Node(v.val.Eval().Syntax()) } -// Return cue source for this value, as a Go string -func (v *Value) SourceString() (string, error) { - b, err := v.Source() - return string(b), err -} - func (v *Value) IsEmptyStruct() bool { if st, err := v.Struct(); err == nil { if st.Len() == 0 { diff --git a/dagger/pipeline.go b/dagger/pipeline.go index 6ea5034e..c7ec55d3 100644 --- a/dagger/pipeline.go +++ b/dagger/pipeline.go @@ -84,7 +84,11 @@ func ops(code ...*compiler.Value) ([]*compiler.Value, error) { ops = append(ops, xops...) } else { // 4. error - return nil, fmt.Errorf("not executable: %s", x.SourceUnsafe()) + source, err := x.Source() + if err != nil { + panic(err) + } + return nil, fmt.Errorf("not executable: %s", source) } } return ops, nil diff --git a/dagger/route.go b/dagger/route.go index ac378dd3..b2013b1b 100644 --- a/dagger/route.go +++ b/dagger/route.go @@ -82,18 +82,6 @@ type Route struct { state *compiler.Value } -func (r *Route) ID() string { - return r.st.ID -} - -func (r *Route) Name() string { - return r.st.Name -} - -func (r *Route) LayoutSource() Input { - return r.st.LayoutSource -} - func NewRoute(st *RouteState) (*Route, error) { empty := compiler.EmptyStruct() r := &Route{ @@ -125,23 +113,47 @@ func NewRoute(st *RouteState) (*Route, error) { return r, nil } +func (r *Route) ID() string { + return r.st.ID +} + +func (r *Route) Name() string { + return r.st.Name +} + +func (r *Route) LayoutSource() Input { + return r.st.LayoutSource +} + +func (r *Route) Layout() *compiler.Value { + return r.layout +} + +func (r *Route) Input() *compiler.Value { + return r.input +} + +func (r *Route) Output() *compiler.Value { + return r.output +} + func (r *Route) State() *compiler.Value { return r.state } -// Update the base configuration -func (r *Route) Update(ctx context.Context, s Solver) error { +// LoadLayout loads the layout +func (r *Route) LoadLayout(ctx context.Context, s Solver) error { span, ctx := opentracing.StartSpanFromContext(ctx, "r.Update") defer span.Finish() - layout, err := r.st.LayoutSource.Compile() + layoutSource, err := r.st.LayoutSource.Compile() if err != nil { return err } p := NewPipeline("[internal] source", s, nil) // execute updater script - if err := p.Do(ctx, layout); err != nil { + if err := p.Do(ctx, layoutSource); err != nil { return err } @@ -150,24 +162,16 @@ func (r *Route) Update(ctx context.Context, s Solver) error { stdlib.Path: stdlib.FS, "/": p.FS(), } - base, err := compiler.Build(sources) + layout, err := compiler.Build(sources) if err != nil { - return fmt.Errorf("base config: %w", err) + return fmt.Errorf("layout config: %w", err) } - r.layout = base + r.layout = layout // Commit return r.mergeState() } -func (r *Route) Base() *compiler.Value { - return r.layout -} - -func (r *Route) Output() *compiler.Value { - return r.output -} - // Scan all scripts in the environment for references to local directories (do:"local"), // and return all referenced directory names. // This is used by clients to grant access to local directories when they are referenced @@ -299,7 +303,7 @@ func (r *Route) Up(ctx context.Context, s Solver, _ *UpOpts) error { } { - span, _ := opentracing.StartSpanFromContext(ctx, "r.Compute: merge state") + span, _ := opentracing.StartSpanFromContext(ctx, "merge state") defer span.Finish() return r.mergeState()