Bootstrap: docker
From: ubuntu:16.04

%help
This is a test container.

%files
    ../../TomoATT /opt/TomoATT

%environment
    export PKG_DIR=/opt/packages
    export SINGULARITY_PKG_DIR=$PKG_DIR
    export SINGULARITYENV_APPEND_PATH=$PKG_DIR/bin
    export SINGULAIRTYENV_APPEND_LD_LIBRARY_PATH=$PKG_DIR/lib
    export PATH=$PKG_DIR/bin:$PATH
    export PATH=/opt/TomoATT/build/bin:$PATH
    export LD_LIBRARY_PATH=$PKG_DIR/lib:$LD_LIBRARY_PATH

%post
    echo "Installing required packages..."
    apt-get update && apt-get install -y wget git bash gcc gfortran g++ make file apt-transport-https ca-certificates

    # install gcc-9 and g++-9
    apt-get install -y software-properties-common && \
    add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
    apt-get update -y && \
    apt-get install -y gcc-9 g++-9 && \
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9

    # install latest cmake
    apt update && \
    apt install -y software-properties-common lsb-release && \
    apt clean all && \
    wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
    apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
    apt update && \
    apt install kitware-archive-keyring && \
    rm /etc/apt/trusted.gpg.d/kitware.gpg && \
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6AF7F09730B3F0A4 && \
    apt update && \
    apt install -y cmake && \
    apt clean all

    export PKG_DIR=/opt/packages
    export NPROC=4

    echo "Installing Open MPI"
    export OMPI_VERSOIN_MAJOR=3.0
    export OMPI_VERSION_FULL=3.0.1
    export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v$OMPI_VERSOIN_MAJOR/openmpi-$OMPI_VERSION_FULL.tar.gz"
    mkdir -p /tmp/ompi
    mkdir -p /opt
    # Download
    cd /tmp/ompi && wget -O openmpi-$OMPI_VERSION_FULL.tar.gz $OMPI_URL && tar -xvf openmpi-$OMPI_VERSION_FULL.tar.gz
    # Compile and install
    cd /tmp/ompi/openmpi-$OMPI_VERSION_FULL && ./configure --prefix=$PKG_DIR && make -j$NPROC && make install
    # Set env variables so we can compile our application
    export PATH=$PKG_DIR/bin:$PATH
    export LD_LIBRARY_PATH=$PKG_DIR/lib:$LD_LIBRARY_PATH
    export MANPATH=$PKG_DIR/share/man:$MANPATH

    echo "openmpi installed."

    echo "Compiling hdf5"

    export HDF5_VERSION_MAJOR=1.13
    export HDF5_VERSION_FULL=1.13.2
    export HDF5_URL="https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-$HDF5_VERSION_MAJOR/hdf5-$HDF5_VERSION_FULL/src/hdf5-$HDF5_VERSION_FULL.tar.gz"
    mkdir -p /tmp/hdf5
    cd /tmp/hdf5 && wget -O hdf5-$HDF5_VERSION_FULL.tar.gz $HDF5_URL && tar -xvf hdf5-$HDF5_VERSION_FULL.tar.gz && cd hdf5-$HDF5_VERSION_FULL
    tar -xvf hdf5-$HDF5_VERSION_FULL.tar.gz && cd hdf5-$HDF5_VERSION_FULL
    CC=mpicc CXX=mpic++ ./configure --enable-parallel --enable-unsupported --enable-shared --enable-cxx --prefix=$PKG_DIR && make -j$NPROC && make install

    echo "hdf5 installed."

    cd /opt/TomoATT
    mkdir -p build && cd build && rm -rf ./*
    cmake .. -DUSE_CUDA=True -DCMAKE_PREFIX_PATH=$PKG_DIR
    make -j$NPROC

    echo "TomoATT installed."

%labels

    Maintainer MasaruNagaso

    Version v1.0
