diff --git a/cmd/docker-buildx/config.go b/cmd/docker-buildx/config.go index 550ec3c..05705f3 100644 --- a/cmd/docker-buildx/config.go +++ b/cmd/docker-buildx/config.go @@ -207,6 +207,12 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag { Usage: "cache destination for the build cache", Destination: &settings.Build.CacheTo, }, + &cli.StringSliceFlag{ + Name: "cache-images", + EnvVars: []string{"PLUGIN_CACHE_IMAGES"}, + Usage: "list of images to use for build cache. applies both to and from flags for each image", + Destination: &settings.Build.CacheImages, + }, &cli.BoolFlag{ Name: "pull-image", EnvVars: []string{"PLUGIN_PULL_IMAGE"}, diff --git a/plugin/docker.go b/plugin/docker.go index 88c965b..e966b37 100644 --- a/plugin/docker.go +++ b/plugin/docker.go @@ -84,6 +84,10 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd { if build.CacheTo != "" { args = append(args, "--cache-to", build.CacheTo) } + for _, arg := range build.CacheImages.Value() { + args = append(args, "--cache-from", arg) + args = append(args, string("--cache-to=type=registry,ref="+arg+",mode=max,image-manifest=true,oci-mediatypes=true")) + } for _, arg := range build.ArgsEnv.Value() { addProxyValue(&build, arg) } diff --git a/plugin/impl.go b/plugin/impl.go index 053a577..563d03d 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -74,6 +74,7 @@ type Build struct { Pull bool // Docker build pull CacheFrom string // Docker build cache-from CacheTo string // Docker build cache-to + CacheImages cli.StringSlice // Docker build cache images Compress bool // Docker build compress Repo cli.StringSlice // Docker build repository NoCache bool // Docker build no-cache