# API runtime for laboratory 3. Pinned base image and Python dependencies.
FROM python:3.12.6-slim-bookworm

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

WORKDIR /app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY app ./app
COPY migrations ./migrations

RUN groupadd --gid 10001 app \
    && useradd --uid 10001 --gid 10001 --create-home app

USER 10001:10001
EXPOSE 8080

# Uvicorn is PID 1: it handles SIGTERM, stops accepting new connections and
# drains in-flight requests within the graceful shutdown window.
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080", "--no-access-log", "--timeout-graceful-shutdown", "5"]
