Merge pull request #1185 from talentedmrjones/europa-loader-to-spec
dagger up passes args to cue loader
This commit is contained in:
commit
2cc61d94b7
@ -25,7 +25,7 @@ import (
|
|||||||
var upCmd = &cobra.Command{
|
var upCmd = &cobra.Command{
|
||||||
Use: "up",
|
Use: "up",
|
||||||
Short: "Bring an environment online with latest plan and inputs",
|
Short: "Bring an environment online with latest plan and inputs",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.MaximumNArgs(1),
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
// Fix Viper bug for duplicate flags:
|
// Fix Viper bug for duplicate flags:
|
||||||
// https://github.com/spf13/viper/issues/233
|
// https://github.com/spf13/viper/issues/233
|
||||||
@ -52,6 +52,20 @@ var upCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := lg.WithContext(cmd.Context())
|
ctx := lg.WithContext(cmd.Context())
|
||||||
|
cl := common.NewClient(ctx)
|
||||||
|
|
||||||
|
if viper.GetBool("europa") {
|
||||||
|
err = europaUp(ctx, cl, args...)
|
||||||
|
|
||||||
|
// TODO: rework telemetry
|
||||||
|
// <-doneCh
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
lg.Fatal().Err(err).Msg("failed to up environment")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
project := common.CurrentProject(ctx)
|
project := common.CurrentProject(ctx)
|
||||||
st := common.CurrentEnvironmentState(ctx, project)
|
st := common.CurrentEnvironmentState(ctx, project)
|
||||||
@ -62,20 +76,6 @@ var upCmd = &cobra.Command{
|
|||||||
|
|
||||||
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
|
||||||
|
|
||||||
cl := common.NewClient(ctx)
|
|
||||||
|
|
||||||
if viper.GetBool("europa") {
|
|
||||||
err = europaUp(ctx, cl, project.Path)
|
|
||||||
|
|
||||||
<-doneCh
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
lg.Fatal().Err(err).Msg("failed to up environment")
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
env, err := environment.New(st)
|
env, err := environment.New(st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("unable to create environment")
|
lg.Fatal().Err(err).Msg("unable to create environment")
|
||||||
@ -112,10 +112,10 @@ var upCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func europaUp(ctx context.Context, cl *client.Client, path 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, path, "")
|
p, err := plan.Load(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.Fatal().Err(err).Msg("failed to load plan")
|
lg.Fatal().Err(err).Msg("failed to load plan")
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,14 @@ type Plan struct {
|
|||||||
source *compiler.Value
|
source *compiler.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(ctx context.Context, path, pkg string) (*Plan, error) {
|
func Load(ctx context.Context, args ...string) (*Plan, error) {
|
||||||
// FIXME: universe vendoring
|
// FIXME: universe vendoring
|
||||||
if err := state.VendorUniverse(ctx, path); err != nil {
|
|
||||||
|
if err := state.VendorUniverse(ctx, ""); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := compiler.Build(path, nil, pkg)
|
v, err := compiler.Build("", nil, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -391,6 +391,10 @@ func cueModInit(ctx context.Context, parentDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func VendorUniverse(ctx context.Context, p string) error {
|
func VendorUniverse(ctx context.Context, p string) error {
|
||||||
|
if p == "" {
|
||||||
|
p = getCueModParent()
|
||||||
|
}
|
||||||
|
|
||||||
// ensure cue module is initialized
|
// ensure cue module is initialized
|
||||||
if err := cueModInit(ctx, p); err != nil {
|
if err := cueModInit(ctx, p); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -414,3 +418,25 @@ func VendorUniverse(ctx context.Context, p string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCueModParent() string {
|
||||||
|
cwd, _ := os.Getwd()
|
||||||
|
parentDir := cwd
|
||||||
|
|
||||||
|
// traverse the directory tree up through ancestors looking for a cue.mod folder
|
||||||
|
for {
|
||||||
|
if _, err := os.Stat(path.Join(parentDir, "cue.mod")); !errors.Is(err, os.ErrNotExist) {
|
||||||
|
break // found it!
|
||||||
|
}
|
||||||
|
|
||||||
|
parentDir = filepath.Dir(parentDir)
|
||||||
|
|
||||||
|
if parentDir == string(os.PathSeparator) {
|
||||||
|
// reached the root
|
||||||
|
parentDir = cwd // reset to working directory
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentDir
|
||||||
|
}
|
||||||
|
10
tests/plan.bats
Normal file
10
tests/plan.bats
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
setup() {
|
||||||
|
load 'helpers'
|
||||||
|
|
||||||
|
common_setup
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "plan: hello" {
|
||||||
|
run dagger --europa up ./plan/hello-europa
|
||||||
|
assert_success
|
||||||
|
}
|
16
tests/plan/hello-europa/main.cue
Normal file
16
tests/plan/hello-europa/main.cue
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"alpha.dagger.io/dagger/engine"
|
||||||
|
"alpha.dagger.io/os"
|
||||||
|
)
|
||||||
|
|
||||||
|
engine.#Plan & {
|
||||||
|
actions: {
|
||||||
|
sayHello: os.#Container & {
|
||||||
|
command: "echo Hello Europa! > /out.txt"
|
||||||
|
}
|
||||||
|
|
||||||
|
verify: "Hello Europa!\n" & (os.#File & {from: sayHello, path: "/out.txt"}).contents
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user