Merge pull request #1162 from aluzzardi/europa-context

europa: new execution engine and #Plan support
This commit is contained in:
Andrea Luzzardi
2021-11-29 16:14:14 -08:00
committed by GitHub
25 changed files with 561 additions and 60 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"cuelang.org/go/cue"
"github.com/docker/buildx/util/buildflags"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
@@ -91,9 +92,9 @@ func FormatValue(val *compiler.Value) string {
return "dagger.#Secret"
}
if val.IsConcreteR() != nil {
return val.IncompleteKindString()
return val.IncompleteKind().String()
}
if val.IncompleteKindString() == "struct" {
if val.IncompleteKind() == cue.StructKind {
return "struct"
}

View File

@@ -198,7 +198,7 @@ var computeCmd = &cobra.Command{
lg.Fatal().Err(err).Msg("unable to create environment")
}
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check that all inputs are set
checkInputs(ctx, env)

View File

@@ -83,7 +83,7 @@ var editCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check for cue errors by scanning all the inputs
_, err := env.ScanInputs(ctx, true)
if err != nil {

View File

@@ -47,7 +47,7 @@ var listCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
inputs, err := env.ScanInputs(ctx, false)
if err != nil {
return err

View File

@@ -59,7 +59,7 @@ func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target stri
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// the inputs are set, check for cue errors by scanning all the inputs
_, err := env.ScanInputs(ctx, true)
if err != nil {

View File

@@ -46,7 +46,7 @@ var listCmd = &cobra.Command{
}
cl := common.NewClient(ctx)
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
return ListOutputs(ctx, env, true)
})

View File

@@ -36,6 +36,8 @@ func init() {
rootCmd.PersistentFlags().StringP("environment", "e", "", "Select an environment")
rootCmd.PersistentFlags().String("project", "", "Specify a project directory (defaults to current)")
rootCmd.PersistentFlags().Bool("europa", false, "Enable experiemental Europa UX")
rootCmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) {
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
@@ -89,8 +91,7 @@ func Execute() {
)
if len(os.Args) > 1 {
tr := otel.Tracer("cmd")
ctx, span = tr.Start(ctx, os.Args[1])
ctx, span = otel.Tracer("dagger").Start(ctx, os.Args[1])
// Record the action
span.AddEvent("command", trace.WithAttributes(
attribute.String("args", strings.Join(os.Args, " ")),

View File

@@ -6,11 +6,13 @@ import (
"os"
"cuelang.org/go/cue"
"go.dagger.io/dagger/client"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/cmd/output"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/environment"
"go.dagger.io/dagger/plan"
"go.dagger.io/dagger/solver"
"golang.org/x/term"
@@ -61,12 +63,24 @@ var upCmd = &cobra.Command{
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)
if err != nil {
lg.Fatal().Err(err).Msg("unable to create environment")
}
err = cl.Do(ctx, env.Context(), func(ctx context.Context, s solver.Solver) error {
err = cl.Do(ctx, env.Context(), env.Context().Directories.Paths(), func(ctx context.Context, s solver.Solver) error {
// check that all inputs are set
if err := checkInputs(ctx, env); err != nil {
return err
@@ -97,6 +111,27 @@ var upCmd = &cobra.Command{
},
}
func europaUp(ctx context.Context, cl *client.Client, path string) error {
lg := log.Ctx(ctx)
p, err := plan.Load(ctx, path, "")
if err != nil {
lg.Fatal().Err(err).Msg("failed to load plan")
}
localdirs, err := p.LocalDirectories()
if err != nil {
return err
}
return cl.Do(ctx, p.Context(), localdirs, func(ctx context.Context, s solver.Solver) error {
if err := p.Up(ctx, s); err != nil {
return err
}
return nil
})
}
func checkInputs(ctx context.Context, env *environment.Environment) error {
lg := log.Ctx(ctx)
warnOnly := viper.GetBool("force")

View File

@@ -118,7 +118,7 @@ func formatMessage(event map[string]interface{}) string {
func parseSource(event map[string]interface{}) string {
source := "system"
if task, ok := event["component"].(string); ok && task != "" {
if task, ok := event["task"].(string); ok && task != "" {
source = task
}
return source
@@ -141,7 +141,7 @@ func formatFields(entry map[string]interface{}) string {
zerolog.ErrorFieldName: {},
zerolog.CallerFieldName: {},
"environment": {},
"component": {},
"task": {},
"state": {},
}

View File

@@ -43,7 +43,7 @@ func (l *Logs) Add(event Event) error {
l.l.Lock()
defer l.l.Unlock()
component, ok := event["component"].(string)
task, ok := event["task"].(string)
if !ok {
l.Messages = append(l.Messages, Message{
Event: event,
@@ -52,7 +52,7 @@ func (l *Logs) Add(event Event) error {
return nil
}
groupKey := strings.Split(component, ".#up")[0]
groupKey := strings.Split(task, ".#up")[0]
group := l.groups[groupKey]
// If the group doesn't exist, create it
@@ -72,8 +72,8 @@ func (l *Logs) Add(event Event) error {
// For state events, we just want to update the group status -- no need to
// dispanything
if st, ok := event["state"].(string); ok {
// Ignore state updates for "sub" components
if component != groupKey {
// Ignore state updates for "sub" tasks
if task != groupKey {
return nil
}