Install CPU-only torch and drop playwright - 9.2GB image on a GPU-less VPS

Measured inside the image: 2.7GB of nvidia/ CUDA libraries and 691MB of
triton/, on a single-CPU VPS with no GPU. sentence-transformers pulls torch in
transitively, and pip's default Linux wheel bundles the whole CUDA stack because
it cannot know the target has none. That is ~3.4GB of code that can never
execute, in a 9.2GB image on a 48GB disk shared with a dozen other services -
and a build here has already failed once on "no space left on device".

torch now installs first from PyTorch's CPU index, so the requirements.txt pass
finds it satisfied and leaves it alone.

playwright is commented out rather than deleted. It is the last-resort
image-search tier and the Dockerfile never installs its browser binary, so in a
container the tier is skipped at runtime regardless while the package still
costs 137MB. Its import is lazy, so absence takes the existing "not installed"
path rather than breaking anything.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Suriyakumarvijayanayagam
2026-08-14 13:04:41 +05:30
parent 1b56aae396
commit c101f2c8ba
2 changed files with 20 additions and 1 deletions

View File

@@ -21,7 +21,20 @@ WORKDIR /app
# image-search fallback (see requirements.txt); run `playwright install
# chromium` in the container if you need that specific fallback tier.
COPY requirements.txt .
# torch is installed FIRST, from PyTorch's CPU-only index, and that ordering is
# the point. sentence-transformers pulls torch in transitively, and pip's
# default wheel for Linux bundles the entire CUDA stack - cuBLAS, cuDNN, NVRTC,
# Triton - because it cannot know the target has no GPU. Measured in this image
# it was 2.7GB of nvidia/ plus 691MB of triton/, none of which can ever execute
# on a CPU-only VPS, in a 9.2GB image on a 48GB disk shared with a dozen
# services. A build here has already failed once on "no space left on device".
#
# Installing it up front means the requirements.txt pass below finds torch
# already satisfied and leaves it alone. Keep these two steps in this order.
RUN python -m venv /opt/venv \
&& /opt/venv/bin/pip install --no-cache-dir \
--index-url https://download.pytorch.org/whl/cpu torch \
&& /opt/venv/bin/pip install --no-cache-dir -r requirements.txt

View File

@@ -52,7 +52,13 @@ aiofiles>=23.2.1
# Playwright (Python) - last-resort image-search fallback only.
# Run `playwright install chromium` once after pip install to enable it;
# the pipeline works fine without it (just one fewer fallback source).
playwright>=1.47.0
# playwright>=1.47.0
# Commented out, not deleted. It is the last-resort image-search tier, and the
# Dockerfile never installs its browser binary - so in a container the tier is
# skipped at runtime no matter what, while the package still costs 137MB. The
# import is lazy (app/services/playwright_image_fallback.py does it inside the
# function), so its absence is handled on the existing "not installed" path.
# Uncomment, and run `playwright install chromium`, if you ever want that tier.
# --- S3 / DigitalOcean Spaces (optional product image storage) ---
boto3>=1.34.162