Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache-copy-layers disabled but not during multi-stage images ? #2003

Closed
thomas-tacquet opened this issue Mar 21, 2022 · 2 comments · Fixed by #2032
Closed

cache-copy-layers disabled but not during multi-stage images ? #2003

thomas-tacquet opened this issue Mar 21, 2022 · 2 comments · Fixed by #2032

Comments

@thomas-tacquet
Copy link

Actual behavior
When building my images and multi stages images with --cache-copy-layer at false (or not definied) I was surprised to find that in multi stages images only, kaniko pushes cache layers to target registry.

I always get the following log entry in my multi stages images : INFO[0033] Pushing layer REDACTED/REDACTED/REDACTED/cache:REDACTED to cache now

I think that command arguments are not correctly propagated through build workflow on multi-stage docker images ?

The function pushing cache layers : https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/executor/push.go#L291 if you check call stack it should be called only when CopyCacheLayers is enabled.

Expected behavior
I expect that --copy-cache-layers=false work with single stage images and multi stages images, but it only works partialy in mutli-stage images

To Reproduce
Steps to reproduce the behavior:

  1. Write a multi stage image, for example something found here : https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
  2. ensure you have cache enabled but copy-cache-layers set at false
  3. build the image with kaniko and check that kaniko push sub image cache layers but no first layer
  4. try with a single stage image and ensure it does not any push layer

Additional Information

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
Please check if the build works in docker but not in kaniko
Please check if this error is seen when you use --cache flag
Please check if your dockerfile is a multistage dockerfile
@thomas-tacquet
Copy link
Author

thomas-tacquet commented Apr 1, 2022

Thanks to @RamyChaabane for helping me to figure out the problem.

I was testing the flag --use-new-runby asserting it would not interfer with other flag, but it does ( https://github.com/GoogleContainerTools/kaniko#--use-new-run ) :

  1. By reading the readme (https://github.com/GoogleContainerTools/kaniko/blob/main/README.md#caching-layers) : kaniko can cache layers created by RUN and COPY (configured by flag --cache-copy-layers) made me think that the flag enable/disabl for COPY and RUN commands but it does not
  2. It just changes for COPY commands : commands.go
  3. For run run and new-run it's at true by default

We will raise a PR to add a flag --cache-run-layers to enable or disable copying run layers.

I was wondering if it makes sens to have two flags : --cache-copy-layers &--cache-run-layers Instead of having just one --cache-layers flag ?

@imjasonh
Copy link
Collaborator

imjasonh commented Apr 1, 2022

I'd probably bias toward fewer flags in general, unless there's some strong reason you'd expect folks to only want to cache one type and not the other.

Thanks for looking into this, and thanks for sending a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants