support buildkit cache export/import
- Add support for buildkit cache export/import - Enable GHA cache for universe test (using buildkit v0.9 GHA support) Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/buildx/util/buildflags"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/client"
|
||||
@@ -145,10 +146,23 @@ func ValueDocOneLine(val *compiler.Value) string {
|
||||
}
|
||||
|
||||
// NewClient creates a new client
|
||||
func NewClient(ctx context.Context, noCache bool) *client.Client {
|
||||
func NewClient(ctx context.Context) *client.Client {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
cl, err := client.New(ctx, "", noCache)
|
||||
cacheExports, err := buildflags.ParseCacheEntry(viper.GetStringSlice("cache-to"))
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to parse --export-cache options")
|
||||
}
|
||||
cacheImports, err := buildflags.ParseCacheEntry(viper.GetStringSlice("cache-fron"))
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to parse --import-cache options")
|
||||
}
|
||||
|
||||
cl, err := client.New(ctx, "", client.Config{
|
||||
CacheExports: cacheExports,
|
||||
CacheImports: cacheImports,
|
||||
NoCache: viper.GetBool("no-cache"),
|
||||
})
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to create client")
|
||||
}
|
||||
|
@@ -168,7 +168,7 @@ var computeCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
cl := common.NewClient(ctx, viper.GetBool("no-cache"))
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
// check that all inputs are set
|
||||
@@ -208,7 +208,6 @@ func init() {
|
||||
computeCmd.Flags().StringSlice("input-git", []string{}, "TARGET=REMOTE#REF")
|
||||
computeCmd.Flags().String("input-json", "", "JSON")
|
||||
computeCmd.Flags().String("input-yaml", "", "YAML")
|
||||
computeCmd.Flags().Bool("no-cache", false, "disable cache")
|
||||
|
||||
if err := viper.BindPFlags(computeCmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
|
@@ -76,7 +76,7 @@ var editCmd = &cobra.Command{
|
||||
st.Plan = newState.Plan
|
||||
st.Inputs = newState.Inputs
|
||||
|
||||
cl := common.NewClient(ctx, false)
|
||||
cl := common.NewClient(ctx)
|
||||
err = cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
// check for cue errors by scanning all the inputs
|
||||
_, err := env.ScanInputs(ctx, true)
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"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"
|
||||
@@ -42,12 +41,8 @@ var listCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st)
|
||||
|
||||
c, err := client.New(ctx, "", false)
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Msg("unable to create client")
|
||||
}
|
||||
|
||||
err = c.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
c := common.NewClient(ctx)
|
||||
err := c.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
inputs, err := env.ScanInputs(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -50,7 +50,7 @@ func updateEnvironmentInput(ctx context.Context, cmd *cobra.Command, target stri
|
||||
Value: target,
|
||||
})
|
||||
|
||||
cl := common.NewClient(ctx, false)
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
st.SetInput(target, input)
|
||||
|
||||
|
@@ -40,7 +40,7 @@ var listCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st)
|
||||
|
||||
cl := common.NewClient(ctx, false)
|
||||
cl := common.NewClient(ctx)
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
return ListOutputs(ctx, env, true)
|
||||
})
|
||||
|
@@ -45,7 +45,7 @@ var queryCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, state)
|
||||
|
||||
cl := common.NewClient(ctx, false)
|
||||
cl := common.NewClient(ctx)
|
||||
cueVal := compiler.NewValue()
|
||||
|
||||
err := cl.Do(ctx, state, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
|
@@ -25,6 +25,13 @@ var rootCmd = &cobra.Command{
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().String("log-format", "", "Log format (json, pretty). Defaults to json if the terminal is not a tty")
|
||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "Log level")
|
||||
|
||||
rootCmd.PersistentFlags().Bool("no-cache", false, "Disable caching")
|
||||
rootCmd.PersistentFlags().StringArray("cache-to", []string{},
|
||||
"Cache export destinations (eg. user/app:cache, type=local,dest=path/to/dir)")
|
||||
rootCmd.PersistentFlags().StringArray("cache-from", []string{},
|
||||
"External cache sources (eg. user/app:cache, type=local,src=path/to/dir)")
|
||||
|
||||
rootCmd.PersistentFlags().StringP("environment", "e", "", "Select an environment")
|
||||
rootCmd.PersistentFlags().StringP("workspace", "w", "", "Specify a workspace (defaults to current git repository)")
|
||||
|
||||
|
@@ -43,7 +43,7 @@ var upCmd = &cobra.Command{
|
||||
|
||||
doneCh := common.TrackWorkspaceCommand(ctx, cmd, workspace, st)
|
||||
|
||||
cl := common.NewClient(ctx, viper.GetBool("no-cache"))
|
||||
cl := common.NewClient(ctx)
|
||||
|
||||
err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
// check that all inputs are set
|
||||
@@ -104,7 +104,6 @@ func checkInputs(ctx context.Context, env *environment.Environment) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
upCmd.Flags().Bool("no-cache", false, "Disable all run cache")
|
||||
upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check")
|
||||
|
||||
if err := viper.BindPFlags(upCmd.Flags()); err != nil {
|
||||
|
Reference in New Issue
Block a user