FROM python:3.12-slim@sha256:78387bc3881b8273120a12ebe6c1ab22b018ccc2c9adf565ae1ac9b536e184ea AS builder
# multi-arch OCI index digest (linux/amd64 + linux/arm64)

ARG AISIMULATE_TAG=v0.12.0

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        curl \
        pkg-config \
    && rm -rf /var/lib/apt/lists/*

RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs \
        | sh -s -- -y --profile minimal --default-toolchain 1.91.0
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /src
RUN curl -fsSL -o /tmp/aisimulate.tar.gz \
        "https://github.com/ai-dynamo/aisimulate/archive/refs/tags/${AISIMULATE_TAG}.tar.gz" \
    && tar -xzf /tmp/aisimulate.tar.gz --strip-components=1 \
    && rm /tmp/aisimulate.tar.gz

RUN pip install --no-cache-dir "maturin>=1.12,<2" \
    && (cd python/aisimulate && maturin build --release -i python3 --out /opt/wheels)

FROM python:3.12-slim@sha256:78387bc3881b8273120a12ebe6c1ab22b018ccc2c9adf565ae1ac9b536e184ea

ARG PYTHON_BASE_DIGEST=sha256:78387bc3881b8273120a12ebe6c1ab22b018ccc2c9adf565ae1ac9b536e184ea
ARG DYNOSIM_PLATFORM

LABEL swo.bench.dynosim.wheel_pin="ai-dynamo==1.5.0"
LABEL swo.bench.dynosim.base_digest="${PYTHON_BASE_DIGEST}"
LABEL swo.bench.dynosim.platform="${DYNOSIM_PLATFORM}"

COPY --from=builder /opt/wheels /opt/wheels
ENV PIP_PREFIX=/opt/dynosim \
    PATH="/opt/dynosim/bin:${PATH}" \
    PYTHONPATH="/opt/dynosim/lib/python3.12/site-packages"

RUN pip install --no-cache-dir /opt/wheels/aisimulate-*.whl
RUN pip install --no-cache-dir ai-dynamo==1.5.0 scikit-learn
