Forward pip's cache controls into scan subprocesses - #302
Merged
Conversation
Dockerfile.worker sets PIP_NO_CACHE_DIR=1 so resolving a Python project leaves no download cache behind. The subprocess env scrubber never forwarded it, so the setting stopped at the worker process and every scan's pip run cached again under HOME. Measured on a 2,080-repository corpus: 3.3 GB in one worker inside a day, which was most of what took a 26 GB root partition to 100%. The cache directory was read as scancode's at first because both live under .cache; scancode's own subdirectory was 0 bytes. Adds PIP_NO_CACHE_DIR and PIP_CACHE_DIR to the cdxgen and prep allowlists. PIP_CACHE_DIR rides along for the opposite deployment: the one that wants the cache and has somewhere with room to put it.
5 tasks
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.
Problem
Dockerfile.workersetsPIP_NO_CACHE_DIR=1so that resolving a Python project leaves no download cache behind. The subprocess env scrubber never forwarded that key, so the image's setting stopped at the worker process and every scan's Python resolution cached again underHOME.Measured on a 2,080-repository corpus: 3.3 GB accumulated in one worker inside a day, which was most of what took a 26 GB root partition to 100% and stopped the run.
Worth recording how this was misdiagnosed. The growth showed up as
~/.cache, which is also where scancode keeps its rule index, so scancode was blamed first. It was not: with the scancode stage disabled the directory kept growing, and.cache/scancode-tkmeasured 0 bytes while.cache/pipheld all 3.3 GB.Change
PIP_NO_CACHE_DIRandPIP_CACHE_DIRjoin the cdxgen and prep allowlists.The prep allowlist had no Python entries at all. Prep does not resolve Python dependencies itself, but the resolvers it runs can shell into pip, and the setting has to survive that hop or the cache it exists to prevent gets written anyway.
PIP_CACHE_DIRis included for the opposite deployment: the one that wants the cache and has somewhere with room to put it. Neither key is credential-bearing, so both are safe additions to a list whose purpose is keeping secrets away from hostile-clone subprocesses.Test plan
scrubbed_env_for_cdxgenandscrubbed_env_for_preppytest tests/unit/integrations/(973 passed)ruff check .clean; em-dash lint clean