Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add shared dir to user's favorite list #102

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you thinking this is going to work? Is there going to be a mount per group?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking in long-term plan, we will first get a list of dirs that are shared to the login user. And then mount those dir to that user.

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 @@
# 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 @@
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 @@

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 @@
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 @@
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
Loading