# ============================================================
# Acupedia Platform API — Backend Dockerfile
# Python 3.12 + FastAPI + Uvicorn + Bootstrap CLI
# ============================================================

FROM python:3.12-slim AS backend

WORKDIR /app

# Install system dependencies for asyncpg, psycopg, and psql
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    libpq-dev \
    postgresql-client \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy pyproject.toml first for layer caching
COPY pyproject.toml ./
COPY README.md ./

# Copy schema and source code
COPY docs/accupedia_db_v5.sql /app/schema/accupedia_db_v5.sql
COPY app ./app

# Copy git info metadata if generated on host
COPY .git_api_info* /app/.git_api_info

# Install project and CLI scripts into PATH
RUN pip install --no-cache-dir -e .

EXPOSE 8000

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

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

