diff --git a/.golangci.yml b/.golangci.yml index 3e2d26a7..d6625717 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ run: skip-dirs: # progressui is a modified 3rd party library from buildkit - - pkg/progressui + - util/progressui linters: disable-all: true diff --git a/Makefile b/Makefile index 50641073..84457c4c 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,8 @@ lint: shellcheck cuelint golint check-buildkit-version check-buildkit-version: @test \ "$(shell grep buildkit ./go.mod | cut -d' ' -f2)" = \ - "$(shell grep ' = "v' ./pkg/buildkitd/buildkitd.go | sed -E 's/^.*version.*=.*\"(v.*)\"/\1/' )" \ - || { echo buildkit version mismatch go.mod != pkg/buildkitd/buildkitd.go ; exit 1; } + "$(shell grep ' = "v' ./util/buildkitd/buildkitd.go | sed -E 's/^.*version.*=.*\"(v.*)\"/\1/' )" \ + || { echo buildkit version mismatch go.mod != util/buildkitd/buildkitd.go ; exit 1; } .PHONY: integration integration: dagger-debug diff --git a/dagger/client.go b/client/client.go similarity index 77% rename from dagger/client.go rename to client/client.go index 3fcd8ff3..15506007 100644 --- a/dagger/client.go +++ b/client/client.go @@ -1,7 +1,8 @@ -package dagger +package client import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -22,11 +23,13 @@ import ( "github.com/moby/buildkit/session" // docker output - "dagger.io/go/pkg/buildkitd" - "dagger.io/go/pkg/progressui" + "go.dagger.io/dagger/util/buildkitd" + "go.dagger.io/dagger/util/progressui" - "dagger.io/go/dagger/compiler" - "dagger.io/go/dagger/state" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/environment" + "go.dagger.io/dagger/solver" + "go.dagger.io/dagger/state" ) // A dagger client @@ -35,7 +38,7 @@ type Client struct { noCache bool } -func NewClient(ctx context.Context, host string, noCache bool) (*Client, error) { +func New(ctx context.Context, host string, noCache bool) (*Client, error) { if host == "" { host = os.Getenv("BUILDKIT_HOST") } @@ -61,14 +64,14 @@ func NewClient(ctx context.Context, host string, noCache bool) (*Client, error) }, nil } -type ClientDoFunc func(context.Context, *Environment, Solver) error +type DoFunc func(context.Context, *environment.Environment, solver.Solver) error // FIXME: return completed *Route, instead of *compiler.Value -func (c *Client) Do(ctx context.Context, state *state.State, fn ClientDoFunc) (*Environment, error) { +func (c *Client) Do(ctx context.Context, state *state.State, fn DoFunc) (*environment.Environment, error) { lg := log.Ctx(ctx) eg, gctx := errgroup.WithContext(ctx) - environment, err := NewEnvironment(state) + environment, err := environment.New(state) if err != nil { return nil, err } @@ -90,11 +93,11 @@ func (c *Client) Do(ctx context.Context, state *state.State, fn ClientDoFunc) (* return environment, eg.Wait() } -func (c *Client) buildfn(ctx context.Context, environment *Environment, fn ClientDoFunc, ch chan *bk.SolveStatus) error { +func (c *Client) buildfn(ctx context.Context, env *environment.Environment, fn DoFunc, ch chan *bk.SolveStatus) error { lg := log.Ctx(ctx) // Scan local dirs to grant access - localdirs := environment.LocalDirs() + localdirs := env.LocalDirs() for label, dir := range localdirs { abs, err := filepath.Abs(dir) if err != nil { @@ -104,7 +107,7 @@ func (c *Client) buildfn(ctx context.Context, environment *Environment, fn Clien } // buildkit auth provider (registry) - auth := newRegistryAuthProvider() + auth := solver.NewRegistryAuthProvider() // Setup solve options opts := bk.SolveOpt{ @@ -119,16 +122,22 @@ func (c *Client) buildfn(ctx context.Context, environment *Environment, fn Clien Msg("spawning buildkit job") resp, err := c.c.Build(ctx, opts, "", func(ctx context.Context, gw bkgw.Client) (*bkgw.Result, error) { - s := NewSolver(c.c, gw, ch, auth, c.noCache) + s := solver.New(solver.Opts{ + Control: c.c, + Gateway: gw, + Events: ch, + Auth: auth, + NoCache: c.noCache, + }) lg.Debug().Msg("loading configuration") - if err := environment.LoadPlan(ctx, s); err != nil { + if err := env.LoadPlan(ctx, s); err != nil { return nil, err } // Compute output overlay if fn != nil { - if err := fn(ctx, environment, s); err != nil { + if err := fn(ctx, env, s); err != nil { return nil, compiler.Err(err) } } @@ -139,7 +148,7 @@ func (c *Client) buildfn(ctx context.Context, environment *Environment, fn Clien span, _ := opentracing.StartSpanFromContext(ctx, "Environment.Export") defer span.Finish() - computed := environment.Computed().JSON().PrettyString() + computed := env.Computed().JSON().PrettyString() st := llb. Scratch(). File( @@ -234,3 +243,22 @@ func (c *Client) logSolveStatus(ctx context.Context, ch chan *bk.SolveStatus) er }, ) } + +// A helper to remove noise from buildkit error messages. +// FIXME: Obviously a cleaner solution would be nice. +func bkCleanError(err error) error { + noise := []string{ + "executor failed running ", + "buildkit-runc did not terminate successfully", + "rpc error: code = Unknown desc = ", + "failed to solve: ", + } + + msg := err.Error() + + for _, s := range noise { + msg = strings.ReplaceAll(msg, s, "") + } + + return errors.New(msg) +} diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index 4c0aae01..cac81e68 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -3,10 +3,12 @@ package common import ( "context" - "dagger.io/go/dagger" - "dagger.io/go/dagger/state" "github.com/rs/zerolog/log" "github.com/spf13/viper" + "go.dagger.io/dagger/client" + "go.dagger.io/dagger/environment" + "go.dagger.io/dagger/solver" + "go.dagger.io/dagger/state" ) func CurrentWorkspace(ctx context.Context) *state.Workspace { @@ -79,14 +81,14 @@ func CurrentEnvironmentState(ctx context.Context, workspace *state.Workspace) *s } // Re-compute an environment (equivalent to `dagger up`). -func EnvironmentUp(ctx context.Context, state *state.State, noCache bool) *dagger.Environment { +func EnvironmentUp(ctx context.Context, state *state.State, noCache bool) *environment.Environment { lg := log.Ctx(ctx) - c, err := dagger.NewClient(ctx, "", noCache) + c, err := client.New(ctx, "", noCache) if err != nil { lg.Fatal().Err(err).Msg("unable to create client") } - result, err := c.Do(ctx, state, func(ctx context.Context, environment *dagger.Environment, s dagger.Solver) error { + result, err := c.Do(ctx, state, func(ctx context.Context, environment *environment.Environment, s solver.Solver) error { log.Ctx(ctx).Debug().Msg("bringing environment up") return environment.Up(ctx, s) }) diff --git a/cmd/dagger/cmd/compute.go b/cmd/dagger/cmd/compute.go index 2fb4b8b4..da719543 100644 --- a/cmd/dagger/cmd/compute.go +++ b/cmd/dagger/cmd/compute.go @@ -8,10 +8,10 @@ import ( "strings" "cuelang.org/go/cue" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/compiler" - "dagger.io/go/dagger/state" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/state" "go.mozilla.org/sops/v3" "go.mozilla.org/sops/v3/decrypt" diff --git a/cmd/dagger/cmd/init.go b/cmd/dagger/cmd/init.go index c47346f7..9d5d1872 100644 --- a/cmd/dagger/cmd/init.go +++ b/cmd/dagger/cmd/init.go @@ -3,10 +3,10 @@ package cmd import ( "os" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var initCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/container.go b/cmd/dagger/cmd/input/container.go index 6ced900f..c9da5d41 100644 --- a/cmd/dagger/cmd/input/container.go +++ b/cmd/dagger/cmd/input/container.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var containerCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/dir.go b/cmd/dagger/cmd/input/dir.go index 0e23ccee..8d389cdd 100644 --- a/cmd/dagger/cmd/input/dir.go +++ b/cmd/dagger/cmd/input/dir.go @@ -4,11 +4,11 @@ import ( "path/filepath" "strings" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var dirCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/git.go b/cmd/dagger/cmd/input/git.go index f718b395..4fdd5898 100644 --- a/cmd/dagger/cmd/input/git.go +++ b/cmd/dagger/cmd/input/git.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var gitCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/json.go b/cmd/dagger/cmd/input/json.go index 508328bf..03f5ec9d 100644 --- a/cmd/dagger/cmd/input/json.go +++ b/cmd/dagger/cmd/input/json.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var jsonCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/list.go b/cmd/dagger/cmd/input/list.go index bc1faeb8..6dd65538 100644 --- a/cmd/dagger/cmd/input/list.go +++ b/cmd/dagger/cmd/input/list.go @@ -6,11 +6,13 @@ import ( "os" "text/tabwriter" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger" - "dagger.io/go/dagger/compiler" - "dagger.io/go/dagger/state" + "go.dagger.io/dagger/client" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/environment" + "go.dagger.io/dagger/solver" + "go.dagger.io/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -32,19 +34,19 @@ var listCmd = &cobra.Command{ ctx := lg.WithContext(cmd.Context()) workspace := common.CurrentWorkspace(ctx) - environment := common.CurrentEnvironmentState(ctx, workspace) + st := common.CurrentEnvironmentState(ctx, workspace) lg = lg.With(). - Str("environment", environment.Name). + Str("environment", st.Name). Logger() - c, err := dagger.NewClient(ctx, "", false) + c, err := client.New(ctx, "", false) if err != nil { lg.Fatal().Err(err).Msg("unable to create client") } - _, err = c.Do(ctx, environment, func(lCtx context.Context, lDeploy *dagger.Environment, lSolver dagger.Solver) error { - inputs := lDeploy.ScanInputs(ctx) + _, err = c.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { + inputs := env.ScanInputs(ctx) w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) fmt.Fprintln(w, "Input\tType\tValue\tSet by user") @@ -71,7 +73,7 @@ var listCmd = &cobra.Command{ inp.Path(), getType(inp), valStr, - isUserSet(environment, inp), + isUserSet(st, inp), ) } diff --git a/cmd/dagger/cmd/input/root.go b/cmd/dagger/cmd/input/root.go index e9cf2e75..ef1ae3cf 100644 --- a/cmd/dagger/cmd/input/root.go +++ b/cmd/dagger/cmd/input/root.go @@ -5,11 +5,11 @@ import ( "io" "os" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/dagger/state" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/state" ) // Cmd exposes the top-level command diff --git a/cmd/dagger/cmd/input/secret.go b/cmd/dagger/cmd/input/secret.go index 24e4f29c..9570d99a 100644 --- a/cmd/dagger/cmd/input/secret.go +++ b/cmd/dagger/cmd/input/secret.go @@ -4,10 +4,10 @@ import ( "fmt" "syscall" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" "golang.org/x/term" ) diff --git a/cmd/dagger/cmd/input/text.go b/cmd/dagger/cmd/input/text.go index 19f32520..d5cfbe10 100644 --- a/cmd/dagger/cmd/input/text.go +++ b/cmd/dagger/cmd/input/text.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var textCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/unset.go b/cmd/dagger/cmd/input/unset.go index 9b643c0b..b122d7f7 100644 --- a/cmd/dagger/cmd/input/unset.go +++ b/cmd/dagger/cmd/input/unset.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" ) var unsetCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/input/yaml.go b/cmd/dagger/cmd/input/yaml.go index 6afceecd..db1b0025 100644 --- a/cmd/dagger/cmd/input/yaml.go +++ b/cmd/dagger/cmd/input/yaml.go @@ -1,10 +1,10 @@ package input import ( - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger/state" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/state" ) var yamlCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/list.go b/cmd/dagger/cmd/list.go index 4e1fb8d0..ea29b2a5 100644 --- a/cmd/dagger/cmd/list.go +++ b/cmd/dagger/cmd/list.go @@ -8,10 +8,10 @@ import ( "strings" "text/tabwriter" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" ) var listCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/new.go b/cmd/dagger/cmd/new.go index c2c019c0..81979cfc 100644 --- a/cmd/dagger/cmd/new.go +++ b/cmd/dagger/cmd/new.go @@ -1,10 +1,10 @@ package cmd import ( - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" ) var newCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/query.go b/cmd/dagger/cmd/query.go index 2c689d5e..d4b895de 100644 --- a/cmd/dagger/cmd/query.go +++ b/cmd/dagger/cmd/query.go @@ -4,10 +4,10 @@ import ( "fmt" "cuelang.org/go/cue" - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" - "dagger.io/go/dagger" - "dagger.io/go/dagger/compiler" + "go.dagger.io/dagger/client" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" + "go.dagger.io/dagger/compiler" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -42,7 +42,7 @@ var queryCmd = &cobra.Command{ cuePath = cue.ParsePath(args[0]) } - c, err := dagger.NewClient(ctx, "", false) + c, err := client.New(ctx, "", false) if err != nil { lg.Fatal().Err(err).Msg("unable to create client") } diff --git a/cmd/dagger/cmd/root.go b/cmd/dagger/cmd/root.go index 77006d9c..19ab0229 100644 --- a/cmd/dagger/cmd/root.go +++ b/cmd/dagger/cmd/root.go @@ -4,14 +4,14 @@ import ( "os" "strings" - "dagger.io/go/cmd/dagger/cmd/input" - "dagger.io/go/cmd/dagger/cmd/output" - "dagger.io/go/cmd/dagger/logger" "github.com/moby/buildkit/util/appcontext" "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.dagger.io/dagger/cmd/dagger/cmd/input" + "go.dagger.io/dagger/cmd/dagger/cmd/output" + "go.dagger.io/dagger/cmd/dagger/logger" ) var rootCmd = &cobra.Command{ diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 440216c5..bd4d72a9 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -1,8 +1,8 @@ package cmd import ( - "dagger.io/go/cmd/dagger/cmd/common" - "dagger.io/go/cmd/dagger/logger" + "go.dagger.io/dagger/cmd/dagger/cmd/common" + "go.dagger.io/dagger/cmd/dagger/logger" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/cmd/dagger/cmd/version.go b/cmd/dagger/cmd/version.go index 66b3bfe8..665cc2fb 100644 --- a/cmd/dagger/cmd/version.go +++ b/cmd/dagger/cmd/version.go @@ -25,7 +25,7 @@ const ( ) // set by goreleaser or other builder using -// -ldflags='-X dagger.io/go/cmd/dagger/cmd.version=' +// -ldflags='-X go.dagger.io/dagger/cmd/dagger/cmd.version=' var ( version = defaultVersion versionMessage = "" diff --git a/cmd/dagger/main.go b/cmd/dagger/main.go index 71a7cdaa..88d325d5 100644 --- a/cmd/dagger/main.go +++ b/cmd/dagger/main.go @@ -1,7 +1,7 @@ package main import ( - "dagger.io/go/cmd/dagger/cmd" + "go.dagger.io/dagger/cmd/dagger/cmd" ) func main() { diff --git a/dagger/compiler/build.go b/compiler/build.go similarity index 100% rename from dagger/compiler/build.go rename to compiler/build.go diff --git a/dagger/compiler/compiler.go b/compiler/compiler.go similarity index 100% rename from dagger/compiler/compiler.go rename to compiler/compiler.go diff --git a/dagger/compiler/compiler_test.go b/compiler/compiler_test.go similarity index 100% rename from dagger/compiler/compiler_test.go rename to compiler/compiler_test.go diff --git a/dagger/compiler/json.go b/compiler/json.go similarity index 100% rename from dagger/compiler/json.go rename to compiler/json.go diff --git a/dagger/compiler/value.go b/compiler/value.go similarity index 100% rename from dagger/compiler/value.go rename to compiler/value.go diff --git a/dagger/environment.go b/environment/environment.go similarity index 92% rename from dagger/environment.go rename to environment/environment.go index b12673bf..e6db32bc 100644 --- a/dagger/environment.go +++ b/environment/environment.go @@ -1,4 +1,4 @@ -package dagger +package environment import ( "context" @@ -9,9 +9,10 @@ import ( "cuelang.org/go/cue" cueflow "cuelang.org/go/tools/flow" - "dagger.io/go/dagger/compiler" - "dagger.io/go/dagger/state" - "dagger.io/go/stdlib" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/solver" + "go.dagger.io/dagger/state" + "go.dagger.io/dagger/stdlib" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" @@ -32,7 +33,7 @@ type Environment struct { computed *compiler.Value } -func NewEnvironment(st *state.State) (*Environment, error) { +func New(st *state.State) (*Environment, error) { e := &Environment{ state: st, @@ -81,7 +82,7 @@ func (e *Environment) Computed() *compiler.Value { } // LoadPlan loads the plan -func (e *Environment) LoadPlan(ctx context.Context, s Solver) error { +func (e *Environment) LoadPlan(ctx context.Context, s solver.Solver) error { span, ctx := opentracing.StartSpanFromContext(ctx, "environment.LoadPlan") defer span.Finish() @@ -165,7 +166,7 @@ func (e *Environment) LocalDirs() map[string]string { } // Up missing values in environment configuration, and write them to state. -func (e *Environment) Up(ctx context.Context, s Solver) error { +func (e *Environment) Up(ctx context.Context, s solver.Solver) error { span, ctx := opentracing.StartSpanFromContext(ctx, "environment.Up") defer span.Finish() @@ -216,7 +217,7 @@ func noOpRunner(t *cueflow.Task) error { return nil } -func newPipelineRunner(computed *compiler.Value, s Solver) cueflow.RunnerFunc { +func newPipelineRunner(computed *compiler.Value, s solver.Solver) cueflow.RunnerFunc { return cueflow.RunnerFunc(func(t *cueflow.Task) error { ctx := t.Context() lg := log. @@ -294,5 +295,5 @@ func newPipelineRunner(computed *compiler.Value, s Solver) cueflow.RunnerFunc { } func (e *Environment) ScanInputs(ctx context.Context) []*compiler.Value { - return ScanInputs(ctx, e.plan) + return scanInputs(ctx, e.plan) } diff --git a/dagger/environment_test.go b/environment/environment_test.go similarity index 83% rename from dagger/environment_test.go rename to environment/environment_test.go index 3da6ba6c..f35bc1c4 100644 --- a/dagger/environment_test.go +++ b/environment/environment_test.go @@ -1,10 +1,10 @@ -package dagger +package environment import ( "testing" - "dagger.io/go/dagger/state" "github.com/stretchr/testify/require" + "go.dagger.io/dagger/state" ) func TestLocalDirs(t *testing.T) { @@ -14,7 +14,7 @@ func TestLocalDirs(t *testing.T) { } require.NoError(t, st.SetInput("www.source", state.DirInput("/", []string{}))) - environment, err := NewEnvironment(st) + environment, err := New(st) require.NoError(t, err) localdirs := environment.LocalDirs() diff --git a/dagger/inputs_scan.go b/environment/inputs_scan.go similarity index 90% rename from dagger/inputs_scan.go rename to environment/inputs_scan.go index 2b04becc..9fcea5b0 100644 --- a/dagger/inputs_scan.go +++ b/environment/inputs_scan.go @@ -1,11 +1,11 @@ -package dagger +package environment import ( "context" "cuelang.org/go/cue" - "dagger.io/go/dagger/compiler" "github.com/rs/zerolog/log" + "go.dagger.io/dagger/compiler" ) func isReference(val cue.Value) bool { @@ -42,7 +42,7 @@ func isReference(val cue.Value) bool { return isRef(val) } -func ScanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value { +func scanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value { lg := log.Ctx(ctx) inputs := []*compiler.Value{} diff --git a/dagger/pipeline.go b/environment/pipeline.go similarity index 98% rename from dagger/pipeline.go rename to environment/pipeline.go index 04b7d436..226e0830 100644 --- a/dagger/pipeline.go +++ b/environment/pipeline.go @@ -1,4 +1,4 @@ -package dagger +package environment import ( "bytes" @@ -25,7 +25,8 @@ import ( "github.com/rs/zerolog/log" "gopkg.in/yaml.v3" - "dagger.io/go/dagger/compiler" + "go.dagger.io/dagger/compiler" + "go.dagger.io/dagger/solver" ) const ( @@ -36,14 +37,14 @@ const ( type Pipeline struct { code *compiler.Value name string - s Solver + s solver.Solver state llb.State result bkgw.Reference image dockerfile2llb.Image computed *compiler.Value } -func NewPipeline(code *compiler.Value, s Solver) *Pipeline { +func NewPipeline(code *compiler.Value, s solver.Solver) *Pipeline { return &Pipeline{ code: code, name: code.Path().String(), @@ -70,7 +71,7 @@ func (p *Pipeline) Result() (llb.State, error) { } func (p *Pipeline) FS() fs.FS { - return NewBuildkitFS(p.result) + return solver.NewBuildkitFS(p.result) } func (p *Pipeline) ImageConfig() dockerfile2llb.Image { @@ -641,7 +642,7 @@ func (p *Pipeline) DockerLogin(ctx context.Context, op *compiler.Value, st llb.S return st, err } - p.s.auth.AddCredentials(target, username, secret) + p.s.AddCredentials(target, username, secret) log. Ctx(ctx). Debug(). @@ -862,7 +863,7 @@ func (p *Pipeline) DockerBuild(ctx context.Context, op *compiler.Value, st llb.S return st, err } - if p.s.noCache { + if p.s.NoCache() { opts["no-cache"] = "" } diff --git a/go.mod b/go.mod index 5e742046..c21e5cdc 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module dagger.io/go +module go.dagger.io/dagger go 1.16 diff --git a/dagger/keychain/encrypt.go b/keychain/encrypt.go similarity index 100% rename from dagger/keychain/encrypt.go rename to keychain/encrypt.go diff --git a/dagger/keychain/keys.go b/keychain/keys.go similarity index 100% rename from dagger/keychain/keys.go rename to keychain/keys.go diff --git a/dagger/fs.go b/solver/fs.go similarity index 99% rename from dagger/fs.go rename to solver/fs.go index ecae9401..dd208256 100644 --- a/dagger/fs.go +++ b/solver/fs.go @@ -1,4 +1,4 @@ -package dagger +package solver import ( "context" diff --git a/dagger/registryauth.go b/solver/registryauth.go similarity index 76% rename from dagger/registryauth.go rename to solver/registryauth.go index 5acd618a..af17d38e 100644 --- a/dagger/registryauth.go +++ b/solver/registryauth.go @@ -1,4 +1,4 @@ -package dagger +package solver import ( "context" @@ -12,20 +12,20 @@ import ( "google.golang.org/grpc/status" ) -// registryAuthProvider is a buildkit provider for registry authentication +// RegistryAuthProvider is a buildkit provider for registry authentication // Adapted from: https://github.com/moby/buildkit/blob/master/session/auth/authprovider/authprovider.go -type registryAuthProvider struct { +type RegistryAuthProvider struct { credentials map[string]*bkauth.CredentialsResponse m sync.RWMutex } -func newRegistryAuthProvider() *registryAuthProvider { - return ®istryAuthProvider{ +func NewRegistryAuthProvider() *RegistryAuthProvider { + return &RegistryAuthProvider{ credentials: map[string]*bkauth.CredentialsResponse{}, } } -func (a *registryAuthProvider) AddCredentials(target, username, secret string) { +func (a *RegistryAuthProvider) AddCredentials(target, username, secret string) { a.m.Lock() defer a.m.Unlock() @@ -35,11 +35,11 @@ func (a *registryAuthProvider) AddCredentials(target, username, secret string) { } } -func (a *registryAuthProvider) Register(server *grpc.Server) { +func (a *RegistryAuthProvider) Register(server *grpc.Server) { bkauth.RegisterAuthServer(server, a) } -func (a *registryAuthProvider) Credentials(ctx context.Context, req *bkauth.CredentialsRequest) (*bkauth.CredentialsResponse, error) { +func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.CredentialsRequest) (*bkauth.CredentialsResponse, error) { reqURL, err := parseAuthHost(req.Host) if err != nil { return nil, err @@ -73,14 +73,14 @@ func parseAuthHost(host string) (*url.URL, error) { return url.Parse(host) } -func (a *registryAuthProvider) FetchToken(ctx context.Context, req *bkauth.FetchTokenRequest) (rr *bkauth.FetchTokenResponse, err error) { +func (a *RegistryAuthProvider) FetchToken(ctx context.Context, req *bkauth.FetchTokenRequest) (rr *bkauth.FetchTokenResponse, err error) { return nil, status.Errorf(codes.Unavailable, "client side tokens not implemented") } -func (a *registryAuthProvider) GetTokenAuthority(ctx context.Context, req *bkauth.GetTokenAuthorityRequest) (*bkauth.GetTokenAuthorityResponse, error) { +func (a *RegistryAuthProvider) GetTokenAuthority(ctx context.Context, req *bkauth.GetTokenAuthorityRequest) (*bkauth.GetTokenAuthorityResponse, error) { return nil, status.Errorf(codes.Unavailable, "client side tokens not implemented") } -func (a *registryAuthProvider) VerifyTokenAuthority(ctx context.Context, req *bkauth.VerifyTokenAuthorityRequest) (*bkauth.VerifyTokenAuthorityResponse, error) { +func (a *RegistryAuthProvider) VerifyTokenAuthority(ctx context.Context, req *bkauth.VerifyTokenAuthorityRequest) (*bkauth.VerifyTokenAuthorityResponse, error) { return nil, status.Errorf(codes.Unavailable, "client side tokens not implemented") } diff --git a/dagger/solver.go b/solver/solver.go similarity index 78% rename from dagger/solver.go rename to solver/solver.go index e057155b..4a33ac62 100644 --- a/dagger/solver.go +++ b/solver/solver.go @@ -1,11 +1,9 @@ -package dagger +package solver import ( "context" "encoding/json" - "errors" "fmt" - "strings" bk "github.com/moby/buildkit/client" "github.com/moby/buildkit/client/llb" @@ -19,20 +17,20 @@ import ( ) type Solver struct { - events chan *bk.SolveStatus - control *bk.Client - gw bkgw.Client - auth *registryAuthProvider - noCache bool + opts Opts } -func NewSolver(control *bk.Client, gw bkgw.Client, events chan *bk.SolveStatus, auth *registryAuthProvider, noCache bool) Solver { +type Opts struct { + Control *bk.Client + Gateway bkgw.Client + Events chan *bk.SolveStatus + Auth *RegistryAuthProvider + NoCache bool +} + +func New(opts Opts) Solver { return Solver{ - events: events, - control: control, - gw: gw, - auth: auth, - noCache: noCache, + opts: opts, } } @@ -55,6 +53,14 @@ func invalidateCache(def *llb.Definition) error { return nil } +func (s Solver) NoCache() bool { + return s.opts.NoCache +} + +func (s Solver) AddCredentials(target, username, secret string) { + s.opts.Auth.AddCredentials(target, username, secret) +} + func (s Solver) Marshal(ctx context.Context, st llb.State) (*bkpb.Definition, error) { // FIXME: do not hardcode the platform def, err := st.Marshal(ctx, llb.LinuxAmd64) @@ -62,7 +68,7 @@ func (s Solver) Marshal(ctx context.Context, st llb.State) (*bkpb.Definition, er return nil, err } - if s.noCache { + if s.opts.NoCache { if err := invalidateCache(def); err != nil { return nil, err } @@ -72,7 +78,7 @@ func (s Solver) Marshal(ctx context.Context, st llb.State) (*bkpb.Definition, er } func (s Solver) SessionID() string { - return s.gw.BuildOpts().SessionID + return s.opts.Gateway.BuildOpts().SessionID } func (s Solver) ResolveImageConfig(ctx context.Context, ref string, opts llb.ResolveImageConfigOpt) (dockerfile2llb.Image, error) { @@ -81,7 +87,7 @@ func (s Solver) ResolveImageConfig(ctx context.Context, ref string, opts llb.Res // Load image metadata and convert to to LLB. // Inspired by https://github.com/moby/buildkit/blob/master/frontend/dockerfile/dockerfile2llb/convert.go // FIXME: this needs to handle platform - _, meta, err := s.gw.ResolveImageConfig(ctx, ref, opts) + _, meta, err := s.opts.Gateway.ResolveImageConfig(ctx, ref, opts) if err != nil { return image, err } @@ -94,12 +100,7 @@ func (s Solver) ResolveImageConfig(ctx context.Context, ref string, opts llb.Res // Solve will block until the state is solved and returns a Reference. func (s Solver) SolveRequest(ctx context.Context, req bkgw.SolveRequest) (*bkgw.Result, error) { - // call solve - res, err := s.gw.Solve(ctx, req) - if err != nil { - return nil, bkCleanError(err) - } - return res, nil + return s.opts.Gateway.Solve(ctx, req) } // Solve will block until the state is solved and returns a Reference. @@ -149,7 +150,7 @@ func (s Solver) Export(ctx context.Context, st llb.State, img *dockerfile2llb.Im opts := bk.SolveOpt{ Exports: []bk.ExportEntry{output}, - Session: []session.Attachable{s.auth}, + Session: []session.Attachable{s.opts.Auth}, } ch := make(chan *bk.SolveStatus) @@ -158,11 +159,11 @@ func (s Solver) Export(ctx context.Context, st llb.State, img *dockerfile2llb.Im // purposes. go func() { for event := range ch { - s.events <- event + s.opts.Events <- event } }() - return s.control.Build(ctx, opts, "", func(ctx context.Context, c bkgw.Client) (*bkgw.Result, error) { + return s.opts.Control.Build(ctx, opts, "", func(ctx context.Context, c bkgw.Client) (*bkgw.Result, error) { res, err := c.Solve(ctx, bkgw.SolveRequest{ Definition: def, }) @@ -203,22 +204,3 @@ func dumpLLB(def *bkpb.Definition) ([]byte, error) { } return json.Marshal(ops) } - -// A helper to remove noise from buildkit error messages. -// FIXME: Obviously a cleaner solution would be nice. -func bkCleanError(err error) error { - noise := []string{ - "executor failed running ", - "buildkit-runc did not terminate successfully", - "rpc error: code = Unknown desc = ", - "failed to solve: ", - } - - msg := err.Error() - - for _, s := range noise { - msg = strings.ReplaceAll(msg, s, "") - } - - return errors.New(msg) -} diff --git a/dagger/state/input.go b/state/input.go similarity index 99% rename from dagger/state/input.go rename to state/input.go index 4c06e47e..c29e5e0d 100644 --- a/dagger/state/input.go +++ b/state/input.go @@ -10,7 +10,7 @@ import ( "cuelang.org/go/cue" - "dagger.io/go/dagger/compiler" + "go.dagger.io/dagger/compiler" ) // An input is a value or artifact supplied by the user. diff --git a/dagger/state/state.go b/state/state.go similarity index 100% rename from dagger/state/state.go rename to state/state.go diff --git a/dagger/state/workspace.go b/state/workspace.go similarity index 99% rename from dagger/state/workspace.go rename to state/workspace.go index 4a516401..6b926390 100644 --- a/dagger/state/workspace.go +++ b/state/workspace.go @@ -9,8 +9,8 @@ import ( "path" "path/filepath" - "dagger.io/go/dagger/keychain" "github.com/rs/zerolog/log" + "go.dagger.io/dagger/keychain" "gopkg.in/yaml.v3" ) diff --git a/dagger/state/workspace_test.go b/state/workspace_test.go similarity index 100% rename from dagger/state/workspace_test.go rename to state/workspace_test.go diff --git a/pkg/buildkitd/buildkitd.go b/util/buildkitd/buildkitd.go similarity index 100% rename from pkg/buildkitd/buildkitd.go rename to util/buildkitd/buildkitd.go diff --git a/pkg/progressui/display.go b/util/progressui/display.go similarity index 100% rename from pkg/progressui/display.go rename to util/progressui/display.go diff --git a/pkg/progressui/printer.go b/util/progressui/printer.go similarity index 100% rename from pkg/progressui/printer.go rename to util/progressui/printer.go