Skip to content

Commit

Permalink
Add a new flag to cleanup the filesystem at the end
Browse files Browse the repository at this point in the history
Currently, kaniko can only build a single image per container run, because the filesystem is full of the content of the first image.
When running kaniko in Jenkins, where we need to start the container "doing nothing" first (using the debug kaniko container), and then exec /kaniko/executor, this is a limitation because it means that if we want to build multiple images, we need to start multiple containers - see https://groups.google.com/forum/#!topic/kaniko-users/_7LivHdMdy0 for more details

A solution to fix this issue is to add a new flag to cleanup the filesystem at the end - the same way it is done between stages when building a multi-stages image. This way, the same (debug) container can be used to build multiple images.
  • Loading branch information
vbehar committed Sep 27, 2018
1 parent 1a13c81 commit da14929
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ If `--destination=gcr.io/kaniko-project/test`, then cached layers will be stored

_This flag must be used in conjunction with the `--cache=true` flag._

#### --cleanup

Set this flag to cleanup the filesystem at the end, leaving a clean kaniko container (if you want to build multiple images in the same container, using the debug kaniko image)

### Debug Image

The kaniko executor image is based off of scratch and doesn't contain a shell.
Expand Down
7 changes: 7 additions & 0 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ var (
opts = &config.KanikoOptions{}
logLevel string
force bool
cleanup bool
)

func init() {
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic")
RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container")
RootCmd.PersistentFlags().BoolVarP(&cleanup, "cleanup", "", false, "Clean the filesystem at the end")
addKanikoOptionsFlags(RootCmd)
addHiddenFlags(RootCmd)
}
Expand Down Expand Up @@ -77,6 +79,11 @@ var RootCmd = &cobra.Command{
if err := executor.DoPush(image, opts); err != nil {
exit(errors.Wrap(err, "error pushing image"))
}
if cleanup {
if err := util.DeleteFilesystem(); err != nil {
exit(errors.Wrap(err, "error cleaning filesystem"))
}
}
},
}

Expand Down

0 comments on commit da14929

Please sign in to comment.