# Serving image: only the API and the trained model, nothing else.
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt gunicorn==23.0.0

COPY pyproject.toml README.md ./
COPY src ./src
RUN pip install --no-deps .

# The trained, calibrated model bundle produced by `make train` (copied in at build time).
COPY models/model.joblib /app/models/model.joblib
COPY configs ./configs

RUN useradd --create-home --uid 10001 appuser
USER appuser

ENV MODEL_PATH=/app/models/model.joblib \
    PORT=8000
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request,os; urllib.request.urlopen(f'http://127.0.0.1:{os.environ[\"PORT\"]}/health')"
CMD gunicorn --workers 2 --bind 0.0.0.0:$PORT --access-logfile - "noshow.serving.app:create_app()"
