-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Is there a way not to include build-args in the cache key? #1008
Comments
Thanks @thomasfulton for your issue.
We can provide a flag to configure it. |
@tejal29 Either way, either excluding all build args or having it be configurable so we can select which arguments to exclude. Both ways would work. Out of curiosity why are the docker layer hashes themselves not used as the cache keys? |
I'm experiencing the same issue; our build uses a build-arg to specify which version of a python wheel to install. Our Dockerfile is as follows:
It would be nice if the build-arg wasn't considered part of the cache key until the |
I've run into exactly the same issue and I'm also getting 100% cache miss. Before I happened on this issue, I had assumed that the hash of a RUN layer was done by hashing the expanded command line and the hashes of prior layers and state (ex. ENV declarations do not create layers but do create "state"). In that case, if the command line used a build argument, the existing cached layer would get used as long as THAT build argument hadn't changed after expansion. |
We are also experiencing this issue, in our case we would like to pass git commit IDs as build arguments to our builds, so the app can use it for logging or traceability - but with the current approach it is always invalidating the whole cache, not just from the moment the argument is used in the docker file like documented on https://docs.docker.com/engine/reference/builder/#impact-on-build-caching |
Actually... It looks like Kaniko uses EVERY variable passed through --build-arg on the command line, even if it is never referenced by an ARG line. |
Thanks folks, as soon as we get some bandwidth, we will fix this. |
Because layer digest produced by kaniko are not idempotent; running the same build twice will always produce different layer digests unless the Also, I'm not sure how you would get the layer digest without building the layer which at that point you aren't caching. Edit - I realize now you might have meant something other than the digest of the layer, perhaps you meant a hash of all paths in the filesystem or something like that. Apologies for the confusion. |
I'd want to understand how docker handles this case before making any major changes and if at all possible avoid adding another flag (kaniko already has a lot of configuration). I'm having a hard time imagining how you could build a deterministic cache key without the build args. How do you know the build args won't affect the output of the layer? |
Hi Cole,
Docker only takes the ARG and ENV directives into account from the line
that appear downwards. A FROM directive resets that - prior ARE are
forgotten after the FROM. This is documented in the Dockerfile
documentation.
Kaniko, on the other hand, doesn't look at the ARG directive at all and all
build args specified on the command line, regardless of if they are used,
are composed into the cache key. I saw this when running - v=debug.
We just want Kaniko to behave like Docker.
Thanks
…On Wed, Feb 12, 2020, 19:41 Cole Wippern ***@***.***> wrote:
I'd want to understand how docker handles this case before making any
major changes and if at all possible avoid adding another flag (kaniko
already has a lot of configuration).
I'm having a hard time imagining how you could build a deterministic cache
key without the build args. How do you know the build args won't affect the
output of the layer?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1008?email_source=notifications&email_token=ABT6LNX3COF5IC2FHUZN7GLRCSJMTA5CNFSM4KMUQZP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELS6DNQ#issuecomment-585490870>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABT6LNVVEDPBNEUMFUK3HEDRCSJMTANCNFSM4KMUQZPQ>
.
|
PS - I worked around this by writing the value to a file, copying that file
just before the RUN that needs it, and having the script which is run use
the file instead of an environment variable. It's not pretty, but I could
not wait for this fix.
…On Wed, Feb 12, 2020 at 8:00 PM Lucas Lacroix ***@***.***> wrote:
Hi Cole,
Docker only takes the ARG and ENV directives into account from the line
that appear downwards. A FROM directive resets that - prior ARE are
forgotten after the FROM. This is documented in the Dockerfile
documentation.
Kaniko, on the other hand, doesn't look at the ARG directive at all and
all build args specified on the command line, regardless of if they are
used, are composed into the cache key. I saw this when running - v=debug.
We just want Kaniko to behave like Docker.
Thanks
On Wed, Feb 12, 2020, 19:41 Cole Wippern ***@***.***> wrote:
> I'd want to understand how docker handles this case before making any
> major changes and if at all possible avoid adding another flag (kaniko
> already has a lot of configuration).
>
> I'm having a hard time imagining how you could build a deterministic
> cache key without the build args. How do you know the build args won't
> affect the output of the layer?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#1008?email_source=notifications&email_token=ABT6LNX3COF5IC2FHUZN7GLRCSJMTA5CNFSM4KMUQZP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELS6DNQ#issuecomment-585490870>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABT6LNVVEDPBNEUMFUK3HEDRCSJMTANCNFSM4KMUQZPQ>
> .
>
|
@raijinsetsu thanks for the info; to make sure I understand correctly given the following scenario Dockerfile
The cache key for stage 0 ( The cache key for stage 1 ( Is that essentially correct? |
According to the Docker documentation:
FROM foo:latest key=()
ARG VERSION
RUN apt-get install -y bar-${VERSION} key=(ARG VERSION=v0.14.3)
FROM baz:latest key=(ARG VERSION=v0.14.3)
ARG COMMIT
ARG BUILD_TYPE
RUN git checkout ${COMMIT} key=(ARG COMMIT=xf443d,ARG
BUILD_TYPE=development)
RUN make key=(ARG COMMIT=xf443d,ARG
BUILD_TYPE=development)
The "key" value I show on the right is that additional data to be included
in the key with the commands.
Reference:
https://docs.docker.com/engine/reference/builder/#scope
Hope that helps.
On Thu, Feb 13, 2020 at 12:43 PM Cole Wippern <[email protected]>
wrote:
… Hi Cole, Docker only takes the ARG and ENV directives into account from
the line that appear downwards. A FROM directive resets that - prior ARE
are forgotten after the FROM. This is documented in the Dockerfile
documentation. Kaniko, on the other hand, doesn't look at the ARG directive
at all and all build args specified on the command line, regardless of if
they are used, are composed into the cache key. I saw this when running -
v=debug. We just want Kaniko to behave like Docker. Thanks
… <#m_4694278128194927049_>
On Wed, Feb 12, 2020, 19:41 Cole Wippern *@*.***> wrote: I'd want to
understand how docker handles this case before making any major changes and
if at all possible avoid adding another flag (kaniko already has a lot of
configuration). I'm having a hard time imagining how you could build a
deterministic cache key without the build args. How do you know the build
args won't affect the output of the layer? — You are receiving this because
you are subscribed to this thread. Reply to this email directly, view it on
GitHub <#1008 <#1008>?email_source=notifications&email_token=ABT6LNX3COF5IC2FHUZN7GLRCSJMTA5CNFSM4KMUQZP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELS6DNQ#issuecomment-585490870>,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABT6LNVVEDPBNEUMFUK3HEDRCSJMTANCNFSM4KMUQZPQ
.
@raijinsetsu <https://github.com/raijinsetsu> thanks for the info; to
make sure I understand correctly given the following scenario
Dockerfile
FROM foo:latest
ARG VERSION
RUN apt-get install -y bar-${VERSION}
FROM baz:latest
ARG COMMIT
RUN git checkout ${COMMIT}
docker build --build-arg COMMIT=xf443d VERSION=v0.14.3 ./
The cacher key for stage 0 (FROM foo:latest) would contain the ARG VERSION,
but not COMMIT
The cache key for stage 1 (FROM baz:latest) would contain the ARG COMMIT,
but not VERSION
Is that essentially correct?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1008?email_source=notifications&email_token=ABT6LNSTTWHRPAPMBAPRIBDRCWBCRA5CNFSM4KMUQZP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELV5XQI#issuecomment-585882561>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABT6LNQ2XBDK4R2XEZKEISTRCWBCRANCNFSM4KMUQZPQ>
.
|
Agreed. #1085 addresses this issue. |
Hey folks i pushed following images with a fix if anyone is interested in trying out
|
|
@tejal29 the fix in #1085 is not according to the dockerfile standard https://docs.docker.com/engine/reference/builder/#impact-on-build-caching
In this fix, only explicit ARG usage are treated as cache miss where in the docker standard all RUN statement should in fact trigger cache miss. A simple way to reproduce the bug is like this
with the kaniko cache |
We are trying to use the kaniko executor in cloud build. We pass in a build timestamp and build commit sha into our dockerfile as build-args. Since these change with every build, the cache keys change every build even though the contents of the layers are the same. This causes a 100% cache miss rate. Is there any way around this? We would like to be able to pass in build args that change every build but still use kaniko cache.
The text was updated successfully, but these errors were encountered: