Fix caching for empty RUNs
Description
Currently the output of kaniko differs whether we have build from scratch or from cache. When we build from scratch we omit empty layers created by pointless RUN statements. When we then rebuild from cache we do emit layers for them. This can cause further cache misses if the empty RUN statement is in a base image of a multistage build.
FROM ubuntu
RUN echo hello
first run (from scratch):
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:8901a649dd5a9284fa6206a08f3ba3b5a12fddbfd2f82c880e68cdb699d98bfb"
]
},
second run (from cache):
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:8901a649dd5a9284fa6206a08f3ba3b5a12fddbfd2f82c880e68cdb699d98bfb",
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
]
},
Interestingly we here mimic the behaviour of legacy docker and this is enforced by integration-tests. buildkit does no longer optimize out empty RUN statements.
With this change we now make behaviour consistent whether we build from scratch or from cache.
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
- kaniko learned to rebuild empty RUN layers from cache correctly