FROM python:3.11-slim

# Set environment variables for Python
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy dependency configuration
COPY pyproject.toml /app/

# Stub package to leverage Docker layer caching for pip dependencies
RUN mkdir -p /app/app && touch /app/app/__init__.py \
    && pip install --no-cache-dir -e ".[prototype,embedding]"

# Copy application source code and migrations
COPY app/ /app/app/
COPY migrations/ /app/migrations/
COPY alembic.ini /app/
COPY data/ /app/data/

# Reinstall editable package to ensure all entry points and modules are bound
RUN pip install --no-deps -e .

# Expose default API port
EXPOSE 8000

# Default command: FastAPI API server
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
