Splits torch+torchvision into its own RUN layer so edits to requirements.txt don't invalidate the ~200MB CPU-only torch download. Adds buildkit cache mounts on both pip-install layers so even when a layer is invalidated (or buildkit evicts it) the wheel is reused from the on-disk pip cache instead of refetching from download.pytorch.org. Triggered by two consecutive deploy failures where pytorch.org timed out mid-download (2026-05-13 ~21:41 and possibly ~22:47). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.6 KiB
Docker
54 lines
1.6 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
FROM python:3.12-slim
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
# Build dependencies
|
|
gcc \
|
|
g++ \
|
|
make \
|
|
# Image processing libraries
|
|
libvips42 \
|
|
libvips-dev \
|
|
# ExifTool for metadata extraction
|
|
libimage-exiftool-perl \
|
|
# FFmpeg for video processing
|
|
ffmpeg \
|
|
# Git for some Python packages
|
|
git \
|
|
# PostgreSQL client (for potential future use)
|
|
postgresql-client \
|
|
# Clean up
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
# 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 .
|
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
|
pip install -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create necessary directories
|
|
RUN mkdir -p /data/thumbs /data/db /data/proxies /data/models /app/config
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Run the application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] |