Skip to content

Commit

Permalink
Merge pull request #1851 from manics/local-binder-local-hub
Browse files Browse the repository at this point in the history
local-binder-local-hub: easier testing of auth and non-standard Docker
  • Loading branch information
consideRatio committed May 10, 2024
2 parents 5c05e7a + a55cc10 commit 430a3ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions testing/local-binder-local-hub/README.md
Expand Up @@ -17,3 +17,8 @@ Run JupyterHub in one terminal

BinderHub will be running as a managed JupyterHub service, go to http://localhost:8000
and you should be redirected to BinderHub.

If you want to test BinderHub with dummy authentication:

export AUTHENTICATOR=dummy
jupyterhub --config=jupyterhub_config.py
3 changes: 3 additions & 0 deletions testing/local-binder-local-hub/binderhub_config.py
Expand Up @@ -42,3 +42,6 @@
# JUPYTERHUB_BASE_URL may not include the host
# c.BinderHub.hub_url = os.getenv('JUPYTERHUB_BASE_URL')
c.BinderHub.hub_url = os.getenv("JUPYTERHUB_EXTERNAL_URL") or f"http://{hostip}:8000"

if os.getenv("AUTH_ENABLED") == "1":
c.BinderHub.auth_enabled = True
19 changes: 17 additions & 2 deletions testing/local-binder-local-hub/jupyterhub_config.py
Expand Up @@ -30,7 +30,20 @@ class LocalContainerSpawner(BinderSpawnerMixin, DockerSpawner):

c.Application.log_level = "DEBUG"
c.Spawner.debug = True
c.JupyterHub.authenticator_class = "null"
c.JupyterHub.authenticator_class = os.getenv("AUTHENTICATOR", "null")

auth_enabled = c.JupyterHub.authenticator_class != "null"
if auth_enabled:
c.JupyterHub.load_roles = [
{
"name": "user",
"description": "Standard user privileges",
"scopes": [
"self",
"access:services!service=binder",
],
}
]

c.JupyterHub.hub_ip = "0.0.0.0"
c.JupyterHub.hub_connect_ip = hostip
Expand All @@ -39,9 +52,11 @@ class LocalContainerSpawner(BinderSpawnerMixin, DockerSpawner):
binderhub_config = os.path.join(os.path.dirname(__file__), "binderhub_config.py")

binderhub_environment = {}
for env_var in ["JUPYTERHUB_EXTERNAL_URL", "GITHUB_ACCESS_TOKEN"]:
for env_var in ["JUPYTERHUB_EXTERNAL_URL", "GITHUB_ACCESS_TOKEN", "DOCKER_HOST"]:
if os.getenv(env_var) is not None:
binderhub_environment[env_var] = os.getenv(env_var)
if auth_enabled:
binderhub_environment["AUTH_ENABLED"] = "1"
c.JupyterHub.services = [
{
"name": binderhub_service_name,
Expand Down

0 comments on commit 430a3ea

Please sign in to comment.