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
Caching does not work with ARG inside the Dockerfile #1910
Comments
Comparing the composite keys I see:
vs
I am pretty sure that TEST=123 is wrong, this should always be only set after the ARG command ran. |
…oogleContainerTools#1910 This seems to be required because otherwise build & optimize calculate different caches keys.
For my simple docker file this fix works: diff --git a/pkg/executor/build.go b/pkg/executor/build.go
index 995c6737..45b3cae7 100644
--- a/pkg/executor/build.go
+++ b/pkg/executor/build.go
@@ -242,6 +242,13 @@ func (s *stageBuilder) optimize(compositeKey CompositeCache, cfg v1.Config) erro
return errors.Wrap(err, "failed to get files used from context")
}
+ // Mutate the config for any commands that require it.
+ if command.MetadataOnly() {
+ if err := command.ExecuteCommand(&cfg, s.args); err != nil {
+ return err
+ }
+ }
+
compositeKey, err = s.populateCompositeKey(command, files, compositeKey, s.args, cfg.Env)
if err != nil {
return err
@@ -272,13 +279,6 @@ func (s *stageBuilder) optimize(compositeKey CompositeCache, cfg v1.Config) erro
s.cmds[i] = cacheCmd
}
}
-
- // Mutate the config for any commands that require it.
- if command.MetadataOnly() {
- if err := command.ExecuteCommand(&cfg, s.args); err != nil {
- return err
- }
- }
}
return nil
} Since |
Yeah my fix breaks down as soon as I have the following dockerfile:
with the following difference in the composite key:
vs
|
apollo13 commentedFeb 2, 2022
•
edited
Note to maintainers: Attached a patch in #1915 -- not sure how to test that though, hints welcome.
Actual behavior
I am running kaniko with
--cache-copy-layers=true
and it fails to utilize the cache in certain situations.Expected behavior
I expect kaniko to reuse the cache, it seems as if the cache ids are generated wrongly
To Reproduce
Additional Information
Looking at the debug output the cache key changes:
Triage Notes for the Maintainers
--cache
flagThe text was updated successfully, but these errors were encountered: