# Dockerfile for simtools development.
#
# Based on the CORSIKA and sim_telarray image (no vector optimization).
# All dependencies for simtools are installed, but not simtools itself.
# It is expected that simtools is installed in an external directory
# mounted in the container.
#
# hadolint global ignore=DL3007,DL3013,DL3041,SC1091
# - DL3007, DL3041: ignore warnings about using latest
# - DL3013: ignore warnings about installing non-specific versions with microdnf)
# - SC1091: ignore warning about not being able to source the bashrc
ARG BUILD_OPT="prod6-baseline"
ARG HADRONIC_MODEL="qgs3"
ARG SIMTEL_VERSION="250903"
ARG CORSIKA_VERSION="78010"
ARG BERNLOHR_VERSION="1.70"
ARG AVX_INSTRUCTION="no_opt"
ARG PYTHON_VERSION="3.12"
FROM ghcr.io/gammasim/corsika-simtel-${SIMTEL_VERSION}-corsika-${CORSIKA_VERSION}-bernlohr-${BERNLOHR_VERSION}-${BUILD_OPT}-${HADRONIC_MODEL}-${AVX_INSTRUCTION}:latest
WORKDIR /workdir
ARG PYTHON_VERSION

RUN microdnf update -y && microdnf install -y \
    findutils gcc-c++ git wget \
    python${PYTHON_VERSION} python${PYTHON_VERSION}-pip python${PYTHON_VERSION}-devel && \
    microdnf clean all

# Create python symlink pointing to the specified Python version
RUN ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python

RUN wget --quiet https://raw.githubusercontent.com/gammasim/simtools/main/pyproject.toml && \
    python${PYTHON_VERSION} -m venv env && \
    . env/bin/activate && \
    pip install --no-cache-dir -U pip && \
    pip install --no-cache-dir toml-to-requirements && \
    toml-to-req --toml-file pyproject.toml --optional-lists dev,doc,tests && \
    pip uninstall -y toml-to-requirements && \
    pip install --no-cache-dir -r requirements.txt

ENV SIMTEL_PATH="/workdir/sim_telarray/"
ENV PATH="/workdir/simtools/env/bin/:$PATH"
SHELL ["/bin/bash", "-c"]

WORKDIR /workdir/external
