performance: compile CUE client side
Restructured the compile logic to happen on the CLI instead of the BuildKit frontend. - Avoid uploading the entire workspace to BuildKit on every compilation - Let the CUE loader scan the files instead of going through the BuildKit filesystem gRPC APIs. Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -170,7 +170,25 @@ var computeCmd = &cobra.Command{
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
v := compiler.NewValue()
|
||||
plan, err := st.CompilePlan(ctx)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile plan")
|
||||
}
|
||||
if err := v.FillPath(cue.MakePath(), plan); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile plan")
|
||||
}
|
||||
|
||||
inputs, err := st.CompileInputs()
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile inputs")
|
||||
}
|
||||
|
||||
if err := v.FillPath(cue.MakePath(), inputs); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile inputs")
|
||||
}
|
||||
|
||||
err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
// check that all inputs are set
|
||||
checkInputs(ctx, env)
|
||||
|
||||
@@ -178,13 +196,6 @@ var computeCmd = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
v := compiler.NewValue()
|
||||
if err := v.FillPath(cue.MakePath(), env.Plan()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.FillPath(cue.MakePath(), env.Input()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.FillPath(cue.MakePath(), env.Computed()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -318,7 +318,7 @@ func loadCode(packageName string) (*compiler.Value, error) {
|
||||
stdlib.Path: stdlib.FS,
|
||||
}
|
||||
|
||||
src, err := compiler.Build(sources, packageName)
|
||||
src, err := compiler.Build("/config", sources, packageName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -1,15 +1,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cuelang.org/go/cue"
|
||||
"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/solver"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -45,28 +42,27 @@ var queryCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, state)
|
||||
|
||||
cl := common.NewClient(ctx)
|
||||
cueVal := compiler.NewValue()
|
||||
|
||||
err := cl.Do(ctx, state, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
if !viper.GetBool("no-plan") {
|
||||
if err := cueVal.FillPath(cue.MakePath(), env.Plan()); err != nil {
|
||||
return err
|
||||
}
|
||||
if !viper.GetBool("no-plan") {
|
||||
plan, err := state.CompilePlan(ctx)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile plan")
|
||||
}
|
||||
if err := cueVal.FillPath(cue.MakePath(), plan); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile plan")
|
||||
}
|
||||
}
|
||||
|
||||
if !viper.GetBool("no-input") {
|
||||
inputs, err := state.CompileInputs()
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile inputs")
|
||||
}
|
||||
|
||||
if !viper.GetBool("no-input") {
|
||||
if err := cueVal.FillPath(cue.MakePath(), env.Input()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cueVal.FillPath(cue.MakePath(), inputs); err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to compile inputs")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
<-doneCh
|
||||
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("failed to query environment")
|
||||
}
|
||||
|
||||
if !viper.GetBool("no-computed") && state.Computed != "" {
|
||||
@@ -79,6 +75,8 @@ var queryCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
<-doneCh
|
||||
|
||||
cueVal = cueVal.LookupPath(cuePath)
|
||||
|
||||
if viper.GetBool("concrete") {
|
||||
@@ -98,7 +96,7 @@ var queryCmd = &cobra.Command{
|
||||
case "json":
|
||||
fmt.Println(cueVal.JSON().PrettyString())
|
||||
case "yaml":
|
||||
lg.Fatal().Err(err).Msg("yaml format not yet implemented")
|
||||
lg.Fatal().Msg("yaml format not yet implemented")
|
||||
case "text":
|
||||
out, err := cueVal.String()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user