diff --git a/stack/base/Dockerfile b/stack/base/Dockerfile index 1af8ea59..975c880a 100644 --- a/stack/base/Dockerfile +++ b/stack/base/Dockerfile @@ -32,7 +32,7 @@ RUN mkdir -p "${CONDA_DIR}/etc/conda/activate.d" && \ # Configure AiiDA profile. COPY config-quick-setup.yaml . -COPY before-notebook.d/prepare-aiida.sh /usr/local/bin/before-notebook.d/ +COPY before-notebook.d/* /usr/local/bin/before-notebook.d/ # Configure AiiDA. ENV SETUP_DEFAULT_AIIDA_PROFILE true @@ -42,10 +42,16 @@ ENV AIIDA_USER_FIRST_NAME Giuseppe ENV AIIDA_USER_LAST_NAME Verdi ENV AIIDA_USER_INSTITUTION Khedivial +# Install the load-singlesshagent.sh script as described here: +# https://aiida.readthedocs.io/projects/aiida-core/en/v2.0.0/howto/ssh.html#starting-the-ssh-agent +# The startup of this script is configured in the before-notebook.d/setup-ssh.sh file. +RUN wget --quiet --directory-prefix=/opt/bin/ \ + "https://aiida.readthedocs.io/projects/aiida-core/en/v${AIIDA_VERSION}/_downloads/4265ec5a42c3a3dba586dd460c0db95e/load-singlesshagent.sh" \ + && echo $'\n# Load singlesshagent on shell startup.\n\ +if [ -f /opt/bin/load-singlesshagent.sh ]; then\n\ + . /opt/bin/load-singlesshagent.sh\n\ +fi\n' >> "/home/${NB_USER}/.bashrc" + USER ${NB_USER} WORKDIR "/home/${NB_USER}" - -# Make sure that the known_hosts file is present inside the .ssh folder. -RUN mkdir -p --mode=0700 /home/${NB_USER}/.ssh && \ - touch /home/${NB_USER}/.ssh/known_hosts diff --git a/stack/base/before-notebook.d/setup-ssh.sh b/stack/base/before-notebook.d/setup-ssh.sh new file mode 100755 index 00000000..00bc4a02 --- /dev/null +++ b/stack/base/before-notebook.d/setup-ssh.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Make sure that the known_hosts file is present inside the .ssh folder. +mkdir -p --mode=0700 /home/${NB_USER}/.ssh && \ + touch /home/${NB_USER}/.ssh/known_hosts + + +if [[ ! -f /home/${NB_USER}/.ssh/id_rsa ]]; then + # Generate ssh key that works with `paramiko` + # See: https://aiida.readthedocs.io/projects/aiida-core/en/latest/get_started/computers.html#remote-computer-requirements + ssh-keygen -f /home/${NB_USER}/.ssh/id_rsa -t rsa -b 4096 -m PEM -N '' +fi + +# Start the ssh-agent. +eval `ssh-agent` diff --git a/stack/lab/before-notebook.d/prepare-aiidalab.sh b/stack/lab/before-notebook.d/prepare-aiidalab.sh index 66766e76..76f83cab 100755 --- a/stack/lab/before-notebook.d/prepare-aiidalab.sh +++ b/stack/lab/before-notebook.d/prepare-aiidalab.sh @@ -11,12 +11,6 @@ if [ -L /home/${NB_USER}/${NB_USER} ]; then rm /home/${NB_USER}/${NB_USER} fi -if [[ ! -f /home/${NB_USER}/.ssh/id_rsa ]]; then - # Generate ssh key that works with `paramiko` - # See: https://aiida.readthedocs.io/projects/aiida-core/en/latest/get_started/computers.html#remote-computer-requirements - ssh-keygen -f /home/${NB_USER}/.ssh/id_rsa -t rsa -b 4096 -m PEM -N '' -fi - # Install the home app. if [ ! -e /home/${NB_USER}/apps/home ]; then echo "Install home app."