@@ -16,107 +16,104 @@ class LocalNativeAuthenticator(NativeAuthenticator, LocalAuthenticator):
16
16
pass
17
17
18
18
19
- c : Config = get_config ()
20
-
21
- # Spawn containers from this image
22
- # Either use the CoGstack one from the repo which is huge and contains all the stuff needed or,
23
- # use the default official one which is clean.
24
- c .DockerSpawner .image = os .getenv ("DOCKER_NOTEBOOK_IMAGE" , "cogstacksystems:jupyterhub/singleuser:latest-amd64" )
19
+ DOCKER_NOTEBOOK_IMAGE = os .getenv ("DOCKER_NOTEBOOK_IMAGE" , "cogstacksystems:jupyterhub/singleuser:latest-amd64" )
25
20
26
21
# JupyterHub requires a single-user instance of the Notebook server, so we
27
22
# default to using the `start-singleuser.sh` script included in the
28
23
# jupyter/docker-stacks *-notebook images as the Docker run command when
29
24
# spawning containers. Optionally, you can override the Docker run command
30
25
# using the DOCKER_SPAWN_CMD environment variable.
31
- spawn_cmd = os .environ .get ("DOCKER_SPAWN_CMD" , "start-singleuser.sh" )
26
+ SPAWN_CMD = os .environ .get ("DOCKER_SPAWN_CMD" , "start-singleuser.sh" )
32
27
33
28
# Connect containers to this Docker network
34
29
# IMPORTANT, THIS MUST MATCH THE NETWORK DECLARED in "services.yml", by default: "cogstack-net"
35
- network_name = os .environ .get ("DOCKER_NETWORK_NAME" , "cogstack-net" )
30
+ NETWORK_NAME = os .environ .get ("DOCKER_NETWORK_NAME" , "cogstack-net" )
36
31
37
32
# The IP address or hostname of the JupyterHub container in the Docker network
38
- hub_container_ip_or_name = os .environ .get ("DOCKER_JUPYTER_HUB_CONTAINER_NAME" , "cogstack-jupyter-hub" )
33
+ HUB_CONTAINER_IP_OR_NAME = os .environ .get ("DOCKER_JUPYTER_HUB_CONTAINER_NAME" , "cogstack-jupyter-hub" )
39
34
40
35
# The timeout in seconds after which the idle notebook container will be shutdown
41
- notebook_idle_timeout = os .environ .get ("DOCKER_NOTEBOOK_IDLE_TIMEOUT" , "7200" )
36
+ NOTEBOOK_IDLE_TIMEOUT = int ( os .environ .get ("DOCKER_NOTEBOOK_IDLE_TIMEOUT" , "7200" ) )
42
37
43
- c .DockerSpawner .use_internal_ip = True
44
- c .DockerSpawner .network_name = network_name
45
- # Pass the network name as argument to spawned containers
46
- c .DockerSpawner .extra_host_config = {"network_mode" : network_name }
38
+ SELECT_NOTEBOOK_IMAGE_ALLOWED = str (os .environ .get ("DOCKER_SELECT_NOTEBOOK_IMAGE_ALLOWED" , "false" )).lower ()
39
+
40
+ RUN_IN_DEBUG_MODE = str (os .environ .get ("DOCKER_NOTEBOOK_DEBUG_MODE" , "false" )).lower ()
47
41
48
42
# Explicitly set notebook directory because we"ll be mounting a host volume to
49
43
# it. Most jupyter/docker-stacks *-notebook images run the Notebook server as
50
44
# user `jovyan`, and set the notebook directory to `/home/jovyan/work`.
51
45
# We follow the same convention.
52
- notebook_dir = os .environ .get ("DOCKER_NOTEBOOK_DIR" , "/home/jovyan/work" )
53
- shared_content_dir = os .environ .get ("DOCKER_SHARED_DIR" , "/home/jovyan/scratch" )
54
- work_dir = os .environ .get ("JUPYTER_WORK_DIR" , "/lab/workspaces/auto-b/tree/" + str (notebook_dir .split ("/" )[- 1 ]))
55
-
56
- #c.DockerSpawner.notebook_dir = notebook_dir
57
- # Mount the real user"s Docker volume on the host to the notebook user"s
58
- # notebook directory in the container
59
- c .DockerSpawner .volumes = {"jupyterhub-user-{username}" : notebook_dir , "jupyter-hub-shared-scratch" : shared_content_dir }
60
- # volume_driver is no longer a keyword argument to create_container()
46
+ NOTEBOOK_DIR = os .environ .get ("DOCKER_NOTEBOOK_DIR" , "/home/jovyan/work" )
47
+ SHARED_CONTENT_DIR = os .environ .get ("DOCKER_SHARED_DIR" , "/home/jovyan/scratch" )
48
+ #WORK_DIR = os.environ.get("DOCKER_JUPYTER_WORK_DIR", "/lab/workspaces/auto-b/tree/" + str(NOTEBOOK_DIR.split("/")[-1]))
49
+ WORK_DIR = "/lab/"
61
50
51
+ ENV_PROXIES = {
52
+ "HTTP_PROXY" : os .environ .get ("HTTP_PROXY" , "" ),
53
+ "HTTPS_PROXY" : os .environ .get ("HTTPS_PROXY" , "" ),
54
+ "NO_PROXY" : "," .join (list (filter (len , os .environ .get ("NO_PROXY" , "" ).split ("," ) + [HUB_CONTAINER_IP_OR_NAME ]))),
55
+ "http_proxy" : os .environ .get ("HTTP_PROXY" , os .environ .get ("http_proxy" , "" )),
56
+ "https_proxy" : os .environ .get ("HTTPS_PROXY" , os .environ .get ("https_proxy" , "" )),
57
+ "no_proxy" : "," .join (list (filter (len , os .environ .get ("no_proxy" , "" ).split ("," ) + [HUB_CONTAINER_IP_OR_NAME ]))),
58
+ }
59
+
60
+ os .environ ["NO_PROXY" ] = ""
61
+ os .environ ["no_proxy" ] = ""
62
+ os .environ ["HTTP_PROXY" ] = ""
63
+ os .environ ["HTTPS_PROXY" ] = ""
64
+ os .environ ["http_proxy" ] = ""
65
+ os .environ ["https_proxy" ] = ""
66
+
67
+ c : Config = get_config ()
68
+
69
+ # Spawn containers from this image
70
+ # Either use the CoGstack one from the repo which is huge and contains all the stuff needed or,
71
+ # use the default official one which is clean.
72
+ c .DockerSpawner .image = DOCKER_NOTEBOOK_IMAGE
73
+
74
+ c .DockerSpawner .use_internal_ip = True
75
+ c .DockerSpawner .network_name = NETWORK_NAME
76
+ # Pass the network name as argument to spawned containers
77
+ c .DockerSpawner .extra_host_config = {"network_mode" : NETWORK_NAME }
78
+
79
+ # # Mount the real users Docker volume on the host to the notebook user"s
80
+ # # notebook directory in the container
81
+ c .DockerSpawner .volumes = {"jupyterhub-user-{username}" : NOTEBOOK_DIR , "jupyter-hub-shared-scratch" : SHARED_CONTENT_DIR }
82
+
83
+ # volume_driver is no longer a keyword argument to create_container()
62
84
63
85
# Remove containers once they are stopped
64
- # c.DockerSpawner.remove_containers = False # Deprected for c.DockerSpawner.remove
65
86
c .DockerSpawner .remove = False
66
87
67
- select_notebook_image_allowed = os . environ . get ( "DOCKER_SELECT_NOTEBOOK_IMAGE_ALLOWED" , "false" )
68
- if select_notebook_image_allowed == "true" :
88
+
89
+ if SELECT_NOTEBOOK_IMAGE_ALLOWED == "true" :
69
90
# c.DockerSpawner.image_whitelist has been deprecated for allowed_images
70
91
c .DockerSpawner .allowed_images = {
71
92
"minimal" : "jupyterhub/singleuser:latest-amd64" ,
72
93
"cogstack" : "cogstacksystems/jupyter-singleuser:latest-amd64" ,
73
- "cogstack-gpu" : "cogstacksystem s /jupyter-singleuser-gpu:latest-amd64"
94
+ "cogstack-gpu" : "cogstacksystems /jupyter-singleuser-gpu:latest-amd64"
74
95
}
75
96
# https://github.com/jupyterhub/dockerspawner/issues/423
76
97
c .DockerSpawner .remove = True
77
98
78
- run_in_debug_mode = os .environ .get ("DOCKER_NOTEBOOK_DEBUG_MODE" , "false" )
79
-
80
- if run_in_debug_mode == "true" :
99
+ if RUN_IN_DEBUG_MODE == "true" :
81
100
# For debugging arguments passed to spawned containers
82
101
c .DockerSpawner .debug = True
83
102
c .Spawner .debug = True
84
103
# Enable debug-logging of the single-user server
85
104
c .LocalProcessSpawner .debug = True
86
105
87
- ENV_PROXIES = {
88
- "HTTP_PROXY" : os .environ .get ("HTTP_PROXY" , "" ),
89
- "HTTPS_PROXY" : os .environ .get ("HTTPS_PROXY" , "" ),
90
- "NO_PROXY" : "," .join (list (filter (len , os .environ .get ("NO_PROXY" , "" ).split ("," ) + [hub_container_ip_or_name ]))),
91
- "http_proxy" : os .environ .get ("HTTP_PROXY" , os .environ .get ("http_proxy" , "" )),
92
- "https_proxy" : os .environ .get ("HTTPS_PROXY" , os .environ .get ("https_proxy" , "" )),
93
- "no_proxy" : "," .join (list (filter (len , os .environ .get ("no_proxy" , "" ).split ("," ) + [hub_container_ip_or_name ]))),
94
- }
95
-
96
- os .environ ["NO_PROXY" ] = ""
97
- os .environ ["no_proxy" ] = ""
98
- os .environ ["HTTP_PROXY" ] = ""
99
- os .environ ["HTTPS_PROXY" ] = ""
100
- os .environ ["http_proxy" ] = ""
101
- os .environ ["https_proxy" ] = ""
102
-
103
-
104
- """
105
- def pre_spawn_hook(spawner):
106
- username = str(spawner.user.name).lower()
107
- try:
108
- pwd.getpwnam(username)
109
- except KeyError:
110
- subprocess.check_call(["useradd", "-ms", "/bin/bash", username])
111
- """
112
-
113
106
114
107
# Spawn single-user servers as Docker containers
115
108
class DockerSpawner (dockerspawner .DockerSpawner ):
116
109
def start (self ):
117
110
# username is self.user.name
118
- self .volumes = {"jupyterhub-user-{}" .format (self .user .name ): notebook_dir }
111
+ self .volumes = {"jupyterhub-user-{}" .format (self .user .name ): NOTEBOOK_DIR }
119
112
113
+ # Mount the real users Docker volume on the host to the notebook user"s
114
+ # # notebook directory in the container
115
+ #self.volumes = {f"jupyterhub-user-{self.user.name}": NOTEBOOK_DIR, "jupyter-hub-shared-scratch": SHARED_CONTENT_DIR}
116
+
120
117
if self .user .name not in whitelist :
121
118
whitelist .add (self .user .name )
122
119
with open (userlist_path , "a" ) as f :
@@ -125,15 +122,15 @@ def start(self):
125
122
126
123
if self .user .name in list (team_map .keys ()):
127
124
for team in team_map [self .user .name ]:
128
- team_dir_path = os .path .join (shared_content_dir , team )
125
+ team_dir_path = os .path .join (SHARED_CONTENT_DIR , team )
129
126
self .volumes ["jupyterhub-team-{}" .format (team )] = {
130
127
"bind" : team_dir_path ,
131
128
"mode" : "rw" , # or ro for read-only
132
129
}
133
130
134
131
# this is a temporary fix, need to actually check permissions
135
132
self .mem_limit = resource_allocation_user_ram_limit
136
- self .post_start_cmd = "chmod -R 777 " + shared_content_dir
133
+ self .post_start_cmd = "chmod -R 777 " + SHARED_CONTENT_DIR
137
134
138
135
return super ().start ()
139
136
@@ -151,7 +148,17 @@ def pre_spawn_hook(spawner: DockerSpawner):
151
148
traceback .print_exc ()
152
149
153
150
154
- c .Spawner .default_url = work_dir
151
+ """
152
+ def pre_spawn_hook(spawner):
153
+ username = str(spawner.user.name).lower()
154
+ try:
155
+ pwd.getpwnam(username)
156
+ except KeyError:
157
+ subprocess.check_call(["useradd", "-ms", "/bin/bash", username])
158
+ """
159
+
160
+
161
+ c .Spawner .default_url = WORK_DIR
155
162
c .Spawner .pre_spawn_hook = pre_spawn_hook
156
163
157
164
#c.Spawner.ip = "127.0.0.1"
@@ -203,10 +210,12 @@ def per_user_limit(role):
203
210
c .JupyterHub .spawner_class = DockerSpawner
204
211
205
212
# set DockerSpawner args
206
- c .DockerSpawner .extra_create_kwargs .update ({"command" : spawn_cmd })
213
+ c .DockerSpawner .extra_create_kwargs .update ({"command" : SPAWN_CMD })
207
214
# c.DockerSpawner.extra_create_kwargs.update({ "volume_driver": "local" })
208
215
c .DockerSpawner .extra_create_kwargs = {"user" : "root" }
209
216
217
+ c .DockerSpawner .notebook_dir = NOTEBOOK_DIR
218
+
210
219
with open (userlist_path ) as f :
211
220
for line in f :
212
221
if not line :
@@ -277,7 +286,7 @@ def per_user_limit(role):
277
286
# User containers will access hub by container name on the Docker network
278
287
c .JupyterHub .ip = "0.0.0.0"
279
288
c .JupyterHub .hub_ip = "0.0.0.0"
280
- c .JupyterHub .hub_connect_ip = hub_container_ip_or_name
289
+ c .JupyterHub .hub_connect_ip = HUB_CONTAINER_IP_OR_NAME
281
290
282
291
283
292
jupyter_hub_port = int (os .environ .get ("JUPYTERHUB_INTERNAL_PORT" , 8888 ))
@@ -301,14 +310,15 @@ def per_user_limit(role):
301
310
c .JupyterHub .cookie_secret_file = data_dir + "jupyterhub_cookie_secret"
302
311
303
312
c .JupyterHub .services = []
304
- if int (notebook_idle_timeout ) > 0 :
313
+
314
+ if NOTEBOOK_IDLE_TIMEOUT > 0 :
305
315
c .JupyterHub .services .append ({
306
316
"name" : "idle-culler" ,
307
317
"admin" : True ,
308
318
"command" : [
309
319
sys .executable ,
310
320
"-m" , "jupyterhub_idle_culler" ,
311
- f"--timeout={ notebook_idle_timeout } " ,
321
+ f"--timeout={ NOTEBOOK_IDLE_TIMEOUT } " ,
312
322
],
313
323
})
314
324
0 commit comments