Newer
Older
Athanasios Karmas
committed
#!/bin/bash
# ===========================================================================================================
# title : create_JupyterLab_kernel.sh
# usage : ./create_JupyterLab_kernel.sh $INSTALLATION_ROOT $SPACK_ENV $RELEASE_NAME $LAB_KERNEL_ROOT
# description : creates a spackified JupyterLab kernel conf and places it to the NFS where it can be
# loaded by all users.
# ===========================================================================================================
Athanasios Karmas
committed
INSTALLATION_ROOT=$1
Athanasios Karmas
committed
Athanasios Karmas
committed
# capture the empty env
Athanasios Karmas
committed
# load spack
export SPACK_USER_CACHE_PATH=$INSTALLATION_ROOT/spack/.spack
export SPACK_USER_CONFIG_PATH=$INSTALLATION_ROOT/spack/.spack
source $INSTALLATION_ROOT/spack/share/spack/setup-env.sh
# no need to activate as the env is already activated in the context it is used
Athanasios Karmas
committed
module use $INSTALLATION_ROOT/spack/share/spack/modules/linux-ubuntu20.04-x86_64/
source $INSTALLATION_ROOT/spack/var/spack/environments/$SPACK_ENV/loads
# also add user's .local python3.8 packages to allow package installation at runtime by the user using pip
Athanasios Karmas
committed
export PYTHONPATH=$PYTHONPATH:/opt/app-root/src/.local/lib/python3.8/site-packages
export PATH=$PATH:/opt/app-root/src/.local/bin
# and python modules installed in the base docker Collab image
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/dist-packages
Athanasios Karmas
committed
Athanasios Karmas
committed
# capture the env after spack activation
cd ~
env >> /tmp/after.txt
# kernel name is lowercase release name
KERNEL_NAME=$(echo "$RELEASE_NAME" | tr '[:upper:]' '[:lower:]')
# kernel dir is a directory inside LAB_KERNEL_ROOT named after the kernel
KERNEL_PATH=$LAB_KERNEL_ROOT/$KERNEL_NAME
Athanasios Karmas
committed
# prepare the env file required for the JupyterLab kernel
Athanasios Karmas
committed
#!/usr/bin/env bash
set -euxo pipefail
EOF
Athanasios Karmas
committed
# 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' >> $KERNEL_PATH/bin/env.sh
Athanasios Karmas
committed
# end of env creation
Athanasios Karmas
committed
python -m ipykernel_launcher -f \$@
EOF
Athanasios Karmas
committed
# create the new kernel's configuration file
mkdir -p $KERNEL_PATH/$KERNEL_NAME
cat <<EOF >$KERNEL_PATH/$KERNEL_NAME/kernel.json
Athanasios Karmas
committed
{
"argv": ["$KERNEL_PATH/bin/env.sh", "{connection_file}", "--profile=default"],
"language": "python",
"env": { "LAB_KERNEL_NAME": "$RELEASE_NAME", "LAB_KERNEL_RELEASE_DATE": "$(date +"%Y-%m-%d")" }