Fix worker rq not found — build venv natively in Playwright image

The Playwright Noble image ships Python 3.12 while the builder uses
python:3.11-slim. Copying the venv produced broken shebangs, causing
"exec /app/.venv/bin/rq: no such file or directory".

Fix: install uv in the worker stage and run uv sync natively so the
venv targets this image's Python version. Manifests copied first for
layer cache efficiency.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-08-04 21:39:51 +03:30
parent 0bbd4ba840
commit 1ce57c3ea2
+10 -4
View File
@@ -49,6 +49,8 @@ EXPOSE 8000
CMD ["python", "main.py", "admin"]
# ── Stage 2b: worker runtime (Playwright image with Chromium) ────────────────
# The Playwright Noble image ships Python 3.12. Copying a venv built with
# python:3.11-slim would produce broken shebangs — so we build the venv here.
FROM oci.reg.darano.ir//mcr.microsoft.com/playwright:v1.62.0-noble AS worker
ENV PATH="/app/.venv/bin:$PATH" \
@@ -62,11 +64,15 @@ ENV PATH="/app/.venv/bin:$PATH" \
WORKDIR /app
# Copy application code
COPY . .
# Copy manifests + lockfile first (stable cache layer)
COPY pyproject.toml uv.lock* ./
# Copy Python deps from builder stage
COPY --from=builder /app/.venv /app/.venv
# Install deps natively so the venv targets this image's Python
RUN pip install --no-cache-dir --upgrade uv==0.11.31 \
&& uv sync --frozen --no-dev --no-install-project
# Copy app code (busts cache on code changes, not deps)
COPY . .
# Playwright's Chromium is already downloaded and pre-patched with
# undetected-chromedriver-friendly modifications, so no patch_driver run needed.