From df25e8e484c6e68e8c5dabfcab3eef70a9847796 Mon Sep 17 00:00:00 2001 From: Hong Phuc Date: Sat, 30 May 2026 12:38:59 +0700 Subject: [PATCH] perf: PyTorch CPU-only + pip cache cleanup to reduce Docker image size (~3GB savings) --- Dockerfile | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 758642f..9b043fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,21 +8,34 @@ ENV PYTHONDONTWRITEBYTECODE=1 \ WORKDIR /app +# System deps: ffmpeg for video processing RUN apt-get update \ && apt-get install -y --no-install-recommends \ ffmpeg \ curl \ && rm -rf /var/lib/apt/lists/* +# Install PyTorch CPU-only first (saves ~1.5GB vs GPU version) +RUN pip install --no-cache-dir torch==2.11.0 --index-url https://download.pytorch.org/whl/cpu + +# Install remaining Python deps COPY requirements.txt ./ -RUN pip install --upgrade pip \ - && pip install -r requirements.txt \ - && pip install pytest +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt +# Install Chromium for Playwright (already cached at /ms-playwright) RUN python -m playwright install --with-deps chromium +# Clean up pip cache and temp files +RUN pip cache purge 2>/dev/null || true \ + && find /usr/local/lib/python3.14 -name '__pycache__' -exec rm -rf {} + 2>/dev/null || true \ + && find /usr/local/lib/python3.14 -name '*.pyc' -delete 2>/dev/null || true \ + && rm -rf /root/.cache + +# Copy app code COPY . . +# Create non-root user RUN groupadd -r appuser && useradd -r -g appuser -d /app appuser \ && chown -R appuser:appuser /app /ms-playwright