# ------------------------------------ # Stage 1: Build dependencies # ------------------------------------ FROM python:3.11-slim-bookworm AS builder WORKDIR /build COPY requirements.txt . # Install dependencies to a specific directory RUN pip install --no-cache-dir --target=/build/packages -r requirements.txt # ------------------------------------ # Stage 2: Final distroless image # ------------------------------------ # Using Debian 12 (Bookworm) based distroless to match builder FROM gcr.io/distroless/python3-debian12 WORKDIR /app # Add our packages to python path ENV PYTHONPATH=/app/packages ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Copy dependencies COPY --from=builder /build/packages /app/packages # Copy application code COPY app.py . # Expose port (metadata only, distroless doesn't enforce) EXPOSE 5000 # Run app.py directly (which uses waitress with signal handling) CMD ["app.py"]