ARG PYTHON_TAG=3.12.12-slim-bookworm
FROM python:${PYTHON_TAG} AS base

ARG PIP_SPEC="pip<25"
ARG SETUPTOOLS_SPEC="setuptools<70"
ARG PIP_INDEX_URL=""
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY

ENV PYTHONDONTWRITEBYTECODE=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DEFAULT_TIMEOUT=120 \
    PIP_INDEX_URL=${PIP_INDEX_URL}

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

RUN python -m pip install --upgrade "${PIP_SPEC}" "${SETUPTOOLS_SPEC}" wheel

FROM base AS deps
ARG CONSTRAINTS_FILE
COPY requirements /opt/deepfos-requirements
COPY verification/constraints /opt/deepfos-constraints
RUN --mount=type=cache,target=/root/.cache/pip,id=deepfos-py-compat-pip,sharing=locked \
    set -eux; \
    constraints="/opt/deepfos-constraints/${CONSTRAINTS_FILE}"; \
    PIP_NO_CACHE_DIR=0 python -m pip install -c "$constraints" \
        -r /opt/deepfos-requirements/testing.txt; \
    PIP_NO_CACHE_DIR=0 python -m pip install -c "$constraints" 'build<1.3'

FROM deps AS runner
ENV PY_COMPAT_WARMED=1
COPY docker/py-compat/run-in-container.sh /usr/local/bin/deepfos-py-compat-runner
RUN chmod +x /usr/local/bin/deepfos-py-compat-runner
ENTRYPOINT ["/usr/local/bin/deepfos-py-compat-runner"]
