From 9cd40da8907bac9c2b637efb4a5b4f1ae46aaa01 Mon Sep 17 00:00:00 2001
From: Christof Kaufmann <christof.kaufmann@hs-bochum.de>
Date: Mon, 13 Jan 2025 17:16:06 +0100
Subject: [PATCH] Workaround missing `mamba init --system` cmd

---
 keras3-cpu/Dockerfile  |  4 ++--
 keras3-cpu/conda.sh    | 18 ++++++++++++++++++
 keras3-gpu/Dockerfile  |  4 ++--
 keras3-gpu/conda.sh    | 18 ++++++++++++++++++
 pytorch-gpu/Dockerfile |  4 ++--
 pytorch-gpu/conda.sh   | 18 ++++++++++++++++++
 6 files changed, 60 insertions(+), 6 deletions(-)
 create mode 100644 keras3-cpu/conda.sh
 create mode 100644 keras3-gpu/conda.sh
 create mode 100644 pytorch-gpu/conda.sh

diff --git a/keras3-cpu/Dockerfile b/keras3-cpu/Dockerfile
index b5e977d..92597b3 100644
--- a/keras3-cpu/Dockerfile
+++ b/keras3-cpu/Dockerfile
@@ -149,6 +149,8 @@ USER root
 # activate extensions by default
 COPY plugin.jupyterlab-settings "/home/${NB_USER}/.jupyter/lab/user-settings/@jupyterlab/extensionmanager-extension/"
 COPY plugin.jupyterlab-settings "/home/${NB_USER}/.jupyter/lab/user-settings/@jupyter-server/resource-usage/"
+# source mamba.sh in bash using /etc/profile.d/conda.sh (workaround for removed mamba init --system, see https://github.com/mamba-org/mamba/issues/3691)
+COPY conda.sh "/etc/profile.d/"
 RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
     # history search with Page Up/Down
     sed -i "s/^# \(.*history-search.*\)/\1/" /etc/inputrc && \
@@ -174,8 +176,6 @@ RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
            '  fi' \
            'done' \
            >> /usr/local/bin/start-notebook.d/fix-gitlab-server.sh && \
-    # source mamba.sh in bash using /etc/profile.d/conda.sh
-    mamba init --system && \
     chown -R ${NB_USER} "/home/${NB_USER}/.local" && \
     fix-permissions "/home/${NB_USER}" && \
     fix-permissions "/etc/skel"
diff --git a/keras3-cpu/conda.sh b/keras3-cpu/conda.sh
new file mode 100644
index 0000000..824b6ce
--- /dev/null
+++ b/keras3-cpu/conda.sh
@@ -0,0 +1,18 @@
+# >>> conda initialize >>>
+# !! Contents within this block are managed by 'conda init' !!
+__conda_setup="$('/opt/conda/bin/conda' 'shell.posix' 'hook' 2> /dev/null)"
+if [ $? -eq 0 ]; then
+    eval "$__conda_setup"
+else
+    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
+        . "/opt/conda/etc/profile.d/conda.sh"
+    else
+        export PATH="/opt/conda/bin:$PATH"
+    fi
+fi
+unset __conda_setup
+
+if [ -f "/opt/conda/etc/profile.d/mamba.sh" ]; then
+    . "/opt/conda/etc/profile.d/mamba.sh"
+fi
+# <<< conda initialize <<<
diff --git a/keras3-gpu/Dockerfile b/keras3-gpu/Dockerfile
index a1f83e1..5552230 100644
--- a/keras3-gpu/Dockerfile
+++ b/keras3-gpu/Dockerfile
@@ -110,6 +110,8 @@ RUN pip install --no-cache-dir \
 USER root
 # activate extensions by default
 COPY plugin.jupyterlab-settings "/home/${NB_USER}/.jupyter/lab/user-settings/@jupyterlab/extensionmanager-extension/"
+# source mamba.sh in bash using /etc/profile.d/conda.sh (workaround for removed mamba init --system, see https://github.com/mamba-org/mamba/issues/3691)
+COPY conda.sh "/etc/profile.d/"
 RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
     # history search with Page Up/Down
     sed -i "s/^# \(.*history-search.*\)/\1/" /etc/inputrc && \
@@ -135,8 +137,6 @@ RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
            '  fi' \
            'done' \
            >> /usr/local/bin/start-notebook.d/fix-gitlab-server.sh && \
-    # source mamba.sh in bash using /etc/profile.d/conda.sh
-    mamba init --system && \
     chown -R ${NB_USER} "/home/${NB_USER}/.local" && \
     fix-permissions "/home/${NB_USER}" && \
     fix-permissions "/etc/skel"
diff --git a/keras3-gpu/conda.sh b/keras3-gpu/conda.sh
new file mode 100644
index 0000000..824b6ce
--- /dev/null
+++ b/keras3-gpu/conda.sh
@@ -0,0 +1,18 @@
+# >>> conda initialize >>>
+# !! Contents within this block are managed by 'conda init' !!
+__conda_setup="$('/opt/conda/bin/conda' 'shell.posix' 'hook' 2> /dev/null)"
+if [ $? -eq 0 ]; then
+    eval "$__conda_setup"
+else
+    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
+        . "/opt/conda/etc/profile.d/conda.sh"
+    else
+        export PATH="/opt/conda/bin:$PATH"
+    fi
+fi
+unset __conda_setup
+
+if [ -f "/opt/conda/etc/profile.d/mamba.sh" ]; then
+    . "/opt/conda/etc/profile.d/mamba.sh"
+fi
+# <<< conda initialize <<<
diff --git a/pytorch-gpu/Dockerfile b/pytorch-gpu/Dockerfile
index 479c01e..6c9fd71 100644
--- a/pytorch-gpu/Dockerfile
+++ b/pytorch-gpu/Dockerfile
@@ -110,6 +110,8 @@ RUN conda install --yes --no-update-deps \
 USER root
 # activate extensions by default
 COPY plugin.jupyterlab-settings "/home/${NB_USER}/.jupyter/lab/user-settings/@jupyterlab/extensionmanager-extension/"
+# source mamba.sh in bash using /etc/profile.d/conda.sh (workaround for removed mamba init --system, see https://github.com/mamba-org/mamba/issues/3691)
+COPY conda.sh "/etc/profile.d/"
 RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
     # history search with Page Up/Down
     sed -i "s/^# \(.*history-search.*\)/\1/" /etc/inputrc && \
@@ -135,8 +137,6 @@ RUN chown -R ${NB_USER} "/home/${NB_USER}/.jupyter" && \
            '  fi' \
            'done' \
            >> /usr/local/bin/start-notebook.d/fix-gitlab-server.sh && \
-    # source mamba.sh in bash using /etc/profile.d/conda.sh
-    mamba init --system && \
     chown -R ${NB_USER} "/home/${NB_USER}/.local" && \
     fix-permissions "/home/${NB_USER}" && \
     fix-permissions "/etc/skel"
diff --git a/pytorch-gpu/conda.sh b/pytorch-gpu/conda.sh
new file mode 100644
index 0000000..824b6ce
--- /dev/null
+++ b/pytorch-gpu/conda.sh
@@ -0,0 +1,18 @@
+# >>> conda initialize >>>
+# !! Contents within this block are managed by 'conda init' !!
+__conda_setup="$('/opt/conda/bin/conda' 'shell.posix' 'hook' 2> /dev/null)"
+if [ $? -eq 0 ]; then
+    eval "$__conda_setup"
+else
+    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
+        . "/opt/conda/etc/profile.d/conda.sh"
+    else
+        export PATH="/opt/conda/bin:$PATH"
+    fi
+fi
+unset __conda_setup
+
+if [ -f "/opt/conda/etc/profile.d/mamba.sh" ]; then
+    . "/opt/conda/etc/profile.d/mamba.sh"
+fi
+# <<< conda initialize <<<
-- 
GitLab