Skip to content

Commit

Permalink
add correct handling of apptainer
Browse files Browse the repository at this point in the history
  • Loading branch information
stebo85 committed Nov 13, 2023
1 parent 404bbb4 commit 11e5277
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions run_transparent_singularity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,27 @@ singularity exec $singularity_opts --pwd $_base $container $_base/ts_binaryFinde
echo "create singularity executable for each regular executable in commands.txt"
# $@ parses command line options.
#test executable="fslmaths"
singularity_version=$(singularity version | cut -d'-' -f1)

# The --env option requires singularity > 3.6 or apptainer. Test here:
required_version="3.6"
if which apptainer >/dev/null 2>&1; then
echo "Apptainer is installed."
singularity_version=3.6
else
echo "Apptainer is not installed. Testing for singularity version."
singularity_version=$(singularity version | cut -d'-' -f1)
fi

while read executable; do \
echo $executable > $_base/${executable}; \
echo "#!/usr/bin/env bash" > $executable
echo "export PWD=\`pwd -P\`" >> $executable

# neurodesk_singularity_opts is a global variable that can be set in neurodesk for example --nv for gpu support
# --silent is required to suppress bind mound warnings (e.g. for /etc/localtime)
# --cleanenv is required to prevent environment variables on the host to affect the containers (e.g. Julia and R packages), but to work
# correctly with GUIs, the DISPLAY variable needs to be set as well. This only works in singularity >= 3.6.0

if printf '%s\n' "$required_version" "$singularity_version" | sort -V | head -n1 | grep -q "$required_version"; then
echo "Singularity version is equal to or newer than $required_version. All features should work."
echo "singularity --silent exec --cleanenv --env DISPLAY=\$DISPLAY \$neurodesk_singularity_opts --pwd \$PWD $_base/$container $executable \"\$@\"" >> $executable
else
echo "Singularity version is older than $required_version. GUIs will not work correctly!"
Expand Down

0 comments on commit 11e5277

Please sign in to comment.