diff --git a/cmd/dagger/cmd/common/common.go b/cmd/dagger/cmd/common/common.go index 8285573fa86..7969e1e9666 100644 --- a/cmd/dagger/cmd/common/common.go +++ b/cmd/dagger/cmd/common/common.go @@ -9,8 +9,6 @@ import ( "github.com/spf13/viper" "go.dagger.io/dagger/client" "go.dagger.io/dagger/compiler" - "go.dagger.io/dagger/environment" - "go.dagger.io/dagger/solver" "go.dagger.io/dagger/state" ) @@ -83,20 +81,6 @@ func CurrentEnvironmentState(ctx context.Context, workspace *state.Workspace) *s return environments[0] } -// Re-compute an environment (equivalent to `dagger up`). -func EnvironmentUp(ctx context.Context, cl *client.Client, state *state.State, noCache bool) *environment.Environment { - lg := log.Ctx(ctx) - - result, err := cl.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) - }) - if err != nil { - lg.Fatal().Err(err).Msg("failed to up environment") - } - return result -} - // FormatValue returns the String representation of the cue value func FormatValue(val *compiler.Value) string { if val.HasAttr("artifact") { diff --git a/cmd/dagger/cmd/compute.go b/cmd/dagger/cmd/compute.go index cdc2e2da77e..ebda5a8e4e6 100644 --- a/cmd/dagger/cmd/compute.go +++ b/cmd/dagger/cmd/compute.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "encoding/json" "errors" "fmt" @@ -8,10 +9,11 @@ import ( "strings" "cuelang.org/go/cue" - "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" "go.mozilla.org/sops/v3" "go.mozilla.org/sops/v3/decrypt" @@ -164,11 +166,18 @@ var computeCmd = &cobra.Command{ } } - cl, err := client.New(ctx, "", false) + cl := common.NewClient(ctx, viper.GetBool("no-cache")) + + environment, err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { + // check that all inputs are set + checkInputs(ctx, env) + + return env.Up(ctx, s) + }) + if err != nil { - lg.Fatal().Err(err).Msg("unable to create client") + lg.Fatal().Err(err).Msg("failed to up environment") } - environment := common.EnvironmentUp(ctx, cl, st, viper.GetBool("no-cache")) v := compiler.NewValue() if err := v.FillPath(cue.MakePath(), environment.Plan()); err != nil { diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 361e9e0f73a..b81e1ecda0a 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -5,14 +5,12 @@ import ( "os" "cuelang.org/go/cue" - "go.dagger.io/dagger/client" "go.dagger.io/dagger/cmd/dagger/cmd/common" "go.dagger.io/dagger/cmd/dagger/cmd/output" "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" "golang.org/x/term" "github.com/rs/zerolog/log" @@ -40,10 +38,16 @@ var upCmd = &cobra.Command{ cl := common.NewClient(ctx, viper.GetBool("no-cache")) - // check that all inputs are set - checkInputs(ctx, cl, st) + result, err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { + // check that all inputs are set + checkInputs(ctx, env) - result := common.EnvironmentUp(ctx, cl, st, viper.GetBool("no-cache")) + return env.Up(ctx, s) + }) + + if err != nil { + lg.Fatal().Err(err).Msg("failed to up environment") + } st.Computed = result.Computed().JSON().PrettyString() if err := workspace.Save(ctx, st); err != nil { @@ -54,28 +58,20 @@ var upCmd = &cobra.Command{ }, } -func checkInputs(ctx context.Context, cl *client.Client, st *state.State) { +func checkInputs(ctx context.Context, env *environment.Environment) { lg := log.Ctx(ctx) warnOnly := viper.GetBool("force") notConcreteInputs := []*compiler.Value{} - _, err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error { - inputs, err := env.ScanInputs(ctx, true) - if err != nil { - return err - } + inputs, err := env.ScanInputs(ctx, true) + if err != nil { + lg.Fatal().Err(err).Msg("failed to scan inputs") + } - for _, i := range inputs { - if i.IsConcreteR(cue.Optional(true)) != nil { - notConcreteInputs = append(notConcreteInputs, i) - } + for _, i := range inputs { + if i.IsConcreteR(cue.Optional(true)) != nil { + notConcreteInputs = append(notConcreteInputs, i) } - - return nil - }) - - if err != nil { - lg.Fatal().Err(err).Msg("failed to query environment") } for _, i := range notConcreteInputs {