FROM python:3.12-slim

WORKDIR /app

# Poster rendering needs:
#   - libcairo2 (cairosvg ↔ Cairo bindings) for SVG → PNG raster
#   - fonts-dejavu-core for the DejaVuSans-Bold font used by PostersService
# These add ~15 MB to the image but keep poster generation in-process and fast.
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        libcairo2 \
        fonts-dejavu-core \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir \
    fastapi \
    uvicorn \
    fastf1 \
    python-slugify \
    pillow \
    cairosvg

COPY cdn-api.py circuits_service.py ergast_service.py posters_service.py ./
COPY models/ ./models/
COPY circuits/ ./circuits/

EXPOSE 8000

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