add cache images logic

This commit is contained in:
David Kovari 2024-01-24 22:48:06 -06:00
commit 3676944088
No known key found for this signature in database
GPG key ID: EA46A9DC0364BD76
3 changed files with 11 additions and 0 deletions

View file

@ -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"},

View file

@ -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)
}

View file

@ -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