Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Conversation

@mzihlmann
Copy link

@mzihlmann mzihlmann commented Jun 1, 2025

Fixes #3444 #3325 #2835 #2764 #1572 and maybe more...

Description

When building a multi-stage image kaniko deletes the entire filesystem between stages. This is necessary as we need to rollback to an empty state before we start building other stages, but it can result in unexpected behaviour when the user relies on files being there implicitly. Examples can be secrets that are passed into the build by just existing, or after_script snippets in gitlab-ci.

With this change kaniko learned a new cli parameter --preserve-context. If set, kaniko will take a snapshot of the full filesystem before it starts building to later restore to that state. If combined with the --cleanup flag it will also restore the state after cleanup.

It will only take the snapshot if we are building a multistage image or if we plan to cleanup the filesystem after the build.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Examples of user facing changes:
- kaniko adds a new flag `--registry-repo` to override registry

@mzihlmann
Copy link
Author

If you're still looking for a solution to this you could give my fork a try https://github.com/mzihlmann/kaniko/releases/
It fixes this issue and a few more, mostly related to caching, if you have other issues you would like to see resolved please let me know. I know that this is not ideal and I hope we can get the changes merged here eventually but for now that's the best I can offer.
If you like what you see you can support me with a star, thank you 🙇

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kaniko Multi Stage Build Issue

1 participant