From 37bf20e24bb7dd6552a5f2b13fea1236bec66f8c Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 23 Mar 2021 22:41:26 +0000 Subject: [PATCH] Expand mockup backend for CLI Signed-off-by: Solomon Hykes --- cmd/dagger/cmd/down.go | 4 +- cmd/dagger/cmd/new.go | 5 +-- cmd/dagger/cmd/query.go | 4 +- cmd/dagger/cmd/up.go | 4 +- dagger/env.go | 2 + dagger/route.go | 91 ++++++++++++++++++++++++++++++++++------- 6 files changed, 87 insertions(+), 23 deletions(-) diff --git a/cmd/dagger/cmd/down.go b/cmd/dagger/cmd/down.go index e588e999..b62667b9 100644 --- a/cmd/dagger/cmd/down.go +++ b/cmd/dagger/cmd/down.go @@ -26,13 +26,13 @@ var downCmd = &cobra.Command{ ctx := lg.WithContext(cmd.Context()) routeName := getRouteName(lg, cmd) - route, err := dagger.LookupRoute(routeName) + route, err := dagger.LookupRoute(routeName, nil) if err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route") } // TODO: Implement options: --no-cache - if err := route.Down(ctx); err != nil { + if err := route.Down(ctx, nil); err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to up the route") } }, diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index 5ea4a13f..f317caca 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -33,8 +33,7 @@ var newCmd = &cobra.Command{ routeName := getRouteName(lg, cmd) // TODO: Implement options: --layout-*, --setup - // FIXME: give route name in create opts - route, err := dagger.CreateRoute(ctx) + route, err := dagger.CreateRoute(ctx, routeName, nil) if err != nil { lg.Fatal().Err(err).Msg("failed to create route") } @@ -42,7 +41,7 @@ var newCmd = &cobra.Command{ if upRoute { lg.Info().Str("route-id", route.ID).Msg("bringing route online") - if err := route.Up(ctx); err != nil { + if err := route.Up(ctx, nil); err != nil { lg.Fatal().Err(err).Str("route-id", route.ID).Msg("failed to create route") } } diff --git a/cmd/dagger/cmd/query.go b/cmd/dagger/cmd/query.go index e4527e92..913b03a5 100644 --- a/cmd/dagger/cmd/query.go +++ b/cmd/dagger/cmd/query.go @@ -27,14 +27,14 @@ var queryCmd = &cobra.Command{ ctx := lg.WithContext(cmd.Context()) routeName := getRouteName(lg, cmd) - route, err := dagger.LookupRoute(routeName) + route, err := dagger.LookupRoute(routeName, nil) if err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route") } expr := args[0] - out, err := route.Query(ctx, expr) + out, err := route.Query(ctx, expr, nil) if err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to query route") } diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 9ee78784..c04655f1 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -26,13 +26,13 @@ var upCmd = &cobra.Command{ ctx := lg.WithContext(cmd.Context()) routeName := getRouteName(lg, cmd) - route, err := dagger.LookupRoute(routeName) + route, err := dagger.LookupRoute(routeName, nil) if err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Msg("failed to lookup route") } // TODO: Implement options: --no-cache - if err := route.Up(ctx); err != nil { + if err := route.Up(ctx, nil); err != nil { lg.Fatal().Err(err).Str("route-name", routeName).Str("route-id", route.ID).Msg("failed to up the route") } }, diff --git a/dagger/env.go b/dagger/env.go index a99534ed..c2e1896e 100644 --- a/dagger/env.go +++ b/dagger/env.go @@ -135,6 +135,8 @@ func (env *Env) LocalDirs() map[string]string { if err != nil { return err } + // nolint:goconst + // FIXME: merge Env into Route, or fix the linter error if do != "local" { return nil } diff --git a/dagger/route.go b/dagger/route.go index 5773834c..3b1fed93 100644 --- a/dagger/route.go +++ b/dagger/route.go @@ -10,49 +10,112 @@ import ( type Route struct { // Globally unique route ID ID string + + // Human-friendly route name. + // A route may have more than one name. + Name string } -func CreateRoute(ctx context.Context, opts ...CreateOpt) (*Route, error) { +func CreateRoute(ctx context.Context, name string, o *CreateOpts) (*Route, error) { panic("NOT IMPLEMENTED") } -type CreateOpt interface{} // FIXME +type CreateOpts struct{} -func DeleteRoute(ctx context.Context, opts ...DeleteOpt) (*Route, error) { +func DeleteRoute(ctx context.Context, o *DeleteOpts) (*Route, error) { panic("NOT IMPLEMENTED") } -type DeleteOpt interface{} // FIXME +type DeleteOpts struct{} -func LookupRoute(name string, opts ...LookupOpt) (*Route, error) { +func LookupRoute(name string, o *LookupOpts) (*Route, error) { panic("NOT IMPLEMENTED") } -type LookupOpt interface{} // FIXME +type LookupOpts struct{} -func LoadRoute(ctx context.Context, id string, opts ...LoadOpt) (*Route, error) { +func LoadRoute(ctx context.Context, id string, o *LoadOpts) (*Route, error) { panic("NOT IMPLEMENTED") } -type LoadOpt interface{} // FIXME +type LoadOpts struct{} -func (r *Route) Up(ctx context.Context, opts ...UpOpt) error { +func (r *Route) Up(ctx context.Context, o *UpOpts) error { panic("NOT IMPLEMENTED") } -type UpOpt interface{} // FIXME +type UpOpts struct{} -func (r *Route) Down(ctx context.Context, opts ...DownOpt) error { +func (r *Route) Down(ctx context.Context, o *DownOpts) error { panic("NOT IMPLEMENTED") } -type DownOpt interface{} // FIXME +type DownOpts struct{} -func (r *Route) Query(ctx context.Context, expr interface{}, opts ...QueryOpt) (*compiler.Value, error) { +func (r *Route) Query(ctx context.Context, expr interface{}, o *QueryOpts) (*compiler.Value, error) { panic("NOT IMPLEMENTED") } -type QueryOpt interface{} // FIXME +type QueryOpts struct{} + +func (r *Route) SetLayout(ctx context.Context, a *Artifact) error { + panic("NOT IMPLEMENTED") +} + +func (r *Route) Layout() (*Artifact, error) { + panic("NOT IMPLEMENTED") +} + +func (r *Route) AddInputArtifact(ctx context.Context, target string, a *Artifact) error { + panic("NOT IMPLEMENTED") +} + +func (r *Route) AddInputValue(ctx context.Context, target string, v *compiler.Value) error { + panic("NOT IMPLEMENTED") +} + +// FIXME: how does remove work? Does it require a specific file layout? +func (r *Route) RemoveInputs(ctx context.Context, target string) error { + panic("NOT IMPLEMENTED") +} + +// FIXME: connect outputs to auto-export values and artifacts. + +// An artifact is a piece of data, like a source code checkout, +// binary bundle, container image, database backup etc. +// +// Artifacts can be passed as inputs, generated dynamically from +// other inputs, and received as outputs. +// +// Under the hood, an artifact is encoded as a LLB pipeline, and +// attached to the cue configuration as a +type Artifact struct { + llb interface{} +} + +func Dir(path string, include []string) *Artifact { + var llb struct { + Do string + Include []string + } + llb.Do = "local" + llb.Include = include + return &Artifact{ + llb: llb, + } +} + +func Git(remote, ref, dir string) *Artifact { + panic("NOT IMPLEMENTED") +} + +func Container(ref string) *Artifact { + panic("NOT IMPLEMENTED") +} + +func LLB(code interface{}) *Artifact { + panic("NOT IMPLEMENTED") +} // FIXME: manage base // FIXME: manage inputs