Don't store pip and uv cache files in our docker images#3344
Merged
copybara-service[bot] merged 1 commit intomainfrom Mar 6, 2026
Merged
Don't store pip and uv cache files in our docker images#3344copybara-service[bot] merged 1 commit intomainfrom
copybara-service[bot] merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
🤖 Hi @igorts-git, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This PR correctly implements BuildKit cache mounts (--mount=type=cache) to prevent pip and uv from polluting the final Docker image with cache files. The change successfully addresses the 4 GB image size reduction goal.
🔍 General Feedback
- Cache utilization vs. image bloat: Using Docker cache mounts is the ideal solution for keeping package installation caches out of the final image. However, some
pip installcommands still include the--no-cache-dirflag. Removing this flag allowspipto actually populate and use the mounted cache directory during the build, which will speed up subsequent local rebuilds while continuing to keep the image small. - Uninstall commands: Several
pip uninstallcommands now use the cache mount. Since uninstalling packages does not read or write to the cache, this mount is redundant and can be omitted.
Reduces docker image size by removing pip and uv cache files.
88eb51e to
e56309a
Compare
khatwanimohit
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
uvandpipcreate a copy of everything they fetch under the/root/.cachedir. Those cached files are not used at runtime.This cache adds about 4 GB to the docker image size.
We use the Dockerfile syntax below to avoid creating the
/root/.cache/[pip|uv]dirs inside the final image:Tests
Manually built a couple of variants of the docker images. Confirmed that they get smaller and still run under XPK.
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.