FROM python:3.11-slim-bookworm AS base

# Determinism: single-thread BLAS, fixed hash seed
ENV PYTHONHASHSEED=0 \
    OPENBLAS_NUM_THREADS=1 \
    MKL_NUM_THREADS=1 \
    OMP_NUM_THREADS=1 \
    VECLIB_MAXIMUM_THREADS=1 \
    NUMEXPR_NUM_THREADS=1

# System deps (rarely changes - good cache layer)
RUN apt-get update && \
    apt-get install -y --no-install-recommends git && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Layer 2: project metadata + source (needed for editable install)
COPY pyproject.toml ./
COPY src/ src/

# Layer 3: install deps via editable install (changes on dep or src bump)
RUN pip install --no-cache-dir -e ".[reproduce]"

# Layer 4: data + experiments + tooling (changes on data/experiment change)
COPY data/ data/
COPY experiments/ experiments/
COPY docker/ docker/
COPY reproduce.sh .
RUN chmod +x reproduce.sh

ENV PATH="/app/.venv/bin:$PATH"

ENTRYPOINT ["./reproduce.sh"]
