cmd: centralize code for buildkit client creation
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
84acad8706
commit
d4c8350c08
@ -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
|
||||
}
|
||||
|
@ -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]))
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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"),
|
||||
|
@ -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))
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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])),
|
||||
)
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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])),
|
||||
)
|
||||
|
@ -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])),
|
||||
)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user