FROM python:3.11-slim AS builder

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/

WORKDIR /app

COPY pyproject.toml uv.lock README.md ./
COPY plotstyle/pyproject.toml plotstyle/README.md plotstyle/
COPY gallery/ gallery/

RUN uv build --package gallery -o dist

FROM python:3.11-slim

RUN apt-get update \
    && apt-get install -y --no-install-recommends imagemagick \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=builder /app/dist/*.whl /tmp/
COPY deploy/entrypoint.sh deploy/entrypoint.sh

RUN pip install --no-cache-dir /tmp/*.whl && rm /tmp/*.whl

RUN useradd -r -s /bin/false gallery
USER gallery

ENTRYPOINT ["gallery"]
CMD ["generate"]
