From c2dbf832ebfa9a2e961ea4aa730318945bd8f946 Mon Sep 17 00:00:00 2001 From: "Griffiths, Owen" Date: Fri, 8 Dec 2023 13:11:30 +0000 Subject: [PATCH] feat: add --skip-snapshot arg which skips all build snapshots --- cmd/executor/cmd/root.go | 1 + pkg/config/options.go | 1 + pkg/executor/build.go | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 23233ed06..6d10e766d 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -216,6 +216,7 @@ func addKanikoOptionsFlags() { RootCmd.PersistentFlags().StringVarP(&opts.KanikoDir, "kaniko-dir", "", constants.DefaultKanikoPath, "Path to the kaniko directory, this takes precedence over the KANIKO_DIR environment variable.") RootCmd.PersistentFlags().StringVarP(&opts.TarPath, "tar-path", "", "", "Path to save the image in as a tarball instead of pushing") RootCmd.PersistentFlags().BoolVarP(&opts.SingleSnapshot, "single-snapshot", "", false, "Take a single snapshot at the end of the build.") + RootCmd.PersistentFlags().BoolVarP(&opts.SkipSnapshot, "skip-snapshot", "", false, "Skip all snapshots for the duration of the build.") RootCmd.PersistentFlags().BoolVarP(&opts.Reproducible, "reproducible", "", false, "Strip timestamps out of the image to make it reproducible") RootCmd.PersistentFlags().StringVarP(&opts.Target, "target", "", "", "Set the target build stage to build") RootCmd.PersistentFlags().BoolVarP(&opts.NoPush, "no-push", "", false, "Do not push the image to the registry") diff --git a/pkg/config/options.go b/pkg/config/options.go index df419ff64..a3d79c65b 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -75,6 +75,7 @@ type KanikoOptions struct { CompressionLevel int ImageFSExtractRetry int SingleSnapshot bool + SkipSnapshot bool Reproducible bool NoPush bool NoPushCache bool diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 754a1ad13..2325976dd 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -461,6 +461,11 @@ func (s *stageBuilder) takeSnapshot(files []string, shdDelete bool) (string, err func (s *stageBuilder) shouldTakeSnapshot(index int, isMetadatCmd bool) bool { isLastCommand := index == len(s.cmds)-1 + // Skip snapshot entirely with skip snapshot mode on. + if s.opts.SkipSnapshot { + return false + } + // We only snapshot the very end with single snapshot mode on. if s.opts.SingleSnapshot { return isLastCommand