From 1d8834b9b1ec9144e8c8b4a8d345f3d655851d46 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 10:23:21 -0700 Subject: [PATCH 1/7] implemented --with to fill inputs.params Signed-off-by: Richard Jones --- cmd/dagger/cmd/up.go | 5 ++++- plan/plan.go | 17 ++++++++++++++++- stdlib/europa/dagger/engine/plan.cue | 5 +---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 721f8af1..b1b14a8f 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -24,6 +24,8 @@ import ( "github.com/spf13/viper" ) +var withParams []string + var upCmd = &cobra.Command{ Use: "up", Short: "Bring an environment online with latest plan and inputs", @@ -142,7 +144,7 @@ func checkUniverseVersion(ctx context.Context, projectPath string) bool { func europaUp(ctx context.Context, cl *client.Client, args ...string) error { lg := log.Ctx(ctx) - p, err := plan.Load(ctx, args...) + p, err := plan.Load(ctx, withParams, args...) if err != nil { lg.Fatal().Err(err).Msg("failed to load plan") } @@ -220,6 +222,7 @@ func checkInputs(ctx context.Context, env *environment.Environment) error { func init() { upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check") upCmd.Flags().String("output", "", "Write computed output. Prints on stdout if set to-") + upCmd.Flags().StringArrayVarP(&withParams, "with", "w", []string{}, "") if err := viper.BindPFlags(upCmd.Flags()); err != nil { panic(err) diff --git a/plan/plan.go b/plan/plan.go index 659b79d6..fe6e7581 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -23,7 +23,7 @@ type Plan struct { source *compiler.Value } -func Load(ctx context.Context, args ...string) (*Plan, error) { +func Load(ctx context.Context, withParams []string, args ...string) (*Plan, error) { log.Ctx(ctx).Debug().Interface("args", args).Msg("loading plan") // FIXME: universe vendoring @@ -36,6 +36,21 @@ func Load(ctx context.Context, args ...string) (*Plan, error) { return nil, err } + if len(withParams) > 0 { + for i, param := range withParams { + log.Ctx(ctx).Debug().Interface("with", param).Msg("applying parameter") + paramV, err := compiler.Compile(fmt.Sprintf("with%v", i), param) + if err != nil { + return nil, err + } + + fillErr := v.FillPath(cue.ParsePath("inputs.params"), paramV) + if fillErr != nil { + return nil, err + } + } + } + p := &Plan{ context: plancontext.New(), source: v, diff --git a/stdlib/europa/dagger/engine/plan.cue b/stdlib/europa/dagger/engine/plan.cue index 29b2efaf..20ebce6a 100644 --- a/stdlib/europa/dagger/engine/plan.cue +++ b/stdlib/europa/dagger/engine/plan.cue @@ -12,10 +12,7 @@ package engine // Securely receive secrets secrets: [name=string]: _#inputSecret // Receive runtime parameters - params: { - @dagger(notimplemented) - [name=string]: _ - } + params: [name=string]: _ } // Send outputs to the client From 6f4a5a769ce806d744ec49cc88eda5b6d3629b42 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 10:25:32 -0700 Subject: [PATCH 2/7] initial test Signed-off-by: Richard Jones --- tests/plan.bats | 5 +++++ tests/plan/inputs/params/main.cue | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/plan/inputs/params/main.cue diff --git a/tests/plan.bats b/tests/plan.bats index 51ee02c7..ce83a5b3 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -82,6 +82,11 @@ setup() { assert_output --partial 'failed: exec: "rtyet": executable file not found' } +@test "plan/params" { + cd "$TESTDIR" + "$DAGGER" --europa up --with 'foo:"bar"' ./plan/inputs/params/main.cue +} + @test "plan/outputs" { cd "$TESTDIR"/plan/outputs diff --git a/tests/plan/inputs/params/main.cue b/tests/plan/inputs/params/main.cue new file mode 100644 index 00000000..402ac379 --- /dev/null +++ b/tests/plan/inputs/params/main.cue @@ -0,0 +1,26 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + inputs: params: foo: string + + actions: { + image: engine.#Pull & { + source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" + } + + verify: engine.#Exec & { + input: image.output + env: FOO: inputs.params.foo + args: [ + "sh", "-c", + #""" + test "$FOO" = "bar" + """#, + ] + } + } +} From c61d47722ebf1ee42681837675098bbff41628ad Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 11:32:05 -0700 Subject: [PATCH 3/7] allowing --with to fill root object Signed-off-by: Richard Jones --- plan/plan.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plan/plan.go b/plan/plan.go index fe6e7581..39398ffd 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -38,15 +38,16 @@ func Load(ctx context.Context, withParams []string, args ...string) (*Plan, erro if len(withParams) > 0 { for i, param := range withParams { - log.Ctx(ctx).Debug().Interface("with", param).Msg("applying parameter") + log.Ctx(ctx).Debug().Interface("with", param).Msg("compiling parameter") paramV, err := compiler.Compile(fmt.Sprintf("with%v", i), param) if err != nil { return nil, err } - fillErr := v.FillPath(cue.ParsePath("inputs.params"), paramV) + log.Ctx(ctx).Debug().Interface("with", param).Msg("filling parameter") + fillErr := v.FillPath(cue.ParsePath(""), paramV) if fillErr != nil { - return nil, err + return nil, fillErr } } } From 7292d62cd6f76bd8c7763cd18667c3bd0cd65879 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 11:32:26 -0700 Subject: [PATCH 4/7] more tests Signed-off-by: Richard Jones --- tests/plan.bats | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/plan.bats b/tests/plan.bats index ce83a5b3..52b567a4 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -84,7 +84,15 @@ setup() { @test "plan/params" { cd "$TESTDIR" - "$DAGGER" --europa up --with 'foo:"bar"' ./plan/inputs/params/main.cue + "$DAGGER" --europa up --with 'inputs: params: foo:"bar"' ./plan/inputs/params/main.cue + + run "$DAGGER" --europa up --with 'inputs: params: foo:1' ./plan/inputs/params/main.cue + assert_failure + assert_output --partial "conflicting values string and 1" + + run "$DAGGER" --europa up ./plan/inputs/params/main.cue + assert_failure + assert_output --partial "actions.verify.env.FOO: non-concrete value string" } @test "plan/outputs" { From b4bcbab31118446a256f4a400ac435e293e34ae7 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 11:54:50 -0700 Subject: [PATCH 5/7] passing struct to plan.Load Signed-off-by: Richard Jones --- cmd/dagger/cmd/up.go | 10 ++++++---- plan/plan.go | 36 +++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index b1b14a8f..925bf248 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -24,8 +24,6 @@ import ( "github.com/spf13/viper" ) -var withParams []string - var upCmd = &cobra.Command{ Use: "up", Short: "Bring an environment online with latest plan and inputs", @@ -144,7 +142,11 @@ func checkUniverseVersion(ctx context.Context, projectPath string) bool { func europaUp(ctx context.Context, cl *client.Client, args ...string) error { lg := log.Ctx(ctx) - p, err := plan.Load(ctx, withParams, args...) + p, err := plan.Load(ctx, plan.Config{ + Args: args, + With: viper.GetStringSlice("with"), + }) + if err != nil { lg.Fatal().Err(err).Msg("failed to load plan") } @@ -222,7 +224,7 @@ func checkInputs(ctx context.Context, env *environment.Environment) error { func init() { upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check") upCmd.Flags().String("output", "", "Write computed output. Prints on stdout if set to-") - upCmd.Flags().StringArrayVarP(&withParams, "with", "w", []string{}, "") + upCmd.Flags().StringArrayP("with", "w", []string{}, "") if err := viper.BindPFlags(upCmd.Flags()); err != nil { panic(err) diff --git a/plan/plan.go b/plan/plan.go index 39398ffd..8f942d31 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -19,40 +19,46 @@ import ( ) type Plan struct { + config Config + context *plancontext.Context source *compiler.Value } -func Load(ctx context.Context, withParams []string, args ...string) (*Plan, error) { - log.Ctx(ctx).Debug().Interface("args", args).Msg("loading plan") +type Config struct { + Args []string + With []string +} + +func Load(ctx context.Context, cfg Config) (*Plan, error) { + log.Ctx(ctx).Debug().Interface("args", cfg.Args).Msg("loading plan") // FIXME: universe vendoring if err := state.VendorUniverse(ctx, ""); err != nil { return nil, err } - v, err := compiler.Build("", nil, args...) + v, err := compiler.Build("", nil, cfg.Args...) if err != nil { return nil, err } - if len(withParams) > 0 { - for i, param := range withParams { - log.Ctx(ctx).Debug().Interface("with", param).Msg("compiling parameter") - paramV, err := compiler.Compile(fmt.Sprintf("with%v", i), param) - if err != nil { - return nil, err - } + for i, param := range cfg.With { + log.Ctx(ctx).Debug().Interface("with", param).Msg("compiling overlay") + paramV, err := compiler.Compile(fmt.Sprintf("with%v", i), param) + if err != nil { + return nil, err + } - log.Ctx(ctx).Debug().Interface("with", param).Msg("filling parameter") - fillErr := v.FillPath(cue.ParsePath(""), paramV) - if fillErr != nil { - return nil, fillErr - } + log.Ctx(ctx).Debug().Interface("with", param).Msg("filling overlay") + fillErr := v.FillPath(cue.ParsePath(""), paramV) + if fillErr != nil { + return nil, fillErr } } p := &Plan{ + config: cfg, context: plancontext.New(), source: v, } From 4e27937ccc0c0faecf0020950e99d1778bf3eb84 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 12:20:01 -0700 Subject: [PATCH 6/7] refactored tests and added more Signed-off-by: Richard Jones --- tests/plan.bats | 9 ++++--- tests/plan/with/actions.cue | 25 +++++++++++++++++++ .../params/main.cue => with/params.cue} | 0 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tests/plan/with/actions.cue rename tests/plan/{inputs/params/main.cue => with/params.cue} (100%) diff --git a/tests/plan.bats b/tests/plan.bats index 52b567a4..f6aaaec0 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -82,15 +82,16 @@ setup() { assert_output --partial 'failed: exec: "rtyet": executable file not found' } -@test "plan/params" { +@test "plan/with" { cd "$TESTDIR" - "$DAGGER" --europa up --with 'inputs: params: foo:"bar"' ./plan/inputs/params/main.cue + "$DAGGER" --europa up --with 'inputs: params: foo:"bar"' ./plan/with/params.cue + "$DAGGER" --europa up --with 'actions: verify: env: FOO: "bar"' ./plan/with/actions.cue - run "$DAGGER" --europa up --with 'inputs: params: foo:1' ./plan/inputs/params/main.cue + run "$DAGGER" --europa up --with 'inputs: params: foo:1' ./plan/with/params.cue assert_failure assert_output --partial "conflicting values string and 1" - run "$DAGGER" --europa up ./plan/inputs/params/main.cue + run "$DAGGER" --europa up ./plan/with/params.cue assert_failure assert_output --partial "actions.verify.env.FOO: non-concrete value string" } diff --git a/tests/plan/with/actions.cue b/tests/plan/with/actions.cue new file mode 100644 index 00000000..1d856fdd --- /dev/null +++ b/tests/plan/with/actions.cue @@ -0,0 +1,25 @@ +package main + +import ( + "alpha.dagger.io/europa/dagger/engine" +) + +engine.#Plan & { + + actions: { + image: engine.#Pull & { + source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" + } + + verify: engine.#Exec & { + input: image.output + env: FOO: string + args: [ + "sh", "-c", + #""" + test -n "$FOO" + """#, + ] + } + } +} diff --git a/tests/plan/inputs/params/main.cue b/tests/plan/with/params.cue similarity index 100% rename from tests/plan/inputs/params/main.cue rename to tests/plan/with/params.cue From 7322359797a1473a7c8a0fc95f4daccc5abd97e7 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 14:40:34 -0700 Subject: [PATCH 7/7] MakePath rather than ParsePath Signed-off-by: Richard Jones --- plan/plan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plan/plan.go b/plan/plan.go index 8f942d31..08346821 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -51,7 +51,7 @@ func Load(ctx context.Context, cfg Config) (*Plan, error) { } log.Ctx(ctx).Debug().Interface("with", param).Msg("filling overlay") - fillErr := v.FillPath(cue.ParsePath(""), paramV) + fillErr := v.FillPath(cue.MakePath(), paramV) if fillErr != nil { return nil, fillErr }