FROM python:3.13-slim

# WeasyPrint requires Cairo, Pango, GDK-PixBuf, and fontconfig at the OS level.
# These are not available in the slim image and must be installed explicitly.
RUN apt-get update && apt-get install -y --no-install-recommends \
    libpango-1.0-0 \
    libpangoft2-1.0-0 \
    libharfbuzz0b \
    libfontconfig1 \
    libcairo2 \
    libgdk-pixbuf-2.0-0 \
    shared-mime-info \
    fonts-dejavu-core \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python deps before copying source so this layer is cached on code-only changes.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY aws_warlens/ aws_warlens/
COPY main.py .

RUN useradd --system --no-create-home warlens \
    && mkdir -p /app/output \
    && chown warlens:warlens /app/output

USER warlens

ENTRYPOINT ["python", "main.py"]
