Select Git revision
event_queue.hpp
create_JupyterLab_kernel.sh 2.68 KiB
#!/bin/bash
#title :create_JupyterLab_kernel.sh
#description :Script to create a spackified JupyterLab kernel conf and place it to NFS where it can be loaded by all users.
#usage :./create_JupyterLab_kernel.sh $INSTALLATION_ROOT $ENV $RELEASE_NAME $LAB_KERNEL_PATH
#==============================================================================
INSTALLATION_ROOT=$1
SPACKIFIED_ENV=$2
RELEASE_NAME=$3
LAB_KERNEL_PATH=$4
# capture the empty env
cd ~
env >> /tmp/before.txt
# load spack, spack repos and spack env
export SPACK_USER_CACHE_PATH=/srv/$INSTALLATION_ROOT/spack/.spack
export SPACK_USER_CONFIG_PATH=/srv/$INSTALLATION_ROOT/spack/.spack
source /srv/$INSTALLATION_ROOT/spack/share/spack/setup-env.sh
# this shouldn't be needed:
spack repo add /srv/$INSTALLATION_ROOT/ebrains-spack-builds
# no need to activate as the env is already activated in the context it is used
#spack env activate $SPACKIFIED_ENV
source /usr/share/modules/init/sh
module use /srv/$INSTALLATION_ROOT/spack/share/spack/modules/linux-ubuntu20.04-x86_64/
source /srv/$INSTALLATION_ROOT/spack/var/spack/environments/$SPACKIFIED_ENV/loads
# add also user's .local python3.8 packages to allow package installation at runtime by the user using pip
export PYTHONPATH=$PYTHONPATH:/opt/app-root/src/.local/lib/python3.8/site-packages
export PATH=$PATH:/opt/app-root/src/.local/bin
# export also python modules installed in the base docker Collab image
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/dist-packages
# capture the env after spack activation
cd ~
env >> /tmp/after.txt
# kernel name is lowercase release name
LAB_KERNEL_NAME=$(echo "$RELEASE_NAME" | tr '[:upper:]' '[:lower:]')
# kernel dir is a directory inside LAB_KERNEL_PATH named after the kernel
LAB_KERNEL_DIR=$LAB_KERNEL_PATH/$LAB_KERNEL_NAME
# prepare the env file required for the JupyterLab kernel
mkdir -p $LAB_KERNEL_DIR/bin
# start of env creation
cat <<EOF > $LAB_KERNEL_DIR/bin/env.sh
#!/usr/bin/env bash
set -euxo pipefail
EOF
# append the necessary env variables for spack env and tools
diff /tmp/before.txt /tmp/after.txt|grep ">"|cut -c 3- |awk '$0="export "$0' >> $LAB_KERNEL_DIR/bin/env.sh
# end of env creation
cat <<EOF >>$LAB_KERNEL_DIR/bin/env.sh
python -m ipykernel_launcher -f \$@
EOF
chmod +x $LAB_KERNEL_DIR/bin/env.sh
# create the new kernel's configuration file
mkdir -p $LAB_KERNEL_DIR/$LAB_KERNEL_NAME
cat <<EOF >$LAB_KERNEL_DIR/$LAB_KERNEL_NAME/kernel.json
{
"argv": ["$LAB_KERNEL_DIR/bin/env.sh", "{connection_file}", "--profile=default"],
"display_name": "RELEASE_NAME",
"name": "$LAB_KERNEL_NAME",
"language": "python",
"env": { "LAB_KERNEL_NAME": "$RELEASE_NAME", "LAB_KERNEL_RELEASE_DATE": "$(date +"%Y-%m-%d")" }
}
EOF