Skip to content

Commit

Permalink
apply singularity -w workaround only on macos with apple silicon (and…
Browse files Browse the repository at this point in the history
… in jupyter notebooks)
  • Loading branch information
stebo85 committed Feb 28, 2025
1 parent c1ea0ce commit 44c8ea4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ ARG TOMCAT_REL="9"
ARG TOMCAT_VERSION="9.0.97"
ARG GUACAMOLE_VERSION="1.5.5"

ENV LANG ""
ENV LANGUAGE ""
ENV LC_ALL ""
ENV LANG=""
ENV LANGUAGE=""
ENV LC_ALL=""

# Install apptainer
RUN add-apt-repository -y ppa:apptainer/ppa \
Expand Down Expand Up @@ -337,7 +337,7 @@ COPY --chown=${NB_UID}:${NB_GID} ./config/lxde/libfm.conf /home/${NB_USER}/.conf
RUN touch /home/${NB_USER}/.sudo_as_admin_successful

ENV DONT_PROMPT_WSL_INSTALL=1
ENV LMOD_CMD /usr/share/lmod/lmod/libexec/lmod
ENV LMOD_CMD=/usr/share/lmod/lmod/libexec/lmod

# Add startup and config files for neurodesktop, jupyter, guacamole, vnc
RUN mkdir /home/${NB_USER}/.vnc \
Expand Down Expand Up @@ -388,8 +388,10 @@ ADD "https://api.github.com/repos/neurodesk/example-notebooks/git/refs/heads/mai
RUN rm /home/${NB_USER}/skipcache \
&& git clone --depth 1 https://github.com/NeuroDesk/example-notebooks

# Set SINGULARITY_BINDPATH and MODULEPATH here so it's available within a notebook (the startup scripts set these things too late):
# Set SINGULARITY_BINDPATH and MODULEPATH here so it's available within a notebook (the startup scripts set these things too late?):
ENV APPTAINER_BINDPATH=/data,/mnt,/neurodesktop-storage,/tmp,/cvmfs
ENV MODULEPATH=/cvmfs/neurodesk.ardc.edu.au/containers/modules/

# This workaround is currently needed for Docker on Apple silicone - they broke normal mounting of /cvmfs in the custom docker kernel. Mounting as writable works around it.
ENV neurodesk_singularity_opts=" -w "
ENV neurodesk_singularity_opts=" -w "
# It would be better not to have to set any of these variables here, but I don't know how to get them into the jupyter notebooks otherwise
9 changes: 9 additions & 0 deletions config/jupyter/environment_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@ export PATH=$PATH:/home/${NB_USER}/.local/bin:/opt/conda/bin:/opt/conda/condabin

# workaround for docker on MacOS - this -w flag should only be done when needed, because it prevents apptainer overlay bind mounts from working if they do not yet exist inside the container
# check if the user is running on MacOS with Apple Silicon through our CPU Frequency hack file /home/${NB_USER}/.local/cpuinfo_with_ARM_MHz_fix
# echo "[INFO] Checking if our CPU Frequency hack file is present to determine if we are running on MacOS with Apple Silicon to then set the -w workaround."
if [ -f ~/.local/cpuinfo_with_ARM_MHz_fix ]; then
# echo "[INFO] Detected MacOS with Apple Silicon, setting -w workaround for singularity."
export neurodesk_singularity_opts=" -w "
fi
# Test this in jupyter terminal, desktop terminal and a notebook:
# !echo $neurodesk_singularity_opts
# test if the workaround is still needed: ml fsl; fslmaths or
# import lmod
# await lmod.load('fsl/6.0.4')
# await lmod.list()
# !fslmaths

# # this adds --nv to the singularity calls -> but only if a GPU is present
# if [ "$(lspci | grep -i nvidia)" ]
Expand Down
5 changes: 3 additions & 2 deletions config/jupyter/jupyterlab_startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,23 @@ if [ ! -L "/neurocommand/local/containers" ]; then
fi

# Create a cpufino file with a valid CPU Mhz entry for ARM cpus
echo "[INFO] Checking for ARM CPU and adding a CPU Mhz entry in /proc/cpuinfo to work around a bug in Matlab that expects this value to be present."
if ! grep -iq 'cpu.*hz' /proc/cpuinfo; then
mkdir -p /home/${NB_USER}/.local
cpuinfo_file=/home/${NB_USER}/.local/cpuinfo_with_ARM_MHz_fix
cp /proc/cpuinfo $cpuinfo_file
chmod u+rw $cpuinfo_file
sed -i '/^$/c\cpu MHz : 2245.778\n' $cpuinfo_file
sudo mount --bind $cpuinfo_file /proc/cpuinfo
echo "[INFO] Added CPU Mhz entry in /proc/cpuinfo to work around a bug in Matlab that expects this value to be present."
fi

# Start and stop SSH server to initialize host
sudo service ssh restart
sudo service ssh stop


source /opt/neurodesktop/environment_variables.sh


conda init bash
mamba init bash

Expand Down

0 comments on commit 44c8ea4

Please sign in to comment.