Skip to content

Commit

Permalink
Move ssh configuration into base image.
Browse files Browse the repository at this point in the history
And install the ssh-singleagent.sh script.
  • Loading branch information
csadorf committed Aug 22, 2022
1 parent 342b227 commit 323bb51
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
16 changes: 11 additions & 5 deletions stack/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 15 additions & 0 deletions stack/base/before-notebook.d/setup-ssh.sh
Original file line number Diff line number Diff line change
@@ -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`
6 changes: 0 additions & 6 deletions stack/lab/before-notebook.d/prepare-aiidalab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 323bb51

Please sign in to comment.