-
Notifications
You must be signed in to change notification settings - Fork 5
/
jupyterhub_config.py
140 lines (119 loc) · 4.36 KB
/
jupyterhub_config.py
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
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# Configuration file for JupyterHub
import os
import sys
c = get_config()
# We rely on environment variables to configure JupyterHub so that we
# avoid having to rebuild the JupyterHub container every time we change a
# configuration parameter.
network_name = os.environ['DOCKER_NETWORK_NAME']
notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
#notebook_dir = '/home/' + os.environ.get('NB_USER') + '/work'
notebook_image = os.environ['DOCKER_NOTEBOOK_IMAGE']
notebook_spawn_cmd = os.environ['DOCKER_SPAWN_CMD']
user_workspaces_dir = os.environ['USER_WORKSPACES_DIR']
datacube_v200_dir =os.environ['DATACUBE_V200_DIR']
datacube_v211_suppl_dir =os.environ['DATACUBE_V211_SUPPL_DIR']
datacube_v21_dir =os.environ['DATACUBE_V21_DIR']
datacube_v211_dir =os.environ['DATACUBE_V211_DIR']
sample_notebooks_dir = os.environ['SAMPLE_NOTEBOOKS_DIR']
c.JupyterHub.spawner_class = 'cassinyspawner.SwarmSpawner'
c.JupyterHub.services = [
{
'name': 'cull-idle',
'admin': True,
'command': [sys.executable, 'cull_idle_servers.py', '--timeout=7200'],
}
]
c.SwarmSpawner.jupyterhub_service_name = os.environ['JUPYTERHUB_SERVICE_NAME']
c.SwarmSpawner.networks = [network_name]
c.SwarmSpawner.placement = ["node.role == worker"]
c.SwarmSpawner.notebook_dir = notebook_dir
mounts = [
{
'type' : 'bind',
'source' : user_workspaces_dir,
'target' : '/home/esdc'
},
{
'type' : 'bind',
'source' : datacube_v200_dir,
'target' : notebook_dir + '/datacube/ESDCv2.0.0',
'read_only': True
},
{
'type' : 'bind',
'source' : datacube_v211_suppl_dir,
'target' : notebook_dir + '/datacube/ESDCv2.1.1_suppl',
'read_only': True
},
{
'type' : 'bind',
'source' : datacube_v21_dir,
'target' : notebook_dir + '/datacube/ESDCv2.1',
'read_only': True
},
{
'type' : 'bind',
'source' : datacube_v211_dir,
'target' : notebook_dir + '/datacube/ESDCv2.1.1',
'read_only': True
},
{
'type' : 'bind',
'source' : sample_notebooks_dir,
'target' : notebook_dir + '/shared-nb',
'read_only': True
}
]
c.SwarmSpawner.container_spec = {
# The command to run inside the service
'args' : [notebook_spawn_cmd],
'Image' : notebook_image,
'mounts' : mounts,
# ideally the following parameters can be passed. At the moment produces an error when changing home directory,
# look here https://github.com/jupyter/docker-stacks/issues/442
# 'env': {'NB_UID': 52000, 'NB_GID': 52000, 'NB_USER': 'esdc', 'DOCKER_NOTEBOOK_DIR': notebook_dir},
'env' : {'JUPYTER_ENABLE_LAB':1},
'user' : 'root'
}
c.SwarmSpawner.resource_spec = {
'mem_limit' : int(32 * 1000 * 1000 * 1000),
'mem_reservation' : int(4 * 1000 * 1000 * 1000),
}
c.SwarmSpawner.start_timeout = 60 * 5
c.SwarmSpawner.http_timeout = 60 * 2
c.SwarmSpawner.service_prefix = os.environ['JUPYTER_NB_PREFIX']
c.MappingKernelManager.cull_idle_timeout = 200
c.NotebookApp.shutdown_no_activity_timeout = 100
# User containers will access hub by container name on the Docker network
# c.JupyterHub.hub_ip = '0.0.0.0'
# TLS config
c.JupyterHub.port = 443
c.JupyterHub.ip = "0.0.0.0"
c.JupyterHub.hub_ip = "0.0.0.0"
c.JupyterHub.ssl_key = os.environ['SSL_KEY']
c.JupyterHub.ssl_cert = os.environ['SSL_CERT']
# Authenticate users with GitHub OAuth
c.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator'
c.GitHubOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL']
# Persist hub data on volume mounted inside container
data_dir = os.environ.get('DATA_VOLUME_CONTAINER', '/data')
c.JupyterHub.db_url = os.path.join('sqlite:///', data_dir, 'jupyterhub.sqlite')
c.JupyterHub.cookie_secret_file = os.path.join(data_dir,
'jupyterhub_cookie_secret')
# Whitlelist users and admins
c.Authenticator.whitelist = whitelist = set()
c.Authenticator.admin_users = admin = set()
c.JupyterHub.admin_access = True
pwd = os.path.dirname(__file__)
with open(os.path.join(pwd, 'userlist')) as f:
for line in f:
if not line:
continue
parts = line.split()
name = parts[0]
whitelist.add(name)
if len(parts) > 1 and parts[1] == 'admin':
admin.add(name)