-
Notifications
You must be signed in to change notification settings - Fork 6
/
jupyterhub_config.py.template
139 lines (105 loc) · 5.08 KB
/
jupyterhub_config.py.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
from os.path import join
import logging
import subprocess
from dockerspawner import DockerSpawner
c = get_config() # noqa # can be called directy without import because injected by IPython
c.JupyterHub.bind_url = 'http://:8000/jupyter'
## Whether to shutdown single-user servers when the Hub shuts down.
c.JupyterHub.cleanup_servers = False
c.JupyterHub.hub_ip = 'jupyterhub'
c.JupyterHub.authenticator_class = 'jupyterhub_magpie_authenticator.MagpieAuthenticator'
c.MagpieAuthenticator.magpie_url = "http://magpie:2001"
c.JupyterHub.cookie_secret_file = '/persist/jupyterhub_cookie_secret'
c.JupyterHub.db_url = '/persist/jupyterhub.sqlite'
c.JupyterHub.template_paths = ['/custom_templates']
class CustomDockerSpawner(DockerSpawner):
def start(self):
if(os.environ['MOUNT_IMAGE_SPECIFIC_NOTEBOOKS'] == 'true'):
host_dir = join(os.environ['JUPYTERHUB_USER_DATA_DIR'], 'tutorial-notebooks-specific-images')
# Mount a volume with a tutorial-notebook subfolder corresponding to the image name, if it exists
image_name = self.user_options.get('image')
if(os.path.isdir(join(host_dir, image_name))):
self.volumes[join(host_dir, image_name)] = {
"bind": '/notebook_dir/tutorial-notebooks',
"mode": "ro"
}
else:
# Mount the entire tutorial-notebooks directory
self.volumes[join(os.environ['JUPYTERHUB_USER_DATA_DIR'], "tutorial-notebooks")] = {
"bind": "/notebook_dir/tutorial-notebooks",
"mode": "ro"
}
return super().start()
c.JupyterHub.spawner_class = CustomDockerSpawner
# Selects the first image from the list by default
c.DockerSpawner.image = os.environ['DOCKER_NOTEBOOK_IMAGES'].split()[0]
c.DockerSpawner.use_internal_ip = True
c.DockerSpawner.network_name = os.environ['DOCKER_NETWORK_NAME']
notebook_dir = '/notebook_dir'
jupyterhub_data_dir = os.environ['JUPYTERHUB_USER_DATA_DIR']
host_user_data_dir = join(jupyterhub_data_dir, "{username}")
container_workspace_dir = join(notebook_dir, "writable-workspace")
container_home_dir = join(container_workspace_dir, ".home")
c.DockerSpawner.notebook_dir = notebook_dir
c.DockerSpawner.environment = {
"HOME": container_home_dir
}
c.DockerSpawner.volumes = {host_user_data_dir: container_workspace_dir}
container_gdrive_settings_path = join(container_home_dir, ".jupyter/lab/user-settings/@jupyterlab/google-drive/drive.jupyterlab-settings")
host_gdrive_settings_path = os.environ['JUPYTER_GOOGLE_DRIVE_SETTINGS']
if len(host_gdrive_settings_path) > 0:
c.DockerSpawner.volumes[host_gdrive_settings_path] = {
"bind": container_gdrive_settings_path,
"mode": "ro"
}
readme = os.environ.get('JUPYTERHUB_README', default="")
if readme != "":
c.DockerSpawner.volumes[readme] = {
"bind": join(notebook_dir, "README.ipynb"),
"mode": "ro"
}
def create_dir_hook(spawner):
username = spawner.user.name
user_dir = join(jupyterhub_data_dir, username)
if not os.path.exists(user_dir):
os.mkdir(user_dir, 0o755)
subprocess.call(["chown", "-R", "1000:1000", user_dir])
if username == os.environ['JUPYTER_DEMO_USER']:
# Restrict resources for the public demo user
# CPU limit, seems not honored by DockerSpawner
spawner.cpu_limit = float(os.environ['JUPYTER_DEMO_USER_CPU_LIMIT'])
spawner.mem_limit = os.environ['JUPYTER_DEMO_USER_MEM_LIMIT']
c.Spawner.pre_spawn_hook = create_dir_hook
## Disable per-user configuration of single-user servers.
c.Spawner.disable_user_config = True
c.DockerSpawner.default_url = '/lab'
c.DockerSpawner.remove = True # delete containers when servers are stopped
${ENABLE_JUPYTERHUB_MULTI_NOTEBOOKS} # noqa
c.DockerSpawner.pull_policy = "always" # for images not using pinned version
c.DockerSpawner.debug = True
c.JupyterHub.log_level = logging.DEBUG
c.Spawner.debug = True
## Timeout (in seconds) to wait for spawners to initialize
c.JupyterHub.init_spawners_timeout = 20 # default 10
## Timeout (in seconds) before giving up on a spawned HTTP server
c.Spawner.http_timeout = 60 # default 30
## Timeout (in seconds) before giving up on starting of single-user server.
c.Spawner.start_timeout = 120 # default 60
## Extra arguments to be passed to the single-user server.
c.Spawner.args = ["--NotebookApp.terminals_enabled=False"]
c.Authenticator.admin_users = ${JUPYTERHUB_ADMIN_USERS} # noqa
## Force refresh of auth prior to spawn.
# Do nothing right now, pending implementation of
# MagpieAuthenticator.refresh_user() (see
# https://github.com/Ouranosinc/jupyterhub/issues/2)
c.Authenticator.refresh_pre_spawn = True
## Blacklist of usernames that are not allowed to log in.
# https://jupyterhub.readthedocs.io/en/stable/api/auth.html
#
# For security reasons, block user with known hardcoded public password or
# non real Jupyter users.
blocked_users = {'authtest', '${CATALOG_USERNAME}', 'anonymous'}
c.Authenticator.blacklist = blocked_users # v0.9+
c.Authenticator.blocked_users = blocked_users # v1.2+
${JUPYTERHUB_CONFIG_OVERRIDE} # noqa