-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Could the default mount cache id include target architecture? #2598
Comments
I think the behavior depends on the use case. In a lot of cases same cache is desired for all platforms, eg. when downloading package source code that does not contain binaries it is usually identical. Also for general build cache other languages as Regarding I would do:
That actually caches the packages that have been installed before and doesn't seem to have any requirements for |
As I say, this really about the safety of the defaults. I realise there's two use cases:
My reason for raising this request is that on balance I prefer default safety over default performance. Alternatively a note about this in the documentation wouldn't go amiss. It took me an unfortunate amount of time to figure out what was going wrong. Ultimately it's your call so I won't labor the point.
The example I give is an SSCCE of what can go wrong. It's not a suggested way to cache PIP packages. It caches the package index and saves some performance loss from |
A failed build isn't necessarily a worst-case in the dev phase but a hint for user that they forgot to set
PR welcome.
Iiuc it caches only the index, meaning if you change the command it will still download all packages again but they will always be the old versions. And I guess if the index gets old it will just fail to download packages because they don't exist anymore? A more useful pattern is to cache the packages (it's bit confusing that I use |
Just as a side-note to this, I had a similar problem and tried to resolve it with |
Problem
There's a "gotya" when working with cache mounts and building with multiple architectures. The stated use case for these is:
However both compilers and package managers are often architecture dependant. The default
id
for the cache is justtarget
so the cache is, by default, shared between architectures. This can be damaging.At best, the cache gets flushed and is useless every build with a different architecture.
At worst, the code using the cache can't detect the incorrect architecture and gets confused by the content.
At worst worst, the code using the cache can't detect the incorrect architecture and builds a corrupt image as a result.
It's fine to expect programs using the cache to detect the cache is stale. But it's extremely uncommon for such programs to detect the wrong architecture's cache has been swapped in.
Example Error
If I have a dockerfile:
And then I build twice (with qemu installed):
I'll end up with errors caused by the cache:
Workaround
As a workaround you can include
${TARGETARCH}
in theid
. For example:Since
TARGETARCH
is set by default The workaround only needs a change to the dockerfile and the build commands will then work.Desired enhancement
Ideally this "workaround" should be the default behaviour: include the value from
TARGETARCH
in the defaultid
. If developers want to share a cache between multiple architectures, the current behaviour would still be available by setting anid
manually. But it means that by default the cache would "just work".The worst case of not knowing about this behaviour would be slower builds and increased network usage on multi-arch builds for platform independent caches (java, javascript...).
The text was updated successfully, but these errors were encountered: