Skip to content

Commit

Permalink
add shared dir to user's favorite list
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianhao-Gu committed Oct 1, 2024
1 parent d7b442d commit 101163c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ ENV CDM_SHARED_DIR=/cdm_shared_workspace
RUN mkdir -p ${CDM_SHARED_DIR} && chmod -R 777 ${CDM_SHARED_DIR}
RUN chown -R spark_user:spark $CDM_SHARED_DIR

# TODO: Config through a config file or DB as the number of groups increases.
ENV KBASE_GROUP_SHARED_DIR=$CDM_SHARED_DIR/kbase_group_shared
RUN mkdir -p ${KBASE_GROUP_SHARED_DIR} && chmod -R 777 ${KBASE_GROUP_SHARED_DIR}
RUN chown -R spark_user:spark $KBASE_GROUP_SHARED_DIR

# Set a directory for hosting Hive metastore files - defined in config/hive-site-template.xml
ENV HIVE_METASTORE_DIR=$CDM_SHARED_DIR/hive_metastore
RUN mkdir -p ${HIVE_METASTORE_DIR}
Expand Down
20 changes: 12 additions & 8 deletions src/jupyterhub_config/custom_docker_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def start(self):
# Ensure the user's volume is correctly mounted in the container
self._ensure_user_volume()

# Add the user's home directory to JupyterLab favorites
# TODO: include shared group directories in favorites
self._add_favorite_dir(user_dir)
# Add the user's home and group shared directory to Jupyterhub favorites
self._add_favorite_dir(user_dir, favorites={Path(os.environ['KBASE_GROUP_SHARED_DIR'])})

Check warning on line 38 in src/jupyterhub_config/custom_docker_spawner.py

View check run for this annotation

Codecov / codecov/patch

src/jupyterhub_config/custom_docker_spawner.py#L38

Added line #L38 was not covered by tests

return super().start()

Expand Down Expand Up @@ -138,7 +137,9 @@ def _configure_notebook_dir(self, username: str, user_dir: Path):
self.notebook_dir = str('/')
else:
self.log.info(f'Non-admin user detected: {username}. Setting up user-specific workspace.')
self.notebook_dir = str(user_dir)
# TODO: It appears that notebook_dir must be the parent of the favorites directory - investigate if it's possible to set notebook_dir to user_dir
# self.notebook_dir = str(user_dir)
self.notebook_dir = str('/')

Check warning on line 142 in src/jupyterhub_config/custom_docker_spawner.py

View check run for this annotation

Codecov / codecov/patch

src/jupyterhub_config/custom_docker_spawner.py#L142

Added line #L142 was not covered by tests

def _is_rw_minio_user(self):
"""
Expand All @@ -160,6 +161,7 @@ def _ensure_user_volume(self):

cdm_shared_dir = Path(os.environ['CDM_SHARED_DIR']) # Legacy data volume from JupyterLab
hive_metastore_dir = Path(os.environ['HIVE_METASTORE_DIR']) # within cdm_shared_dir
kbase_shared_dir = Path(os.environ['KBASE_GROUP_SHARED_DIR']) # within cdm_shared_dir

Check warning on line 164 in src/jupyterhub_config/custom_docker_spawner.py

View check run for this annotation

Codecov / codecov/patch

src/jupyterhub_config/custom_docker_spawner.py#L164

Added line #L164 was not covered by tests

if self.user.admin:
self.log.info(f'Admin user detected: {self.user.name}. Setting up admin mount points.')
Expand All @@ -174,7 +176,8 @@ def _ensure_user_volume(self):
self.volumes.update({
f'{mount_base_dir}/{hive_metastore_dir}': {'bind': f'{hive_metastore_dir}', 'mode': access_mode},
# User specific home directory
f'{mount_base_dir}/{user_home_dir}/{self.user.name}': f'{user_home_dir}/{self.user.name}'
f'{mount_base_dir}/{user_home_dir}/{self.user.name}': f'{user_home_dir}/{self.user.name}',
f'{mount_base_dir}/{kbase_shared_dir}': f'{kbase_shared_dir}',
})

def _add_favorite_dir(self, user_dir: Path, favorites: set[Path] = None):
Expand Down Expand Up @@ -211,16 +214,17 @@ def _add_favorite_dir(self, user_dir: Path, favorites: set[Path] = None):
if not fav.is_dir():
raise ValueError(f"Favorite {fav} is not a directory or does not exist")

root_str = str(fav)
path_str = ""
# same approach used by NERSC JupyterHub
root_str = "/"
path_str = str(fav.relative_to(root_str))

Check warning on line 219 in src/jupyterhub_config/custom_docker_spawner.py

View check run for this annotation

Codecov / codecov/patch

src/jupyterhub_config/custom_docker_spawner.py#L218-L219

Added lines #L218 - L219 were not covered by tests

if (root_str, path_str) not in existing_fav_set:
exist_favorites["favorites"].append({
"root": root_str,
"path": path_str,
"contentType": "directory",
"iconLabel": "ui-components:folder",
"name": "$HOME" if root_str == str(user_dir) else fav.name,
"name": "$HOME" if str(fav) == str(user_dir) else fav.name,
})

with open(jupyterlab_favorites_path, 'w') as f:
Expand Down
2 changes: 1 addition & 1 deletion src/jupyterhub_config/hub_singleuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SingleUserEnvManager:

def __init__(self,
username,
groupname: str = 'jupyterhub', ):
groupname: str = 'kbase', ):
"""
Initializes the environment manager for the specified user.
:param username: The name of the user for whom the environment is set up.
Expand Down

0 comments on commit 101163c

Please sign in to comment.