diff --git a/backend/Dockerfile b/backend/Dockerfile index 2a67133..b238c75 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1.7 FROM python:3.12-slim # Install system dependencies @@ -22,13 +23,23 @@ RUN apt-get update && apt-get install -y \ WORKDIR /app -# Copy requirements first for better caching +# Install PyTorch CPU-only FIRST, in its own layer, so open-clip-torch +# doesn't pull the full CUDA build (~7 GB). CPU inference is all we need +# — the heavy lifting happens through ONNX Runtime. +# +# Two cache wins here: +# 1. Its own RUN layer means edits to requirements.txt don't force a +# re-pull of the ~200MB torch wheel. +# 2. The buildkit cache mount keeps pip's download cache on disk +# across builds even when the layer itself is invalidated, so a +# torch-version bump or a builder cache eviction still reuses the +# wheel from local cache instead of re-fetching from pytorch.org. +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu + COPY requirements.txt . -# Install PyTorch CPU-only FIRST so open-clip-torch doesn't pull the full -# CUDA build (~7 GB). CPU inference is all we need — the heavy lifting -# happens through ONNX Runtime. -RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu \ - && pip install --no-cache-dir -r requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt # Copy application code COPY . .