# /api — FastAPI proxy (charter §4). Build context is the repo root so the
# canon log schemas (/docs/schemas) are bundled into the image.
FROM python:3.12-slim

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

WORKDIR /app

# Install deps first so the layer caches when only app code changes.
COPY api/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# App code, the role prompts (§16 — prompts are source code), and the schema
# contract (single source of truth in docs/schemas).
COPY api/app ./app
COPY api/prompts ./prompts
COPY docs/schemas ./schemas
COPY content ./content

# Run as non-root.
RUN useradd --create-home --uid 1000 appuser
USER appuser

EXPOSE 8000

# fly.io / compose set PORT; default to 8000 (charter localhost:8000).
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]
