Bootstrap: docker
From: archlinux:latest
 
%post
    pacman -Sy --noconfirm reflector
    reflector --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
    pacman -Syu --noconfirm gcc cmake eigen python python-matplotlib texlive-core python-seaborn python-pandas jupyter make git png++ boost texlive-latexextra
    cd /opt/
    mkdir geophase
    git clone https://git.rwth-aachen.de/leia/geophase.git geophase/
    cd geophase/
    mkdir build && cd build/
    cmake -DCMAKE_BUILD_TYPE=Timing ..
    make
 
%runscript

    # CMD : geophase image command (see help below). 
    CMD=$1

    # Source directory 
    SOURCE_DIR=$2 

    # Build directory
    BUILD_DIR=$3
 
    case $CMD in
        clone) # Copy the 'geophase' source from /opt/geophase on the image to $SOURCE_DIR 
            echo 'Copying the geophase project from the image to $SOURCE_DIR' 
            cp -r /opt/geophase $SOURCE_DIR
            ;;
        build) 
            # Build in $SOURCE_DIR/$BUILD_DIR 
            rm -rf $SOURCE_DIR/$BUILD_DIR && mkdir -p "$SOURCE_DIR/$BUILD_DIR" 
            cd $SOURCE_DIR/$BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Timing .. && make && cd ../../
            ;;
        run-tests) 
            cd $SOURCE_DIR/$BUILD_DIR && ctest -V 
            ;;
        re-run-tests) 
            cp -r /opt/geophase/* $SOURCE_DIR
            cd $SOURCE_DIR/geophase/build && ctest -V 
            ;;
        jupyter-notebook)
            cd $SOURCE_DIR/jupyter-notebooks/
            jupyter notebook --no-browser --port=8889
            ;;
    esac
 
%help
    This container consists of the environment, the code, the build and the tests for the geophase project (https://git.rwth-aachen.de/leia/geophase).
 
    Usage:
        ./geophase.sif <command>
        singularity ru geophase.sif <command>
        singularity shell [-o overlay.img] geophase.sif (use with overlay)
        singularity shell --writable geophase.sif (use with embedded overlay)
 
    The commands are:
        clone                        Copies the geophase from /opt/geophase to the current working directory.
        getdata                      Copies the data and jupyter notebooks used for data visualization into './data'.
        build   [path-to-project]    Builds the geophase project. By default, it uses the '/opt/geophase' source.
        test    [path-to-project]    Run the tests. By default, the '/opt/geophase/build' binaries are used.
        jupyter [path-to-project]    Runs a Jupyter notebook. Default notebook: '/opt/geophase/jupyter-notebooks/geophase-interface-positioning.ipynb'
