diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 721f8af1..925bf248 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -142,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, 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") } @@ -220,6 +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().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 659b79d6..08346821 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -19,24 +19,46 @@ import ( ) type Plan struct { + config Config + context *plancontext.Context source *compiler.Value } -func Load(ctx context.Context, 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 } + 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 overlay") + fillErr := v.FillPath(cue.MakePath(), paramV) + if fillErr != nil { + return nil, fillErr + } + } + p := &Plan{ + config: cfg, 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 diff --git a/tests/plan.bats b/tests/plan.bats index 51ee02c7..f6aaaec0 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -82,6 +82,20 @@ setup() { assert_output --partial 'failed: exec: "rtyet": executable file not found' } +@test "plan/with" { + cd "$TESTDIR" + "$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/with/params.cue + assert_failure + assert_output --partial "conflicting values string and 1" + + run "$DAGGER" --europa up ./plan/with/params.cue + assert_failure + assert_output --partial "actions.verify.env.FOO: non-concrete value string" +} + @test "plan/outputs" { cd "$TESTDIR"/plan/outputs 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/with/params.cue b/tests/plan/with/params.cue new file mode 100644 index 00000000..402ac379 --- /dev/null +++ b/tests/plan/with/params.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" + """#, + ] + } + } +}