From ff746f691d1c105bc512ec7ea57047432289c7bf Mon Sep 17 00:00:00 2001 From: Chris Ostrouchov Date: Thu, 3 Mar 2022 23:22:09 -0500 Subject: [PATCH] Adding skel to user directories --- qhub/template/image/jupyterlab/postBuild | 4 +--- .../jupyterhub/files/jupyterhub/03-profiles.py | 16 +++++++++++++--- .../services/jupyterhub/files/skel/.bash_logout | 3 +++ .../services/jupyterhub/files/skel/.bashrc | 3 +++ .../services/jupyterhub/files/skel/.profile | 3 +++ .../kubernetes/services/jupyterhub/main.tf | 4 ++++ 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/qhub/template/image/jupyterlab/postBuild b/qhub/template/image/jupyterlab/postBuild index 683f35f59a..510ba4d3fe 100755 --- a/qhub/template/image/jupyterlab/postBuild +++ b/qhub/template/image/jupyterlab/postBuild @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -euo pipefail set -x + # install classic notebook extensions jupyter nbextension enable --py widgetsnbextension --sys-prefix @@ -8,9 +9,6 @@ jupyter nbextension enable --py widgetsnbextension --sys-prefix mkdir -p /opt/conda/share/jupyter/lab/settings cp /opt/jupyterlab/overrides.json /opt/conda/share/jupyter/lab/settings -# ====== fix perms ====== -fix-permissions /opt/jupyterlab /etc/ipython - # if DEFAULT_ENV is unset ${DEFAULT_ENV+x} expands to nothing otherwise # it substitutes the string x. This allows us to check if the variable # is set without triggering an unbound variable error diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py index 34e52aa1fd..b10520b326 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py @@ -15,6 +15,7 @@ def base_profile_home_mounts(username): """ home_pvc_name = z2jh.get_config("custom.home-pvc") + skel_mount = z2jh.get_config("custom.skel-mount") pvc_home_mount_path = "home/{username}" pod_home_mount_path = "/home/{username}" @@ -25,6 +26,12 @@ def base_profile_home_mounts(username): "persistentVolumeClaim": { "claimName": home_pvc_name, }, + }, + { + "name": "skel", + "configMap": { + "name": skel_mount["name"], + } } ] } @@ -35,11 +42,11 @@ def base_profile_home_mounts(username): "mountPath": pod_home_mount_path.format(username=username), "name": "home", "subPath": pvc_home_mount_path.format(username=username), - } + }, ] } - MKDIR_OWN_DIRECTORY = "mkdir -p /mnt/{path} && chmod 777 /mnt/{path}" + MKDIR_OWN_DIRECTORY = "mkdir -p /mnt/{path} && chmod 777 /mnt/{path} && cp -r /etc/skel/. /mnt/{path}" command = MKDIR_OWN_DIRECTORY.format( path=pvc_home_mount_path.format(username=username) ) @@ -49,7 +56,10 @@ def base_profile_home_mounts(username): "image": "busybox:1.31", "command": ["sh", "-c", command], "securityContext": {"runAsUser": 0}, - "volumeMounts": [{"mountPath": "/mnt", "name": "home"}], + "volumeMounts": [ + {"mountPath": "/mnt", "name": "home"}, + {"mountPath": "/etc/skel", "name": "skel"}, + ], } ] return { diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bash_logout b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bash_logout index de4f5f75d7..cbb7e07d51 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bash_logout +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bash_logout @@ -1,3 +1,6 @@ +################################################################### +# Managed by QHub # +################################################################### # ~/.bash_logout: executed by bash(1) when login shell exits. # when leaving the console clear the screen to increase privacy diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bashrc b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bashrc index 408a2db0ca..3d247ed87e 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bashrc +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.bashrc @@ -1,3 +1,6 @@ +################################################################### +# Managed by QHub # +################################################################### # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.profile b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.profile index e5b117332e..560bac09b8 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.profile +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/skel/.profile @@ -1,3 +1,6 @@ +################################################################### +# Managed by QHub # +################################################################### # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/main.tf b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/main.tf index 680449138f..17f2a3ea08 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/main.tf +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/main.tf @@ -31,6 +31,10 @@ resource "helm_release" "jupyterhub" { shared-pvc = var.shared-pvc conda-store-pvc = var.conda-store-pvc conda-store-mount = var.conda-store-mount + skel-mount = { + name = kubernetes_config_map.etc-skel.metadata.0.name + namespace = kubernetes_config_map.etc-skel.metadata.0.namespace + } extra-mounts = merge( var.extra-mounts, {