runpod images: cache wheels across venv rebuilds

PyPI's CDN throttles a machine that has pulled 100 GB of wheels in a day
to ~400 KB/s; a venv rebuild that only needed a new apt layer above it
then spends hours re-downloading torch. Cache mounts for pip and uv keep
the wheels between builds.
Co-Authored-By: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKm7Z56iKjHgNkHc6VhWKz
parent c9fa479c
...@@ -76,7 +76,10 @@ RUN --mount=type=cache,target=/root/.cache/pip set -eux; \ ...@@ -76,7 +76,10 @@ RUN --mount=type=cache,target=/root/.cache/pip set -eux; \
# library during a cold start costs more than carrying the layer. # library during a cold start costs more than carrying the layer.
ARG PROFILE ARG PROFILE
COPY packaging/runpod/profiles/ /tmp/venv-profiles/ COPY packaging/runpod/profiles/ /tmp/venv-profiles/
RUN set -eux; \ # Cache mounts for both installers: a venv rebuild (the apt layer above it
# changed, say) re-downloads nothing — which matters, because PyPI's CDN
# throttles a machine that has pulled 100 GB of wheels in a day to ~400 KB/s.
RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=/root/.cache/uv set -eux; \
for extra in /tmp/venv-profiles/${PROFILE}.venv-*.txt; do \ for extra in /tmp/venv-profiles/${PROFILE}.venv-*.txt; do \
[ -f "$extra" ] || continue; \ [ -f "$extra" ] || continue; \
name="$(basename "$extra" .txt)"; name="${name#${PROFILE}.venv-}"; \ name="$(basename "$extra" .txt)"; name="${name#${PROFILE}.venv-}"; \
...@@ -89,14 +92,14 @@ RUN set -eux; \ ...@@ -89,14 +92,14 @@ RUN set -eux; \
python -m pip install --no-cache-dir uv; \ python -m pip install --no-cache-dir uv; \
# best-match across indexes: the torch index also carries stale copies # best-match across indexes: the torch index also carries stale copies
# of ordinary packages, and first-index-wins would pin those. # of ordinary packages, and first-index-wins would pin those.
uv pip install --python "$vdir/bin/python" --no-cache \ uv pip install --python "$vdir/bin/python" \
--index-strategy unsafe-best-match -r "$extra"; \ --index-strategy unsafe-best-match -r "$extra"; \
else \ else \
"$vdir/bin/pip" install --no-cache-dir -r "$extra"; \ "$vdir/bin/pip" install -r "$extra"; \
fi; \ fi; \
nodeps="${extra%.txt}.nodeps"; \ nodeps="${extra%.txt}.nodeps"; \
if [ -f "$nodeps" ]; then \ if [ -f "$nodeps" ]; then \
"$vdir/bin/pip" install --no-cache-dir --no-deps -r "$nodeps"; \ "$vdir/bin/pip" install --no-deps -r "$nodeps"; \
fi; \ fi; \
find "$vdir" -name __pycache__ -type d -prune -exec rm -rf {} +; \ find "$vdir" -name __pycache__ -type d -prune -exec rm -rf {} +; \
"$vdir/bin/python" -c "import ${name}; print('${name}', getattr(${name}, '__version__', 'ok'), 'in its own venv')"; \ "$vdir/bin/python" -c "import ${name}; print('${name}', getattr(${name}, '__version__', 'ok'), 'in its own venv')"; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment