# ============================================================ # Stage 1: Builder — install Python dependencies # ============================================================ FROM python:3.11-slim AS builder WORKDIR /install # System dependencies required to build some Python packages # (OpenCV, MediaPipe, grpcio, cffi, etc.) RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libgl1 \ libglib2.0-0 \ libgomp1 \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt . # Install all Python deps into an isolated prefix so we can copy # only the built packages to the final stage # Also install gunicorn as the production WSGI server RUN pip install --no-cache-dir --prefix=/python-deps -r requirements.txt gunicorn # ============================================================ # Stage 2: Runtime image # ============================================================ FROM python:3.11-slim LABEL maintainer="undertone-classification" LABEL description="Skin undertone classification — Flask + TensorFlow + MediaPipe" # Runtime system libs (OpenCV needs libGL/libGLib; MediaPipe needs libgomp) RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # Copy installed Python packages from the builder stage COPY --from=builder /python-deps /usr/local WORKDIR /app # Copy application source code COPY app.py . COPY templates/ templates/ COPY static/ static/ COPY models/ models/ # Create uploads directory that Flask writes to at runtime RUN mkdir -p static/uploads # Expose Flask's default port EXPOSE 5000 # Run with Gunicorn for production (single worker keeps model in memory) # Falls back gracefully: if gunicorn is unavailable the CMD can be swapped # to `python app.py` during development. ENV FLASK_ENV=production \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 # Use gunicorn; 1 worker so the global ai_engine singleton is shared CMD ["python", "-m", "gunicorn", \ "--bind", "0.0.0.0:5000", \ "--workers", "1", \ "--timeout", "120", \ "app:app"]