cmd: centralize code for buildkit client creation

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-07-12 10:46:32 +02:00
parent 84acad8706
commit d4c8350c08
9 changed files with 26 additions and 7 deletions

View File

@ -159,3 +159,15 @@ func ValueDocOneLine(val *compiler.Value) string {
}
return strings.Join(docs, " ")
}
// NewClient creates a new client
func NewClient(ctx context.Context) *client.Client {
lg := log.Ctx(ctx)
cl, err := client.New(ctx, "", false)
if err != nil {
lg.Fatal().Err(err).Msg("unable to create client")
}
return cl
}

View File

@ -3,6 +3,7 @@ package input
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
)
@ -22,7 +23,7 @@ var containerCmd = &cobra.Command{
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
updateEnvironmentInput(ctx, args[0], state.DockerInput(args[1]))
updateEnvironmentInput(ctx, common.NewClient(ctx), args[0], state.DockerInput(args[1]))
},
}

View File

@ -43,7 +43,7 @@ var dirCmd = &cobra.Command{
p = "./" + p
}
updateEnvironmentInput(ctx, args[0],
updateEnvironmentInput(ctx, common.NewClient(ctx), args[0],
state.DirInput(
p,
viper.GetStringSlice("include"),

View File

@ -3,6 +3,7 @@ package input
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
)
@ -32,7 +33,7 @@ var gitCmd = &cobra.Command{
subDir = args[3]
}
updateEnvironmentInput(ctx, args[0], state.GitInput(args[1], ref, subDir))
updateEnvironmentInput(ctx, common.NewClient(ctx), args[0], state.GitInput(args[1], ref, subDir))
},
}

View File

@ -3,6 +3,7 @@ package input
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
)
@ -24,6 +25,7 @@ var jsonCmd = &cobra.Command{
updateEnvironmentInput(
ctx,
common.NewClient(ctx),
args[0],
state.JSONInput(readInput(ctx, args[1])),
)

View File

@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
"golang.org/x/term"
@ -43,6 +44,7 @@ var secretCmd = &cobra.Command{
updateEnvironmentInput(
ctx,
common.NewClient(ctx),
args[0],
state.SecretInput(secret),
)

View File

@ -3,6 +3,7 @@ package input
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
)
@ -24,6 +25,7 @@ var textCmd = &cobra.Command{
updateEnvironmentInput(
ctx,
common.NewClient(ctx),
args[0],
state.TextInput(readInput(ctx, args[1])),
)

View File

@ -3,6 +3,7 @@ package input
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
"go.dagger.io/dagger/cmd/dagger/logger"
"go.dagger.io/dagger/state"
)
@ -24,6 +25,7 @@ var yamlCmd = &cobra.Command{
updateEnvironmentInput(
ctx,
common.NewClient(ctx),
args[0],
state.YAMLInput(readInput(ctx, args[1])),
)

View File

@ -38,10 +38,7 @@ var upCmd = &cobra.Command{
workspace := common.CurrentWorkspace(ctx)
st := common.CurrentEnvironmentState(ctx, workspace)
cl, err := client.New(ctx, "", false)
if err != nil {
lg.Fatal().Err(err).Msg("unable to create client")
}
cl := common.NewClient(ctx)
// check that all inputs are set
checkInputs(ctx, cl, st)