FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive

# ---------------------------------------------------------------------------
# System dependencies (dnf instead of apt)
# ---------------------------------------------------------------------------
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    make \
    cmake \
    ninja-build \
    libxerces-c-dev \
    git \
    curl \
    ca-certificates \
    python3 \
    python3-dev \
    python3-pip \
    python3-venv \
    && rm -rf /var/lib/apt/lists/*
# ---------------------------------------------------------------------------
# uv
# ---------------------------------------------------------------------------
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"

WORKDIR /src

# ---------------------------------------------------------------------------
# Copy only files needed for the C++ build
# ---------------------------------------------------------------------------
COPY CMakeLists.txt .
COPY superbuild/ superbuild/
COPY src/ src/
COPY include/ include/
COPY bind/ bind/
COPY lib/ lib/
COPY run_pbwo4.cc .
COPY run_sampling.cc .

# lib/geant4/.git is a submodule pointer to the host's .git/modules dir, which
# is not copied into the image. Replace it with a fresh repo so Geant4's cmake
# git status calls succeed.
RUN rm lib/geant4/.git && git init lib/geant4

# ---------------------------------------------------------------------------
# Build Geant4 + miniCaloSim
# ---------------------------------------------------------------------------
RUN cmake -S superbuild -B build -G Ninja \
      -DGEANT4_INSTALL_DATA=ON

RUN cmake --build build --parallel

# ---------------------------------------------------------------------------
# Python environment (uv)
# ---------------------------------------------------------------------------
RUN uv venv /opt/venv

ENV PATH="/opt/venv/bin:${PATH}"

ADD docker/pyproject.toml pyproject.toml

RUN uv sync

WORKDIR /workspace

ENTRYPOINT ["/bin/bash", "-l"]