# The envlib-api image: the refresher (`envlib-api refresher`) and the API (`envlib-api-server`, as the
# service's entrypoint): one image, a service per command.
# Installs from uv.lock (--frozen), so the image runs exactly the locked stack, all from PyPI. To develop
# against an unreleased ebooklet, add a [tool.uv.sources] path entry locally, and remove it and re-lock
# (uv lock --upgrade-package ebooklet --refresh-package ebooklet) before building.
# The healthcheck is set per service in docker-swarm.yml (it differs between the refresher and the API).
FROM python:3.12-slim

COPY --from=ghcr.io/astral-sh/uv:0.8.17 /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock README.md ./
COPY envlib_api ./envlib_api
RUN uv sync --frozen --no-dev && rm -rf /root/.cache

RUN groupadd --gid 1000 appgroup && \
    useradd --uid 1000 --gid appgroup --shell /bin/bash --no-create-home appuser

USER appuser
ENV PYTHONUNBUFFERED=1 PATH="/app/.venv/bin:$PATH"

ENTRYPOINT ["envlib-api"]
CMD ["refresher"]
