From 44c8ea41a8cf31035acb8b29afdb979af6176c96 Mon Sep 17 00:00:00 2001 From: Steffen Bollmann Date: Fri, 28 Feb 2025 12:51:58 +1000 Subject: [PATCH] apply singularity -w workaround only on macos with apple silicon (and in jupyter notebooks) --- Dockerfile | 14 ++++++++------ config/jupyter/environment_variables.sh | 9 +++++++++ config/jupyter/jupyterlab_startup.sh | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a91186..f51875a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 \ @@ -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 " \ No newline at end of file +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 \ No newline at end of file diff --git a/config/jupyter/environment_variables.sh b/config/jupyter/environment_variables.sh index e291cab..be8851a 100644 --- a/config/jupyter/environment_variables.sh +++ b/config/jupyter/environment_variables.sh @@ -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)" ] diff --git a/config/jupyter/jupyterlab_startup.sh b/config/jupyter/jupyterlab_startup.sh index 2a666d1..e765c12 100644 --- a/config/jupyter/jupyterlab_startup.sh +++ b/config/jupyter/jupyterlab_startup.sh @@ -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