FROM python:3.12-slim

WORKDIR /app

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc libpq-dev curl ffmpeg \
    && rm -rf /var/lib/apt/lists/*

# Python deps (cached layer)
COPY backend/requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Git commit SHA for version tracking
ARG GIT_COMMIT_SHA=unknown

# Application code
COPY backend/ /app/
RUN echo "${GIT_COMMIT_SHA}" > /app/.git-commit
COPY prompts/ /prompts/
COPY config/ /config/
COPY alembic.ini /app/alembic.ini
COPY alembic/ /app/alembic/

EXPOSE 8000

HEALTHCHECK --interval=15s --timeout=5s --retries=3 --start-period=10s \
    CMD curl -f http://localhost:8000/health || exit 1

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