Merge pull request #1333 from talentedmrjones/europa-implement-params
Europa implement --with to support inline overlays
This commit is contained in:
commit
5419f4c89b
@ -142,7 +142,11 @@ func checkUniverseVersion(ctx context.Context, projectPath string) bool {
|
|||||||
func europaUp(ctx context.Context, cl *client.Client, args ...string) error {
|
func europaUp(ctx context.Context, cl *client.Client, args ...string) error {
|
||||||
lg := log.Ctx(ctx)
|
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 {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to load plan")
|
lg.Fatal().Err(err).Msg("failed to load plan")
|
||||||
}
|
}
|
||||||
@ -220,6 +224,7 @@ func checkInputs(ctx context.Context, env *environment.Environment) error {
|
|||||||
func init() {
|
func init() {
|
||||||
upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check")
|
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().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 {
|
if err := viper.BindPFlags(upCmd.Flags()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
28
plan/plan.go
28
plan/plan.go
@ -19,24 +19,46 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Plan struct {
|
type Plan struct {
|
||||||
|
config Config
|
||||||
|
|
||||||
context *plancontext.Context
|
context *plancontext.Context
|
||||||
source *compiler.Value
|
source *compiler.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(ctx context.Context, args ...string) (*Plan, error) {
|
type Config struct {
|
||||||
log.Ctx(ctx).Debug().Interface("args", args).Msg("loading plan")
|
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
|
// FIXME: universe vendoring
|
||||||
if err := state.VendorUniverse(ctx, ""); err != nil {
|
if err := state.VendorUniverse(ctx, ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := compiler.Build("", nil, args...)
|
v, err := compiler.Build("", nil, cfg.Args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
p := &Plan{
|
||||||
|
config: cfg,
|
||||||
context: plancontext.New(),
|
context: plancontext.New(),
|
||||||
source: v,
|
source: v,
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,7 @@ package engine
|
|||||||
// Securely receive secrets
|
// Securely receive secrets
|
||||||
secrets: [name=string]: _#inputSecret
|
secrets: [name=string]: _#inputSecret
|
||||||
// Receive runtime parameters
|
// Receive runtime parameters
|
||||||
params: {
|
params: [name=string]: _
|
||||||
@dagger(notimplemented)
|
|
||||||
[name=string]: _
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send outputs to the client
|
// Send outputs to the client
|
||||||
|
@ -82,6 +82,20 @@ setup() {
|
|||||||
assert_output --partial 'failed: exec: "rtyet": executable file not found'
|
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" {
|
@test "plan/outputs" {
|
||||||
cd "$TESTDIR"/plan/outputs
|
cd "$TESTDIR"/plan/outputs
|
||||||
|
|
||||||
|
25
tests/plan/with/actions.cue
Normal file
25
tests/plan/with/actions.cue
Normal file
@ -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"
|
||||||
|
"""#,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
tests/plan/with/params.cue
Normal file
26
tests/plan/with/params.cue
Normal file
@ -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"
|
||||||
|
"""#,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user