Skip to content

Commit d53e46a

Browse files
committed
feat: push final image to cache repo
This commit enables pushing the final image to the given cache repo.a As part of #185, the goal is to allow for faster startup when the image has already been built.
1 parent 85290fa commit d53e46a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

envbuilder.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,18 @@ func Run(ctx context.Context, options Options) error {
480480
if val, ok := os.LookupEnv("KANIKO_REGISTRY_MIRROR"); ok {
481481
registryMirror = strings.Split(val, ";")
482482
}
483-
image, err := executor.DoBuild(&config.KanikoOptions{
483+
var destinations []string
484+
if options.CacheRepo != "" {
485+
destinations = append(destinations, options.CacheRepo)
486+
}
487+
opts := &config.KanikoOptions{
484488
// Boilerplate!
485489
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
486490
SnapshotMode: "redo",
487491
RunV2: true,
488492
RunStdout: stdoutWriter,
489493
RunStderr: stderrWriter,
490-
Destinations: []string{"local"},
494+
Destinations: destinations,
491495
CacheRunLayers: true,
492496
CacheCopyLayers: true,
493497
CompressedCaching: true,
@@ -518,11 +522,16 @@ func Run(ctx context.Context, options Options) error {
518522
RegistryMirrors: registryMirror,
519523
},
520524
SrcContext: buildParams.BuildContext,
521-
})
525+
}
526+
image, err := executor.DoBuild(opts)
522527
if err != nil {
523528
return nil, err
524529
}
530+
if err := executor.DoPush(image, opts); err != nil {
531+
return nil, err
532+
}
525533
endStage("🏗️ Built image!")
534+
526535
return image, err
527536
}
528537

0 commit comments

Comments
 (0)