# This script can be run with the following command:
# docker build --build-arg branch=<your branch here, defaults to develop> -t "axom/tpls:gcc-13" - < dockerfile_gcc-13

FROM ghcr.io/llnl/radiuss:gcc-13-ubuntu-24.04
ARG branch=develop

SHELL ["/bin/bash", "-c"]
RUN sudo apt-get update -y
RUN sudo apt-get install gettext gfortran-$(gcc -dumpversion) graphviz libopenblas-dev \
                         lsb-release lua5.2 lua5.2-dev python3-sphinx locales ssh -fy
RUN sudo locale-gen en_US.utf8
RUN sudo useradd -m -s /bin/bash -G sudo axom

# Install proper doxygen version (should match version in LC host configs)
RUN sudo wget https://github.com/doxygen/doxygen/releases/download/Release_1_9_8/doxygen-1.9.8.linux.bin.tar.gz
RUN sudo tar -xf doxygen-1.9.8.linux.bin.tar.gz
RUN cd doxygen-1.9.8 && sudo make && sudo make install && doxygen --version

WORKDIR "/home/axom"
USER axom

# Set locale for formatting
ENV LANG='en_US.utf8' \
    LANGUAGE='en_US.utf8' \
    LC_ALL='en_US.utf8'

RUN git clone --recursive --branch $branch --single-branch --depth 1 https://github.com/LLNL/axom.git axom_repo

# Build/install TPLs via spack and then remove the temporary build directory on success
RUN cd axom_repo && python3 ./scripts/uberenv/uberenv.py --spack-env-file=./scripts/spack/configs/docker/ubuntu24/spack.yaml \
                                                         --project-json=.uberenv_config.json \
                                                         --spec="+python+mfem+raja+umpire+adiak+caliper %gcc_13" --prefix=/home/axom/axom_tpls -k \
                 && rm -rf /home/axom/axom_tpls/build_stage /home/axom/axom_tpls/spack

RUN mkdir -p /home/axom/export_hostconfig
RUN cp ./axom_repo/*.cmake /home/axom/export_hostconfig

# Make sure the new hostconfig worked
# Note: having high job slots causes build log to disappear and job to fail
RUN cd axom_repo && python3 config-build.py -hc *.cmake -bp build && cd build && make -j4 VERBOSE=1 && make -j4 test && cd /home/axom && rm -rf axom_repo