8000 fix(docker): survive slow networks while installing Python packages by adeelahmad · Pull Request #182 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile.cloudron
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions fastapi_backend/Dockerfile
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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 -
Expand Down
2 changes: 1 addition & 1 deletion proxmox/install/lens-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading
0