-
Eleni Mathioulaki authored
Script fixes See merge request technical-coordination/project-internal/devops/platform/ebrains-spack-builds!203
184c8f42
Forked from
EBRAINS RI / Tech Hub / Platform / EBRAINS Software Distribution / ebrains-spack-builds
1098 commits behind the upstream repository.
create_JupyterLab_kernel.sh 2.79 KiB
#!/bin/bash
# ===========================================================================================================
# title : create_JupyterLab_kernel.sh
# usage : ./create_JupyterLab_kernel.sh $INSTALLATION_ROOT $EBRAINS_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.
# ===========================================================================================================
INSTALLATION_ROOT=$1
EBRAINS_SPACK_ENV=$2
RELEASE_NAME=$3
LAB_KERNEL_ROOT=$4
# enable modules
source /usr/share/modules/init/sh
# capture the empty env
cd ~
env >> /tmp/before.txt
# 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
# spack env activate $EBRAINS_SPACK_ENV
# load modules
module use $INSTALLATION_ROOT/spack/share/spack/modules/linux-ubuntu20.04-x86_64/
source $INSTALLATION_ROOT/spack/var/spack/environments/$EBRAINS_SPACK_ENV/loads
# also add 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
# and 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
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
# prepare the env file required for the JupyterLab kernel
mkdir -p $KERNEL_PATH/bin
# start of env creation
cat <<EOF > $KERNEL_PATH/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' >> $KERNEL_PATH/bin/env.sh
# end of env creation
cat <<EOF >>$KERNEL_PATH/bin/env.sh
python -m ipykernel_launcher -f \$@
EOF
chmod +x $KERNEL_PATH/bin/env.sh
# create the new kernel's configuration file
mkdir -p $KERNEL_PATH/$KERNEL_NAME
cat <<EOF >$KERNEL_PATH/$KERNEL_NAME/kernel.json
{
"argv": ["$KERNEL_PATH/bin/env.sh", "{connection_file}", "--profile=default"],
"display_name": "$RELEASE_NAME",
"name": "$KERNEL_NAME",
"language": "python",
"env": { "LAB_KERNEL_NAME": "$RELEASE_NAME", "LAB_KERNEL_RELEASE_DATE": "$(date +"%Y-%m-%d")" }
}
EOF
# add EBRAINS logo to kernel
cp $LAB_KERNEL_ROOT/../logo/logo-64x64.png $KERNEL_PATH/$KERNEL_NAME/