Actual behavior
If I specify both --single-snapshot and --tarPath, resulting tar file contains all layers instead of one
Expected behavior
If both --single-snapshot and --tarPath are provided, resulting tar file should contain one layer
Thank you @vvbogdanov87 for your PR.
Looks like for multistage docker files we create layers for every stage.
In order to fix this, you will have to change this stageBuilder code here to return true iff its the last command of the last stage.
In order to determine if the current stage is last stage, you can add a new struct field
isFinalStage bool here
The newStageBuilder is called here for every stage. Please set the bool value isFinalStage to true for the last stage.
Please feel free to submit a PR and I can help you land this!
I cannot reproduce this. --singleSnapshot will generate a single layer for the stage that is snapshotted. However, any layers in the existing image are preserved, so if the base image has multiple layers, so will the resultant image.
It would probably be reasonable to add an option to squash the final image, though.
Hi,
Indeed, it would be convenient to squash ALL layers (including base one) like podman and buildah provide via podman build --squash-all or buildah bud --squash.
Also, I think the kaniko documentation is a bit misleading on that point :
This flag takes a single snapshot of the filesystem at the end of the build,
so only one layer will be appended to the base image.
Thanks !
Most helpful comment
It would probably be reasonable to add an option to squash the final image, though.