FROM python:3.12-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    && rm -rf /var/lib/apt/lists/*

COPY pyproject.toml .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir .

COPY . .

RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
# B4: run as root for staging so /data volume is writable without chown entrypoint.
# (Bind-mounted /data from host typically has host UID, not 1000.)

EXPOSE 8000

CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
