Spaces:
Running
Running
fix: split runtime RUN layers and add pip timeout/retries
Browse filesSplit the monolithic apt+pip RUN into three separate layers so BuildKit
caches each independently — a pip network stall no longer forces Node.js
to reinstall. Add --timeout 120 --retries 5 and a 3-attempt retry loop
to pip install huggingface_hub/pyyaml (mirrors the uv sync retry pattern).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Dockerfile +12 -3
Dockerfile
CHANGED
|
@@ -98,19 +98,28 @@ ENV LANG=C.UTF-8 \
|
|
| 98 |
|
| 99 |
ARG NODE_MAJOR=22
|
| 100 |
|
| 101 |
-
# Install:
|
| 102 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 103 |
curl ca-certificates gnupg nginx jq \
|
| 104 |
-
&&
|
|
|
|
|
|
|
|
|
|
| 105 |
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
|
| 106 |
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
|
| 107 |
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] \
|
| 108 |
https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" \
|
| 109 |
> /etc/apt/sources.list.d/nodesource.list \
|
| 110 |
&& apt-get update && apt-get install -y --no-install-recommends nodejs \
|
| 111 |
-
&& pip3 install --no-cache-dir --break-system-packages huggingface_hub pyyaml \
|
| 112 |
&& rm -rf /var/lib/apt/lists/*
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# pnpm for `pnpm start` in Next.js runtime
|
| 115 |
RUN corepack enable && corepack install -g pnpm@10.26.2
|
| 116 |
|
|
|
|
| 98 |
|
| 99 |
ARG NODE_MAJOR=22
|
| 100 |
|
| 101 |
+
# Install: nginx, curl, jq, gnupg (separate layer — cached independently)
|
| 102 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 103 |
curl ca-certificates gnupg nginx jq \
|
| 104 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 105 |
+
|
| 106 |
+
# Install Node.js (separate layer so apt cache miss doesn't re-download pip packages)
|
| 107 |
+
RUN mkdir -p /etc/apt/keyrings \
|
| 108 |
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
|
| 109 |
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
|
| 110 |
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] \
|
| 111 |
https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" \
|
| 112 |
> /etc/apt/sources.list.d/nodesource.list \
|
| 113 |
&& apt-get update && apt-get install -y --no-install-recommends nodejs \
|
|
|
|
| 114 |
&& rm -rf /var/lib/apt/lists/*
|
| 115 |
|
| 116 |
+
# Install Python helpers (separate layer + retries for flaky HF Spaces network)
|
| 117 |
+
RUN pip3 install --no-cache-dir --break-system-packages --timeout 120 --retries 5 \
|
| 118 |
+
huggingface_hub pyyaml \
|
| 119 |
+
|| (echo "pip retry 2" && pip3 install --no-cache-dir --break-system-packages --timeout 120 --retries 5 huggingface_hub pyyaml) \
|
| 120 |
+
|| (echo "pip retry 3" && pip3 install --no-cache-dir --break-system-packages --timeout 120 --retries 5 huggingface_hub pyyaml) \
|
| 121 |
+
|| (echo "ERROR: pip install failed after 3 attempts" && exit 1)
|
| 122 |
+
|
| 123 |
# pnpm for `pnpm start` in Next.js runtime
|
| 124 |
RUN corepack enable && corepack install -g pnpm@10.26.2
|
| 125 |
|