Skip to content

Instantly share code, notes, and snippets.

@danielballan
Last active May 12, 2020 02:12
Show Gist options
  • Save danielballan/590475a2d0ea7c4638057e4d53418e24 to your computer and use it in GitHub Desktop.
Save danielballan/590475a2d0ea7c4638057e4d53418e24 to your computer and use it in GitHub Desktop.
Container Builder for NSLS-II JupyterHub at SDCC

Initial setup of Docker worker VM

Start the Docker daemon and a local Docker registry.

sudo systemctl start docker
sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2

Place repo2singularity (see file in this gist) in /usr/bin/ or somewhere on the PATH.

Build a Singularity image from a Binder-compatible repo

Clone the Binder-compatible repo and

git clone REPO_URL REPO_DIRECTORY
repo2singularity REPO_DIRECTORY IMAGE_NAME

This generates a .sif file in /tmp/sifs. Copy it to nslshub01.

scp /tmp/sifs/IMAGE_NAME nslshub01:/srv/jupyter/scontainers_available/

Make it available to users

On nslshub01, create a soft link targeting /srv/jupyter/scontainers_available/ from /srv/jupyter/scontainers/.

ln -s -T /srv/jupyter/scontainers_available/NAME /srv/jupyter/scontainers/NAME
#!/bin/bash
set -e
INTERMEDIATE_IMAGE_NAME=$(uuidgen)
FINAL_IMAGE_NAME=$(basename $2)
python3 -m repo2docker --user-id 1000 --user-name jovyan --image-name $INTERMEDIATE_IMAGE_NAME --no-run $1
# Make software area world-writable. It will be owned by jovyan,
# but the system user who runs it will be after to write to it
# via a tmpfs overlay.
echo "Making software area world-writable..." 1>&2
docker run --cidfile=/tmp/cidfile-$INTERMEDIATE_IMAGE_NAME -it $INTERMEDIATE_IMAGE_NAME chmod a+rw -R /srv/conda/ /srv/npm /home/jovyan
docker commit `cat /tmp/cidfile-$INTERMEDIATE_IMAGE_NAME` localhost:5000/$FINAL_IMAGE_NAME
docker push localhost:5000/$FINAL_IMAGE_NAME
mkdir -p /tmp/sifs
SINGULARITY_NOHTTPS=1 singularity build /tmp/sifs/$FINAL_IMAGE_NAME.sif docker://localhost:5000/$FINAL_IMAGE_NAME
@gwbischof
Copy link

For this to work singularity needs to be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment