Skip to content

Commit ada64a9

Browse files
committed
not working
1 parent fe330c7 commit ada64a9

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

jupyterhub/Dockerfile.jupyterlab

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ RUN apt-get -qq update && apt-get install -y --no-install-recommends \
1414

1515
USER $NB_USER
1616

17+
COPY Clowder_APIs.ipynb /home/jovyan/work/
18+
19+
COPY Clowder_APIs.ipynb /home/jovyan/
20+
1721
# Install Python packages
1822
RUN pip install --no-cache-dir \
1923
requests \
2024
pyclowder \
2125
pandas
22-
23-
# Copy Clowder API notebook
24-
COPY Clowder_APIs.ipynb /etc/jupyter/Clowder_APIs.ipynb

jupyterhub/jupyterhub_config.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# Configuration file for JupyterHub
66
import os
7-
import shutil
87

98
from customauthenticator.custom import CustomTokenAuthenticator
109

@@ -14,6 +13,38 @@
1413
# avoid having to rebuild the JupyterHub container every time we change a
1514
# configuration parameter.
1615

16+
17+
def create_dir_hook(spawner):
18+
username = spawner.user.name # get the username
19+
20+
volume_path = os.path.join("/volumes/jupyterhub/", username)
21+
print(f"Checking if {volume_path} exists…")
22+
23+
if not os.path.exists(volume_path):
24+
print(f"{volume_path} does not exist. Creating directory...")
25+
# create a directory with umask 0755
26+
# hub and container user must have the same UID to be writeable
27+
# still readable by other users on the system
28+
try:
29+
# Attempt to create the directory
30+
os.mkdir(volume_path)
31+
print(f"Directory {volume_path} created.")
32+
# Now, do whatever you think your user needs
33+
# ...
34+
except OSError as e:
35+
print(f"Error creating directory {volume_path}: {e}")
36+
37+
try:
38+
os.chown(volume_path, 1003, 1003)
39+
print("Ownership of changed successfully.")
40+
except OSError as e:
41+
print(f"Error changing ownership of: {e}")
42+
# now do whatever you think your user needs
43+
44+
45+
# attach the hook function to the spawner
46+
c.Spawner.pre_spawn_hook = create_dir_hook
47+
1748
# Spawn single-user servers as Docker containers
1849
c.JupyterHub.spawner_class = "dockerspawner.DockerSpawner"
1950

@@ -37,7 +68,6 @@
3768
# notebook directory in the container
3869
c.DockerSpawner.volumes = {"jupyterhub-user-{username}": notebook_dir}
3970

40-
4171
# Remove containers once they are stopped
4272
c.DockerSpawner.remove = True
4373

@@ -103,17 +133,3 @@
103133
admin = os.environ.get("JUPYTERHUB_ADMIN")
104134
if admin:
105135
c.Authenticator.admin_users = [admin]
106-
107-
108-
# Pre spawn hook
109-
def post_spawn_hook(spawner, auth_state):
110-
username = spawner.user.name
111-
spawner.environment["GREETING"] = f"Hello Master {username}"
112-
113-
target_file_path = f"/home/jovyan/work/Clowder_APIs.ipynb"
114-
115-
if not os.path.exists(target_file_path):
116-
shutil.copy2("/etc/jupyter/Clowder_APIs.ipynb", target_file_path)
117-
118-
119-
# c.Spawner.auth_state_hook = post_spawn_hook

0 commit comments

Comments
 (0)