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

fix docker volumn mount + notebook dir for admin #88

Merged
merged 3 commits into from
Sep 13, 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
12 changes: 6 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
- POSTGRES_DB=hive
- POSTGRES_URL=postgres:5432
volumes:
- ./cdr/cdm/jupyter:/cdm_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace:/cdm_shared_workspace

spark-worker-1:
# The latest image from cdm-jupyterhub that includes spark standalone mode
Expand All @@ -68,7 +68,7 @@ services:
- POSTGRES_DB=hive
- POSTGRES_URL=postgres:5432
volumes:
- ./cdr/cdm/jupyter:/cdm_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace:/cdm_shared_workspace

spark-worker-2:
# The latest image from cdm-jupyterhub that includes spark standalone mode
Expand All @@ -90,7 +90,7 @@ services:
- POSTGRES_DB=hive
- POSTGRES_URL=postgres:5432
volumes:
- ./cdr/cdm/jupyter:/cdm_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace:/cdm_shared_workspace

minio:
image: minio/minio
Expand Down Expand Up @@ -150,7 +150,7 @@ services:
- POSTGRES_URL=postgres:5432
- USAGE_MODE=dev # Enabling dev mode grants full access to MinIO and additional privileges for services like Hive, such as the ability to create tables as defined in the scripts/setup.sh.
volumes:
- ./cdr/cdm/jupyter:/cdm_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace:/cdm_shared_workspace

user-jupyterlab:
build:
Expand Down Expand Up @@ -179,7 +179,7 @@ services:
- POSTGRES_DB=hive
- POSTGRES_URL=postgres:5432
volumes:
- ./cdr/cdm/jupyter/user_shared_workspace:/cdm_shared_workspace/user_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace/user_shared_workspace:/cdm_shared_workspace/user_shared_workspace

cdm_jupyterhub:
build:
Expand Down Expand Up @@ -211,7 +211,7 @@ services:
- POSTGRES_URL=postgres:5432
- JUPYTERHUB_ADMIN_PASSWORD=testpassword123
volumes:
- ./cdr/cdm/jupyter:/cdm_shared_workspace
- ./cdr/cdm/jupyter/cdm_shared_workspace:/cdm_shared_workspace # Legacy data volume from JupyterLab
- ./cdr/cdm/jupyter/jupyterhub_secrets:/jupyterhub_secrets
- ./cdr/cdm/jupyter/jupyterhub/users_home:/jupyterhub/users_home

Expand Down
3 changes: 2 additions & 1 deletion src/jupyterhub_config/custom_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def _configure_notebook_dir(self, username: str, user_dir: Path):
"""
if self.user.admin:
self.log.info(f'Admin user detected: {username}. Setting up admin workspace.')
self.notebook_dir = '/cdm_shared_workspace'
# root directory
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)
40 changes: 19 additions & 21 deletions test/src/jupyterhub_config/custom_spawner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,25 +445,23 @@ def test_configure_environment_missing_pythonpath(spawner):
# Check that PYTHONPATH is set correctly even when it's not in the original environment
assert f"{user_env_dir}/lib/python3.11/site-packages" == spawner.environment['PYTHONPATH']


@pytest.mark.parametrize("is_admin, expected_dir", [
(True, '/cdm_shared_workspace'), # Admin user case
(False, 'to_be_defined_in_the_test') # Non-admin user case
])
def test_configure_notebook_dir(is_admin, expected_dir, spawner, caplog):
spawner.user.admin = is_admin
def test_configure_notebook_dir(spawner, caplog):
username = 'testuser'
with tempfile.TemporaryDirectory() as temp_dir:
user_dir = Path(temp_dir) / 'testuser'
if not is_admin:
expected_dir = str(user_dir)

with caplog.at_level(logging.INFO):
spawner._configure_notebook_dir(username, user_dir)

assert spawner.notebook_dir == expected_dir

if is_admin:
assert f'Admin user detected: {username}. Setting up admin workspace.' in caplog.text
else:
assert f'Non-admin user detected: {username}. Setting up user-specific workspace.' in caplog.text
for is_admin in [True, False]:
spawner.user.admin = is_admin
with tempfile.TemporaryDirectory() as temp_dir:
user_dir = Path(temp_dir) / 'testuser'
if not is_admin:
expected_dir = str(user_dir)
else:
expected_dir = '/'

with caplog.at_level(logging.INFO):
spawner._configure_notebook_dir(username, user_dir)

assert spawner.notebook_dir == expected_dir

if is_admin:
assert f'Admin user detected: {username}. Setting up admin workspace.' in caplog.text
else:
assert f'Non-admin user detected: {username}. Setting up user-specific workspace.' in caplog.text
Loading