Skip to content

Commit

Permalink
Improve Singularity image (#330)
Browse files Browse the repository at this point in the history
Fixes shortcomings in singularity image (pyenv and paraview related). See PR for details.

Co-authored-by: Umar <[email protected]>
Co-authored-by: Ahmad Hesam <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2023
1 parent 1fa436f commit 2bd8613
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/singularity-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ jobs:
options: "--privileged --workdir /data"
steps:
- uses: actions/checkout@v3

- name: Add root user to subuid and subgid...
run: |
echo root:100000:65536 >> /etc/subuid
echo root:100000:65536 >> /etc/subgid
- name: Set correct branch...
run: |
export GITHUB_BRANCH_NAME=${{ github.head_ref || github.ref_name }}
sed -i "s|BDM_BRANCH=\"master\"|BDM_BRANCH=\"$GITHUB_BRANCH_NAME\"|" Singularity
- name: Build singularity image...
run: |
singularity build Singularity.sif Singularity
chmod 777 .
singularity build --fakeroot Singularity.sif Singularity
- name: Source Biodynamo and run demo...
run: |
singularity exec --cleanenv -i Singularity.sif bash -c "source /biodynamo/build/third_party/root/bin/thisroot.sh && source /biodynamo/build/bin/thisbdm.sh && \
export DISPLAY=:99.0 && /biodynamo/util/xvfb-initd.sh start && cd $(mktemp -d) && bdm demo tumor_concept && cd tumor_concept && bdm clean && bdm run"
118 changes: 36 additions & 82 deletions Singularity
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@
Bootstrap:docker
From:ubuntu:18.04
From:ubuntu:20.04

%environment

%post -c /bin/bash

export DEBIAN_FRONTEND=noninteractive
export TZ=Europe/Berlin
unset Qt5_DIR
unset ParaView_DIR
unset ROOT_INCLUDE_PATH
unset CMAKE_PREFIX_PATH
unset PYENV_ROOT
unset BDMSYS
unset CC
unset CXX

apt-get -y update &&
apt-get -y install python &&
apt-get -y install python3 &&
apt-get -y install git &&
apt-get -y install curl &&
apt-get -y install make &&
apt-get -y install gcc &&
apt-get -y install g++ &&
apt-get -y install wget &&
apt-get -y install wamerican &&
apt-get -y install libffi-dev &&
apt-get -y install libncurses5-dev &&
apt-get -y install zlib1g &&
apt-get -y install zlib1g-dev &&
apt-get -y install bzip2 &&
apt-get -y install zlib1g-dev &&
apt-get -y install aptitude &&
aptitude -y install libreadline-dev &&
apt-get -y install libssl-dev &&
apt-get -y install libsqlite3-dev &&
apt-get -y install apt-utils &&
apt-get -y install openmpi-bin &&
apt-get -y install libopenmpi-dev &&
apt-get -y install libxkbcommon-x11-dev &&
apt-get -y install bsdmainutils &&
apt-get -y install clang &&
apt-get -y install clang-format &&
apt-get -y install clang-tidy &&
apt-get -y install doxygen &&
apt-get -y install graphviz &&
apt-get -y install libxml2-dev &&
apt-get -y install llvm-7 &&
apt-get -y install llvm-7-dev &&
apt-get -y install llvm-7-runtime &&
apt-get -y install valgrind &&
apt-get -y install libgsl-dev &&
apt-get -y install freeglut3-dev &&
apt-get -y install libbz2-dev &&
apt-get -y install libnuma-dev &&
apt-get -y install libomp5 &&
apt-get -y install libomp-dev &&
apt-get -y install libopenmpi-dev &&
apt-get -y install libpthread-stubs0-dev &&
apt-get -y install zlib1g-dev &&
apt-get -y install libbz2-dev &&
apt-get -y install libffi-dev &&
apt-get -y install liblzma-dev &&
apt-get -y install libreadline-dev &&
apt-get -y install libsqlite3-dev &&
apt-get -y install libssl-dev &&
apt-get -y install python-openssl &&
apt-get -y install tk-dev &&
apt-get -y install xz-utils &&
apt-get -y install zlib1g-dev &&
apt-get -y install sudo &&
apt-get -y install software-properties-common

apt-get -y install locales locales-all
apt-get -y update
apt-get -y install apt-utils
apt-get -y install software-properties-common
apt-get -y install python python3 git curl make gcc g++ wget wamerican wget wamerican libffi-dev libncurses5-dev zlib1g zlib1g-dev bzip2 aptitude libreadline-dev libssl-dev libsqlite3-dev \
openmpi-bin libopenmpi-dev libxkbcommon-x11-dev bsdmainutils clang clang-format clang-tidy doxygen graphviz libxml2-dev llvm-7 llvm-7-dev llvm-7-runtime valgrind libgsl-dev freeglut3-dev \
libbz2-dev libnuma-dev libomp5 libomp-dev libopenmpi-dev libpthread-stubs0-dev zlib1g-dev libbz2-dev libffi-dev liblzma-dev libreadline-dev libsqlite3-dev libssl-dev python-openssl tk-dev \
xz-utils zlib1g-dev sudo libblas-dev liblapack-dev nano locales locales-all ninja-build python3-pip freeglut3-dev valgrind xvfb

dpkg-reconfigure locales
locale-gen

Expand All @@ -76,46 +35,41 @@ From:ubuntu:18.04
export PATH="/miniconda3/bin:$PATH"
conda install -y -c conda-forge pip numpy
conda update -y --all
apt -y install git
apt -y install curl
sudo rm -rf ~/.pyenv
curl https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"
eval "$(pyenv init -)"

export PYENV_ROOT="/opt/pyenv"
export PATH="/opt/pyenv/bin:$PATH"
export PYENV_ROOT="/opt/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.9.1
export PATH="/opt/pyenv/versions/3.9.1/bin:$PATH"
export PATH="/opt/pyenv/versions/3.9.1/bin/:$PATH"
echo 'export PATH="/opt/.pyenv/versions/3.9.1/bin/:$PATH"' >> $SINGULARITY_ENVIRONMENT
export PATH="/opt/.pyenv/versions/3.9.1/bin/:$PATH"

pyenv shell 3.9.1

wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
python3 -m pip install -U pip
python3 -m pip install --upgrade pip
python3 -m pip install numpy
apt-get install -y python3-pip
apt-get install -y freeglut3-dev valgrind

pip install cmake --upgrade
pyenv global 3.9.1

apt-get -y dist-upgrade
sudo apt-get -y install ninja-build
git config --system user.name "Test User"
git config --system user.email [email protected]

export BDM_BRANCH="master"
git clone https://github.com/BioDynaMo/biodynamo.git
cd biodynamo
export SILENT_INSTALL=1
./prerequisites.sh all
cd biodynamo
git checkout $BDM_BRANCH

cmake -G Ninja \
-Dparaview=OFF \
-DCMAKE_BUILD_TYPE=Release \
-B build
mkdir build
cd build

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..

ninja -j $(($(nproc) - 1))

cmake --build build --parallel

%runscript
10 changes: 8 additions & 2 deletions cmake/env/thisbdm.fish
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ function source_thisbdm

set -pgx PATH "$PYENV_ROOT/bin"

pyenv init --path | source; or return 1
pyenv init - | source; or return 1
# Rehashing is not possible within a read-only Singularity container
# and will cause sourcing of thisbdm to get stuck
if test -n "$SINGULARITY_CONTAINER"
set PYENV_NO_REHASH "--no-rehash"
end

pyenv init --path $PYENV_NO_REHASH | source; or return 1
pyenv init - $PYENV_NO_REHASH | source; or return 1
pyenv shell @pythonvers@; or return 1

# Location of jupyter executable (installed with `pip install` command)
Expand Down
10 changes: 8 additions & 2 deletions cmake/env/thisbdm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,14 @@ _source_thisbdm()
fi
export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init --path)" || return 1
eval "$(pyenv init -)" || return 1
# Rehashing is not possible within a read-only Singularity container
# and will cause sourcing of thisbdm to get stuck
if [ -n "$SINGULARITY_CONTAINER" ]; then
PYENV_NO_REHASH="--no-rehash"
fi

eval "$(pyenv init --path $PYENV_NO_REHASH)" || return 1
eval "$(pyenv init - $PYENV_NO_REHASH)" || return 1
pyenv shell @pythonvers@ || return 1

# Location of jupyter executable (installed with `pip install` command)
Expand Down
21 changes: 19 additions & 2 deletions doc/user_guide/Singularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ sudo singularity build Singularity.sif Singularity
```
Then simply run the BioDynaMo singularity container using:
```bash
singularity run Singularity.sif
singularity run --cleanenv Singularity.sif
```
where the ``--cleanenv`` option clears out all the environment variables set in the host machine to avoid conflicts.

Once the container is running we can source Root and the BioDynaMo environment:
```bash
source /biodynamo/build/third_party/root/bin/thisroot.sh
```
```bash
source /biodynamo/build/bin/thisbdm.sh
```
## Method 2, Export image from local PC to HPC.
If you cannot utilise either sudo or fakeroot on the HPC, we can instead build the BioDynaMo image on our local PC and export the image.
Expand All @@ -66,9 +75,17 @@ scp [user@]SRC_LOCALPC/SingularityFileLocation:]Singularity.sif ~/
```
Finally we once again run the Singularity image on the HPC:
```bash
singularity run Singularity.sif
singularity run --cleanenv Singularity.sif
```
where the ``--cleanenv`` option clears out all the environment variables set in the host machine to avoid conflicts.

Once the container is running we can source Root and the BioDynaMo environment:
```bash
source /biodynamo/build/third_party/root/bin/thisroot.sh
```
```bash
source /biodynamo/build/bin/thisbdm.sh
```
If you wish to read further about Singularity, you can find a substantial amount of information on the
singularity home website: https://sylabs.io/guides/3.5/user-guide/introduction.html. Including many tutorials and more
complex use cases.
Expand Down

0 comments on commit 2bd8613

Please sign in to comment.