# issue-core REST ingestion service image.
#
# Installs the published issue-core[api] package from the Coulomb Gitea PyPI
# index (no sibling-checkout build context) and runs the FastAPI ingestion
# server on :8765. Built and pushed to gitea.coulomb.social/coulomb/issue-core.
FROM python:3.12-slim AS runtime

ARG ISSUE_CORE_VERSION=">=0.2,<0.3"
# Do not name this PIP_INDEX_URL — Docker exposes ARGs as env vars during RUN,
# and pip treats PIP_INDEX_URL as the sole primary index (excluding PyPI).
ARG GITEA_PYPI_INDEX_URL=https://gitea.coulomb.social/api/packages/coulomb/pypi/simple/

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HOME=/home/app

# Non-root runtime user; HOME drives issue-core's config dir
# (~/.config/issue-tracker/backends.json).
RUN useradd --create-home --home-dir /home/app --uid 10001 app

RUN pip install --no-cache-dir \
        --index-url https://pypi.org/simple \
        --extra-index-url "${GITEA_PYPI_INDEX_URL}" \
        "issue-core[api]${ISSUE_CORE_VERSION}"

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

USER app
EXPOSE 8765

# Entrypoint renders backends.json from env, then execs the server.
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
