# A job container. It starts, does a stated amount of work, prints one verdict
# line, and stops. `restart: "no"` in the compose file is not an oversight.
FROM python:3.12-slim

# LOCAL=1 installs from the build context instead of PyPI — the path for
# building and proving this image *before* the release is published. The default
# is the community path: whatever is on PyPI.
ARG LOCAL=0
ARG VERSION=

LABEL org.opencontainers.image.title="jgtpricedb-util" \
      org.opencontainers.image.description="Run-to-completion jobs for a jgtpricedb price store" \
      org.opencontainers.image.source="https://pypi.org/project/jgtpricedb-util/"

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /work

# The context is copied unconditionally so one Dockerfile serves both paths;
# `.dockerignore` keeps it to the source tree. The PyPI build discards it.
COPY . /src

RUN set -eux; \
    if [ "$LOCAL" = "1" ]; then \
        pip install /src; \
    else \
        pip install "jgtpricedb-util${VERSION:+==$VERSION}"; \
    fi; \
    rm -rf /src; \
    jgtpdb --version

# Where the compose file mounts the holdings (read-only) and the writable work
# area. Created here so a bare `docker run` without mounts still has them.
RUN mkdir -p /data/current /work

# The entrypoint is the CLI, so the command is just the job:
#   docker run --rm jgtpricedb-util probe-relabel --holdings /data/current/pds
ENTRYPOINT ["jgtpdb"]
CMD ["--help"]
