# ---------------------------------------------------------------------------
#
# Create Ubuntu-based OpenFOAM (Foundation version) image
#
# Build
#   apptainer build of.sif org-openfoam.def
#
# Note
#   apptainer version 1.3.1
#
# ---------------------------------------------------------------------------
Bootstrap: localimage
From: containers/basic/{{ BASE_CONTAINER }}.sif

%arguments
    OS_DISTRO=ubuntu
    OS_VERSION=24.04
    MPI_IMPLEMENTATION=openmpi
    MPI_VERSION=4.1.5
    FRAMEWORK_VERSION=11
    FRAMEWORK_GIT_REF=default

%post -c /bin/bash
    curl -o /etc/apt/trusted.gpg.d/openfoam.asc https://dl.openfoam.org/gpg.key
    DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get -y install --no-install-recommends software-properties-common
    add-apt-repository http://dl.openfoam.org/ubuntu
    apt-get update
    apt-get -y install --no-install-recommends openfoam{{ FRAMEWORK_VERSION }}
    rm -rf /opt/openfoam{{ FRAMEWORK_VERSION }}/tutorials/*
    jq --arg app openfoam --arg commit {{ FRAMEWORK_GIT_REF }} \
        --arg branch {{ FRAMEWORK_GIT_REF }} \
        '.[$app] |= if . == null then
        {
            fork: "org-openfoam",
            branch: $branch,
            commit: $commit,
            source_script: "/opt/openfoam{{ FRAMEWORK_VERSION }}/etc/bashrc",
            version: "{{ FRAMEWORK_VERSION }}"
        }
        else . +
        {
            fork: "org-openfoam",
            branch: $branch,
            commit: $commit,
            source_script: "/opt/openfoam{{ FRAMEWORK_VERSION }}/etc/bashrc",
            version: "{{ FRAMEWORK_VERSION }}"
        } end' /apps.json > /tmp/apps.json

%runscript
    #!/bin/bash
    if [ $# -eq 0 ]; then
        exec /bin/bash
    else
        exec "$@"
    fi

%labels
    Maintainer Mohammed Elwardi Fadeli
    Description Ubuntu-based OpenFOAM (Foundation version) image with OpenMPI
