This commit is contained in:
Owen Griffiths 2025-06-12 20:44:20 -05:00 committed by GitHub
commit f19fbe07fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 0 deletions

View File

@ -244,6 +244,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")

View File

@ -77,6 +77,7 @@ type KanikoOptions struct {
CompressionLevel int
ImageFSExtractRetry int
SingleSnapshot bool
SkipSnapshot bool
Reproducible bool
NoPush bool
NoPushCache bool

View File

@ -457,6 +457,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