From b5a99535719be29513f00d5e21cbd3fec10c72bb Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Mon, 5 Oct 2026 09:31:29 +0000 Subject: [PATCH] fix(docker): survive slow networks while installing Python packages uv gave up on big wheels (ctranslate2 on arm64) after its default 30 s read timeout, failing the one-command install. Allow 300 s with 5 retries, and give the image's uv sync steps a BuildKit cache mount so a rerun resumes from what was already downloaded (the cache stays out of the image). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01GP566GcZrYdzeWsGQeDCYA --- Dockerfile.cloudron | 4 +++- fastapi_backend/Dockerfile | 13 +++++++++---- proxmox/install/lens-install.sh | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Dockerfile.cloudron b/Dockerfile.cloudron index 029ea157b..b9cd33677 100644 --- a/Dockerfile.cloudron +++ b/Dockerfile.cloudron @@ -36,7 +36,9 @@ COPY --from=ghcr.io/astral-sh/uv:0.8 /uv /usr/local/bin/uv ENV PATH="/app/code/venv/bin:/usr/local/node-24.19.0/bin:$PATH" \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - NEXT_TELEMETRY_DISABLED=1 + NEXT_TELEMETRY_DISABLED=1 \ + UV_HTTP_TIMEOUT=300 \ + UV_HTTP_RETRIES=5 # The backend, in a virtualenv built against the base image's Python 3.12 WORKDIR /app/code/backend diff --git a/fastapi_backend/Dockerfile b/fastapi_backend/Dockerfile index 5bfe6b698..ea51c2de4 100644 --- a/fastapi_backend/Dockerfile +++ b/fastapi_backend/Dockerfile @@ -5,12 +5,17 @@ # Outlook .msg emails also need the msg extra (extract-msg, GPL-3.0): --build-arg EXTRAS="msg". FROM python:3.12-slim-bookworm AS base -# UV_NO_CACHE: no package cache left in the image (it doubled its size) or in the container (what workers fetch) +# UV_NO_CACHE: no package cache left in the image (it doubled its size) or in the container (what workers fetch); the +# build's own `uv sync` steps use a BuildKit cache mount instead, outside the image, so a rerun after a failed or +# interrupted download picks up where it stopped. UV_HTTP_TIMEOUT and UV_HTTP_RETRIES: slow or flaky networks (a +# Raspberry Pi on Wi-Fi) finish the big wheels instead of failing the install after uv's default 30 seconds. ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_COMPILE_BYTECODE=1 \ UV_LINK_MODE=copy \ UV_NO_CACHE=1 \ + UV_HTTP_TIMEOUT=300 \ + UV_HTTP_RETRIES=5 \ UV_PROJECT_ENVIRONMENT=/opt/venv \ PATH="/opt/venv/bin:$PATH" @@ -35,12 +40,12 @@ RUN case " $EXTRAS " in *" doctr "*) apt-get update \ # faster-whisper (the whisper extra) is always in: transcription works out of the box, on the CPU (SenseVoice, which # needs PyTorch, is an extra) COPY pyproject.toml uv.lock README.md ./ -RUN uv sync --frozen --no-install-project --extra whisper \ +RUN --mount=type=cache,target=/root/.cache/uv env -u UV_NO_CACHE uv sync --frozen --no-install-project --extra whisper \ $( [ "$DEV" = "true" ] || echo --no-dev ) \ $(for e in $EXTRAS; do printf -- '--extra %s ' "$e"; done) COPY . . -RUN uv sync --frozen --extra whisper $( [ "$DEV" = "true" ] || echo --no-dev ) $(for e in $EXTRAS; do printf -- '--extra %s ' "$e"; done) \ +RUN --mount=type=cache,target=/root/.cache/uv env -u UV_NO_CACHE uv sync --frozen --extra whisper $( [ "$DEV" = "true" ] || echo --no-dev ) $(for e in $EXTRAS; do printf -- '--extra %s ' "$e"; done) \ && useradd --create-home --uid 1000 lens && mkdir -p /data && chown lens:lens /data ENV ARCHIVE_CONFIG=/app/docker/archive.yaml @@ -61,7 +66,7 @@ ARG EXTRAS="" ARG DEV=false ARG YOLOX_URL=https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx ARG YOLOX_SHA256=c5c2d13e59ae883e6af3b45daea64af4833a4951c92d116ec270d9ddbe998063 -RUN uv sync --frozen --extra whisper --extra objects $( [ "$DEV" = "true" ] || echo --no-dev ) $(for e in $EXTRAS; do printf -- '--extra %s ' "$e"; done) \ +RUN --mount=type=cache,target=/root/.cache/uv env -u UV_NO_CACHE uv sync --frozen --extra whisper --extra objects $( [ "$DEV" = "true" ] || echo --no-dev ) $(for e in $EXTRAS; do printf -- '--extra %s ' "$e"; done) \ && mkdir -p /opt/lens/models \ && python -c "import sys, urllib.request; urllib.request.urlretrieve(sys.argv[1], sys.argv[2])" "$YOLOX_URL" /opt/lens/models/yolox_s.onnx \ && echo "$YOLOX_SHA256 /opt/lens/models/yolox_s.onnx" | sha256sum -c - diff --git a/proxmox/install/lens-install.sh b/proxmox/install/lens-install.sh index 3859d4c32..e4950eaab 100755 --- a/proxmox/install/lens-install.sh +++ b/proxmox/install/lens-install.sh @@ -108,7 +108,7 @@ msg_ok "Configured Lens" msg_info "Building Lens API (patience)" cd /opt/lens/fastapi_backend -export UV_PYTHON="3.12" +export UV_PYTHON="3.12" UV_HTTP_TIMEOUT=300 UV_HTTP_RETRIES=5 # slow links finish the big wheels $STD uv sync --frozen --no-dev --extra whisper # faster-whisper: transcription on the CPU msg_ok "Built Lens API"