If I create a new user in JupyterHub I want that the working directory of the corresponding JupyterLab instance is initialized with some getting started examples:
The Spawner provides some hook functions in the configuration file jupyterhub_config.py
. And its possible to get the current user name from within the hook function.
import subprocess
def git(*args):
return subprocess.check_call(['git'] + list(args))
def init_working_directory(spawner):
username = spawner.user.name
git_source = 'https://$user:$password@gitlab.server.de/my/project'
target_folder = '/home/' + username + '/GettingStarted'
git('clone', git_source, target_folder)
c.Spawner.pre_spawn_hook = init_working_directory
There are a few issues left:
a) The git clone command only works the first time, when the folder /home/username/GettingStarted does not yet exist.
b) There is no progress bar shown during the delayed log and the git clone command takes a while.
c) Git password might be shown in error messages/console.
Therefore, I will initially do the git clone when creating my Docker container and only perform a local copy in pre_spawn_hook if the GettingStarted folder does not yet exist.