FROM python:3.13-slim

WORKDIR /app

# install pq (libpq5) - a driver for postgres
RUN apt-get update && apt-get install -y --no-install-recommends \
    libpq5  \
    && rm -rf /var/lib/apt/lists/*

# Install uv for fast, reproducible installs
RUN pip install --no-cache-dir uv alembic procrastinate psycopg2-binary

# Install Python dependencies from pyproject.toml
COPY pyproject.toml .
RUN --mount=type=cache,target=/root/.cache/pip \
    uv pip install --no-cache-dir --system --requirements pyproject.toml

# Download spaCy language models
RUN --mount=type=cache,target=/root/.cache/pip \
    python -m spacy download en_core_web_sm && \
    python -m spacy download fr_core_news_sm && \
    python -m spacy download es_core_news_sm && \
    python -m spacy download it_core_news_sm && \
    python -m spacy download de_core_news_sm

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

EXPOSE 8000
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
