Fix partial CUE tree run for dagger do

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2022-03-02 18:33:15 -08:00
parent 0642e34388
commit 0786410bbd
5 changed files with 288 additions and 162 deletions

View File

@@ -55,29 +55,24 @@ var doCmd = &cobra.Command{
ctx := lg.WithContext(cmd.Context())
cl := common.NewClient(ctx)
p, err := loadPlan(getTargetPath(args).String())
p, err := loadPlan()
if err != nil {
lg.Fatal().Err(err).Msg("failed to load plan")
}
err = cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error {
_, err := p.Up(ctx, s)
if err != nil {
return err
}
return nil
return p.Do(ctx, getTargetPath(args), s)
})
// FIXME: rework telemetry
if err != nil {
lg.Fatal().Err(err).Msg("failed to up environment")
lg.Fatal().Err(err).Msg("failed to execute plan")
}
},
}
func loadPlan(target string) (*plan.Plan, error) {
func loadPlan() (*plan.Plan, error) {
planPath := viper.GetString("plan")
// support only local filesystem paths
@@ -95,26 +90,23 @@ func loadPlan(target string) (*plan.Plan, error) {
return plan.Load(context.Background(), plan.Config{
Args: []string{planPath},
With: viper.GetStringSlice("with"),
Target: target,
Vendor: !viper.GetBool("no-vendor"),
})
}
func getTargetPath(args []string) cue.Path {
actionLookupArgs := []string{plan.ActionsPath}
actionLookupArgs = append(actionLookupArgs, args...)
actionLookupSelectors := []cue.Selector{}
for _, a := range actionLookupArgs {
actionLookupSelectors = append(actionLookupSelectors, cue.Str(a))
selectors := []cue.Selector{plan.ActionSelector}
for _, arg := range args {
selectors = append(selectors, cue.Str(arg))
}
return cue.MakePath(actionLookupSelectors...)
return cue.MakePath(selectors...)
}
func doHelp(cmd *cobra.Command, _ []string) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.StripEscape)
defer w.Flush()
p, err := loadPlan("")
p, err := loadPlan()
if err != nil {
fmt.Printf("%s", err)
fmt.Fprintln(w, "failed to load plan")
@@ -125,7 +117,7 @@ func doHelp(cmd *cobra.Command, _ []string) {
actions := p.Action().FindByPath(actionLookupPath).Children
fmt.Printf(`Execute a dagger action.
%s
Plan loaded from %s:

View File

@@ -2,9 +2,9 @@ package cmd
import (
"context"
"fmt"
"os"
"cuelang.org/go/cue"
"go.dagger.io/dagger/client"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
@@ -89,24 +89,7 @@ func europaUp(ctx context.Context, cl *client.Client, args ...string) error {
}
return cl.Do(ctx, p.Context(), func(ctx context.Context, s solver.Solver) error {
computed, err := p.Up(ctx, s)
if err != nil {
return err
}
if output := viper.GetString("output"); output != "" {
data := computed.JSON().PrettyString()
if output == "-" {
fmt.Println(data)
return nil
}
err := os.WriteFile(output, []byte(data), 0600)
if err != nil {
lg.Fatal().Err(err).Str("path", output).Msg("failed to write output")
}
}
return nil
return p.Do(ctx, cue.ParsePath(viper.GetString("target")), s)
})
}