Remove environment

Signed-off-by: Joel Longtine <joel@dagger.io>
This commit is contained in:
Joel Longtine
2022-02-18 16:00:38 -07:00
parent c971077222
commit 034cd74ed0
10 changed files with 38 additions and 1735 deletions

View File

@@ -20,7 +20,6 @@ import (
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/environment"
"go.dagger.io/dagger/pkg"
"golang.org/x/term"
)
@@ -55,23 +54,6 @@ type Package struct {
func Parse(ctx context.Context, packageName string, val *compiler.Value) *Package {
lg := log.Ctx(ctx)
parseValues := func(field string, values []*compiler.Value) []Value {
val := []Value{}
for _, i := range values {
v := Value{}
v.Name = strings.TrimPrefix(
i.Path().String(),
field+".",
)
v.Type = common.FormatValue(i)
v.Description = common.ValueDocOneLine(i)
val = append(val, v)
}
return val
}
fields, err := val.Fields(cue.Definitions(true))
if err != nil {
lg.Fatal().Err(err).Msg("cannot get fields")
@@ -104,14 +86,6 @@ func Parse(ctx context.Context, packageName string, val *compiler.Value) *Packag
field.Name = name
field.Description = common.ValueDocOneLine(v)
// Inputs
inp := environment.ScanInputs(ctx, v)
field.Inputs = parseValues(field.Name, inp)
// Outputs
out := environment.ScanOutputs(ctx, v)
field.Outputs = parseValues(field.Name, out)
pkg.Fields = append(pkg.Fields, field)
}

View File

@@ -2,19 +2,14 @@ package cmd
import (
"context"
"errors"
"fmt"
"os"
"cuelang.org/go/cue"
"go.dagger.io/dagger/client"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/environment"
"go.dagger.io/dagger/mod"
"go.dagger.io/dagger/plan"
"go.dagger.io/dagger/plancontext"
"go.dagger.io/dagger/solver"
"golang.org/x/term"
@@ -68,58 +63,6 @@ var upCmd = &cobra.Command{
return
}
project := common.CurrentProject(ctx)
st := common.CurrentEnvironmentState(ctx, project)
lg = lg.With().
Str("environment", st.Name).
Logger()
universeUpdateCh := make(chan bool)
go func() {
universeUpdateCh <- checkUniverseVersion(ctx, project.Path)
}()
doneCh := common.TrackProjectCommand(ctx, cmd, project, st)
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 {
// check that all inputs are set
if err := checkInputs(ctx, env); err != nil {
return err
}
if err := env.Up(ctx, s); err != nil {
return err
}
st.Computed = env.Computed().JSON().PrettyString()
if err := project.Save(ctx, st); err != nil {
return err
}
// FIXME: `ListOutput` is printing to Stdout directly which messes
// up the TTY logger.
if tty != nil {
tty.Stop()
}
return nil
})
<-doneCh
if err != nil {
lg.Fatal().Err(err).Msg("failed to up environment")
}
// Warn universe version if out of date
if update := <-universeUpdateCh; update {
fmt.Println("A new version of universe is available, please run 'dagger mod get alpha.dagger.io'")
}
},
}
@@ -173,57 +116,8 @@ func europaUp(ctx context.Context, cl *client.Client, args ...string) error {
})
}
func checkInputs(ctx context.Context, env *environment.Environment) error {
lg := log.Ctx(ctx)
warnOnly := viper.GetBool("force")
notConcreteInputs := []*compiler.Value{}
inputs, err := env.ScanInputs(ctx, true)
if err != nil {
lg.Error().Err(err).Msg("failed to scan inputs")
return err
}
for _, i := range inputs {
isConcrete := (i.IsConcreteR(cue.Optional(true)) == nil)
switch {
case plancontext.IsSecretValue(i):
if _, err := env.Context().Secrets.FromValue(i); err != nil {
isConcrete = false
}
case plancontext.IsFSValue(i):
if _, err := env.Context().FS.FromValue(i); err != nil {
isConcrete = false
}
case plancontext.IsServiceValue(i):
if _, err := env.Context().Services.FromValue(i); err != nil {
isConcrete = false
}
}
if !isConcrete {
notConcreteInputs = append(notConcreteInputs, i)
}
}
for _, i := range notConcreteInputs {
if warnOnly {
lg.Warn().Str("input", i.Path().String()).Msg("required input is missing")
} else {
lg.Error().Str("input", i.Path().String()).Msg("required input is missing")
}
}
if !warnOnly && len(notConcreteInputs) > 0 {
return errors.New("some required inputs are not set, please re-run with `--force` if you think it's a mistake")
}
return nil
}
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{}, "")
upCmd.Flags().StringP("target", "t", "", "Run a single target of the DAG (for debugging only)")
upCmd.Flags().Bool("no-vendor", false, "Force up, disable inputs check")

View File

@@ -14,14 +14,14 @@ import (
"github.com/containerd/console"
"github.com/morikuni/aec"
"github.com/tonistiigi/vt100"
"go.dagger.io/dagger/environment"
"go.dagger.io/dagger/plan/task"
)
type Event map[string]interface{}
type Group struct {
Name string
State environment.State
State task.State
Events []Event
Started *time.Time
Completed *time.Time
@@ -43,7 +43,7 @@ func (l *Logs) Add(event Event) error {
l.l.Lock()
defer l.l.Unlock()
task, ok := event["task"].(string)
taskPath, ok := event["task"].(string)
if !ok {
l.Messages = append(l.Messages, Message{
Event: event,
@@ -52,12 +52,8 @@ func (l *Logs) Add(event Event) error {
return nil
}
// Hide `#up.*` from log group names
// FIXME: remove in Europa
groupKey := strings.Split(task, ".#up")[0]
// Hide hidden fields (e.g. `._*`) from log group names
groupKey = strings.Split(groupKey, "._")[0]
groupKey := strings.Split(taskPath, "._")[0]
group := l.groups[groupKey]
@@ -82,8 +78,8 @@ func (l *Logs) Add(event Event) error {
// For each task in a group, the status will transition from computing to complete, then back to computing and so on.
// The transition is fast enough not to cause a problem.
if st, ok := event["state"].(string); ok {
group.State = environment.State(st)
if group.State == environment.StateComputing {
group.State = task.State(st)
if group.State == task.StateComputing {
group.Completed = nil
} else {
now := time.Now()
@@ -228,7 +224,7 @@ func (c *TTYOutput) linesPerGroup(width, height int) int {
runningGroups := 0
for _, message := range c.logs.Messages {
if group := message.Group; group != nil && group.State == environment.StateComputing {
if group := message.Group; group != nil && group.State == task.StateComputing {
runningGroups++
}
}
@@ -268,13 +264,13 @@ func (c *TTYOutput) printGroup(group *Group, width, maxLines int) int {
prefix := ""
switch group.State {
case environment.StateComputing:
case task.StateComputing:
prefix = "[+]"
case environment.StateCanceled:
case task.StateCanceled:
prefix = "[✗]"
case environment.StateFailed:
case task.StateFailed:
prefix = "[✗]"
case environment.StateCompleted:
case task.StateCompleted:
prefix = "[✔]"
}
@@ -298,13 +294,13 @@ func (c *TTYOutput) printGroup(group *Group, width, maxLines int) int {
// color
switch group.State {
case environment.StateComputing:
case task.StateComputing:
out = aec.Apply(out, aec.LightBlueF)
case environment.StateCanceled:
case task.StateCanceled:
out = aec.Apply(out, aec.LightYellowF)
case environment.StateFailed:
case task.StateFailed:
out = aec.Apply(out, aec.LightRedF)
case environment.StateCompleted:
case task.StateCompleted:
out = aec.Apply(out, aec.LightGreenF)
}
@@ -314,19 +310,19 @@ func (c *TTYOutput) printGroup(group *Group, width, maxLines int) int {
printEvents := []Event{}
switch group.State {
case environment.StateComputing:
case task.StateComputing:
printEvents = group.Events
// for computing tasks, show only last N
if len(printEvents) > maxLines {
printEvents = printEvents[len(printEvents)-maxLines:]
}
case environment.StateCanceled:
case task.StateCanceled:
// for completed tasks, don't show any logs
printEvents = []Event{}
case environment.StateFailed:
case task.StateFailed:
// for failed, show all logs
printEvents = group.Events
case environment.StateCompleted:
case task.StateCompleted:
// for completed tasks, don't show any logs
printEvents = []Event{}
}