FROM python:3.12.4-slim-bookworm@sha256:a3e58f9399353be051735f09be0316bfdeab571a5c6a24fd78b92df85bcb2d85

ARG ARTIFACT_UID=1000
ARG ARTIFACT_GID=1000

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    SOURCE_DATE_EPOCH=1785283200 \
    MPLCONFIGDIR=/home/artifact/.cache/matplotlib \
    OPENBLAS_NUM_THREADS=1 \
    OMP_NUM_THREADS=1 \
    MKL_NUM_THREADS=1

RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates curl git make tini \
    && rm -rf /var/lib/apt/lists/* \
    && groupadd --gid "${ARTIFACT_GID}" artifact \
    && useradd --uid "${ARTIFACT_UID}" --gid "${ARTIFACT_GID}" --create-home artifact

WORKDIR /opt/conformalfl
COPY requirements.lock ./
RUN pip install --no-cache-dir -r requirements.lock
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
RUN pip install --no-cache-dir --no-deps .

WORKDIR /workspace
RUN mkdir -p /home/artifact/.cache/pip /home/artifact/.cache/matplotlib \
    && chown -R artifact:artifact /home/artifact /workspace

COPY docker/entrypoint.sh /usr/local/bin/conformalfl-entrypoint
RUN chmod 0755 /usr/local/bin/conformalfl-entrypoint

USER artifact
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/conformalfl-entrypoint"]
CMD ["make", "reproduce-smoke"]
