Bootstrap: yum
OSVersion: 7
MirrorURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/x86_64/
include: yum

%environment
    export exedir=/opt/delft3dfm_latest/lnx64/scripts

    # Set host related properties
    export LD_LIBRARY_PATH="/host/lib:/host/lib64:$LD_LIBRARY_PATH"
    export PATH="/host/bin:$PATH"

    # Set MPI related properties
    MPI_DIR=/mpi
    export MPI_DIR
    export PATH="$MPI_DIR/bin:$PATH"
    export LD_LIBRARY_PATH="$MPI_DIR/lib:$LD_LIBRARY_PATH"

%setup
    mkdir ${SINGULARITY_ROOTFS}/host
    mkdir ${SINGULARITY_ROOTFS}/mpi

%files
    delft3dfm*.rpm /opt/tmp/

%labels
    NAME <singularityImageName>
    URL http://oss.deltares.nl/web/delft3dfm
    VENDOR Deltares
    CATEGORY Science
    DESCRIPTION Delft3D Open Source. Computational cores: D-Flow FM, D-Water Quality, D-FeedBack Control and D-Waves. Usage: See Installation_manual.pdf shipped with the Windows distribution.
    MAINTAINER delft3d.support@deltares.nl
    LICENSE Affero General Public License
    LICENSEFILE /opt/delft3dfm_latest/license/License.pdf
    ITERATION <singularityVersionNumberDelft3DFM>
    MPI_LIBRARY Without MPI library, please refer to your local ones

%post
    echo "Installing required packages..."
    mkdir -p /opt/tmp \
        && yum -y -v install libgomp &> /opt/tmp/libgomp.log
    
    # This sets the version in the metadata
    filename=`ls /opt/tmp/delft3dfm*.rpm`
    VERSION=$(echo $filename| cut -d'-' -f 4)
    echo "Determining package version..."
    echo "VERSION ${VERSION}" >> "$SINGULARITY_LABELS"

    echo "Preparing deployment..."
    rm -rf /opt/delft3dfm_$VERSION \
        && rpm -i /opt/tmp/delft3dfm-cli-hmwq_*.rpm --nofiledigest \
        && ln -s /opt/delft3dfm_$VERSION /opt/delft3dfm_latest \
        && rm /opt/delft3dfm_latest/lnx64/lib/libmpi* \
        && rm -rf /opt/tmp/delft3dfm*.rpm
