Skip to content
Draft
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
22 changes: 21 additions & 1 deletion .github/scripts/generate_ci_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -xeuo pipefail

if [[ $# -lt 2 ]]; then
cat >&2 <<'USAGE'
Usage: generate_ci_config.sh <output_path> <base_config_yaml> [--minio] [--jupyterhub] [--weko] [--flowable] [--s3compatsigv4] [--s3compatsigv4-inst] [--wiki]
Usage: generate_ci_config.sh <output_path> <base_config_yaml> [--minio] [--jupyterhub] [--binderhub] [--weko] [--flowable] [--s3compatsigv4] [--s3compatsigv4-inst] [--wiki]
USAGE
exit 1
fi
Expand All @@ -13,6 +13,7 @@ BASE_CONFIG=$2
shift 2
MINIO=false
JUPYTERHUB=false
BINDERHUB=false
WEKO=false
FLOWABLE=false
S3COMPATSIGV4=false
Expand All @@ -27,6 +28,9 @@ for arg in "$@"; do
--jupyterhub)
JUPYTERHUB=true
;;
--binderhub)
BINDERHUB=true
;;
--weko)
WEKO=true
;;
Expand Down Expand Up @@ -105,6 +109,22 @@ jupyterhub_enabled: false
EOF
fi

if [[ "${BINDERHUB}" == "true" ]]; then
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
python3 - "$script_dir/../../docker/binderhub/.state/config.json" "$OUTPUT" <<'PYTHON'
import json
from pathlib import Path
import sys
import yaml
config = json.loads(Path(sys.argv[1]).read_text())
with open(sys.argv[2], 'a') as out:
out.write('\n')
yaml.safe_dump(dict(binderhub_enabled=True,
binderhub_binderhub_url=config['binder_origin'],
jupyterhub_username=config['username'], jupyterhub_password=config['password']), out)
PYTHON
fi

if [[ "${WEKO}" == "true" ]]; then
WEKO_URL_VALUE=${WEKO_URL:-http://localhost}
WEKO_ADMIN_EMAIL_VALUE=${WEKO_ADMIN_EMAIL:-}
Expand Down
54 changes: 54 additions & 0 deletions .github/scripts/setup_binderhub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
"""Prepare OAuth settings for both the local Hub and the existing RDM deployment."""
import argparse
import json
import os
from pathlib import Path
import secrets


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('rdm_root', type=Path)
parser.add_argument('--rdm-origin', default='http://192.168.168.167:5000')
parser.add_argument('--rdm-api', default='http://192.168.168.167:8000/v2/')
parser.add_argument('--hub-origin', default='http://192.168.168.167:18000')
parser.add_argument('--binder-origin', default='http://192.168.168.167:18010')
parser.add_argument('--host-ip', required=True)
args = parser.parse_args()
local = args.rdm_root / 'addons/binderhub/settings/local.py'
if not local.is_file():
parser.error('Run setup_rdm.sh setup_config_files first')
root = Path(__file__).resolve().parents[2] / 'docker/binderhub'
state = root / '.state'
state.mkdir(mode=0o700, exist_ok=True)
if (state / 'config.json').exists():
parser.error('Existing Hub state found; stop and remove it before preparing another deployment')
os.umask(0o077)
d = dict(hub_origin=args.hub_origin.rstrip('/'), binder_origin=args.binder_origin.rstrip('/'), rdm_origin=args.rdm_origin.rstrip('/'),
rdm_api=args.rdm_api, host_ip=args.host_ip, username='rdm-e2e',
password=secrets.token_urlsafe(24), binder_secret=secrets.token_hex(32),
hub_secret=secrets.token_hex(32), admin_token=secrets.token_hex(32),
mount_root=str(state.resolve() / 'rdmfs'))
(state / 'config.json').write_text(json.dumps(d, indent=2)+'\n')
bh = d['binder_origin']
jh = d['hub_origin']+'/'
settings = dict(DEFAULT_BINDER_URL=bh,
BINDERHUB_OAUTH_CLIENT=dict(client_id='rdm-binder', client_secret=d['binder_secret'],
authorize_url=bh+'/api/oauth2/authorize', token_url=bh+'/api/oauth2/token',
services_url=bh+'/api/services', scope=['identity']),
JUPYTERHUB_OAUTH_CLIENTS={jh: dict(client_id='service-rdm', client_secret=d['hub_secret'],
admin_api_token=d['admin_token'], authorize_url=jh+'hub/api/oauth2/authorize',
token_url=jh+'hub/api/oauth2/token', api_url=jh+'hub/api/', scope=['identity'], max_servers=10)})
# setup_rdm.sh has already written the deployment image choices. Preserve them.
with local.open('a') as out:
out.write('\n# Local OAuth E2E configuration\n')
out.write('\n'.join(f'{key} = {value!r}' for key, value in settings.items())+'\n')
if os.environ.get('GITHUB_ACTIONS') == 'true':
for key in ('password', 'binder_secret', 'hub_secret', 'admin_token'):
print('::add-mask::'+d[key])
print('Prepared BinderHub/JupyterHub and RDM OAuth settings')


if __name__ == '__main__':
main()
49 changes: 49 additions & 0 deletions .github/scripts/setup_binderhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
STACK_ROOT="${SCRIPT_DIR}/../../docker/binderhub"
COMMAND=${1:-}
case "$COMMAND" in
prepare)
: "${2:?Usage: setup_binderhub.sh prepare <rdm_root>}"
default_interface=$(ip -4 route show default | awk 'NR==1 {print $5}')
host_ip=${BINDERHUB_HOST_IP:-$(ip -4 addr show "$default_interface" scope global | awk '/inet / {split($2, address, "/"); print address[1]; exit}')}
python3 "${SCRIPT_DIR}/setup_binderhub.py" "$2" --host-ip "$host_ip"
;;
install)
mount_root=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["mount_root"])' "${STACK_ROOT}/.state/config.json")
mkdir -p "$mount_root"
sudo modprobe fuse
if ! mountpoint -q "$mount_root"; then
sudo mount --bind "$mount_root" "$mount_root"
fi
sudo mount --make-rshared "$mount_root"
docker pull gcr.io/nii-ap-ops/rdmfs:2026.02.1
docker compose -f "${STACK_ROOT}/compose.yaml" up --build -d
# Fail during setup if the builder cannot reach the host Docker daemon.
docker compose -f "${STACK_ROOT}/compose.yaml" exec -T hub docker version
for attempt in $(seq 1 90); do
if status=$(curl --silent --show-error -o /dev/null -w '%{http_code}' http://192.168.168.167:18010/api/services); then
if [ "$status" = 302 ]; then exit 0; fi
fi
sleep 2
done
echo 'BinderHub did not become ready' >&2
exit 1
;;
down)
docker compose -f "${STACK_ROOT}/compose.yaml" down
docker ps -aq --filter name=rdm-e2e-binder- | xargs -r docker rm -f
if [ -f "${STACK_ROOT}/.state/config.json" ]; then
mount_root=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["mount_root"])' "${STACK_ROOT}/.state/config.json")
if mountpoint -q "$mount_root"; then
sudo umount --recursive --lazy "$mount_root"
fi
fi
;;
*)
echo 'Usage: setup_binderhub.sh <prepare|install|down> [rdm_root]' >&2
exit 1
;;
esac
50 changes: 50 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,26 @@ jobs:
flowable_enabled: false
wiki_enabled: false
mapcore_group_enabled: true
- name: user-binderhub-oauth
display_name: "User Tests (BinderHub OAuth)"
include_admin: false
skip_admin: true
skip_metadata: true
skip_default_storage: true
skip_login: true
skip_130mb_upload: true
minio_enabled: false
weko_enabled: false
jupyterhub_enabled: false
binderhub_enabled: true
flowable_enabled: false
name: E2E ${{ matrix.test-group.display_name }}
env:
MINIO_ENABLED: ${{ matrix.test-group.minio_enabled == true && 'true' || 'false' }}
S3COMPATSIGV4_ENABLED: ${{ matrix.test-group.s3compatsigv4_enabled == true && 'true' || 'false' }}
S3COMPATSIGV4_INST_ENABLED: ${{ matrix.test-group.s3compatsigv4_institutional_storage == true && 'true' || 'false' }}
WEKO_ENABLED: ${{ matrix.test-group.weko_enabled == true && 'true' || 'false' }}
BINDERHUB_ENABLED: ${{ matrix.test-group.binderhub_enabled == true && 'true' || 'false' }}
JUPYTERHUB_ENABLED: ${{ matrix.test-group.jupyterhub_enabled == true && 'true' || 'false' }}
FLOWABLE_ENABLED: ${{ matrix.test-group.flowable_enabled == true && 'true' || 'false' }}
MIBYO_DB_ENABLED: ${{ matrix.test-group.mibyo_db_enabled == true && 'true' || 'false' }}
Expand Down Expand Up @@ -888,6 +902,11 @@ jobs:
export INCLUDE_ADMIN=${{ matrix.test-group.include_admin }}
setup_config_files

- name: Prepare OAuth BinderHub settings
if: env.BINDERHUB_ENABLED == 'true'
working-directory: e2e-tests
run: .github/scripts/setup_binderhub.sh prepare ../RDM-osf.io

- name: Parse PR body and workflow parameters
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
Expand Down Expand Up @@ -1295,6 +1314,11 @@ jobs:
echo "WORKFLOW_BATCH_PROJECT_COUNT=${{ matrix.test-group.workflow_batch_project_count || 50 }}" >> $GITHUB_ENV
echo "WORKFLOW_TEST_MODE=${{ matrix.test-group.workflow_test_mode }}" >> $GITHUB_ENV

- name: Install OAuth BinderHub stack
if: env.BINDERHUB_ENABLED == 'true'
working-directory: e2e-tests
run: .github/scripts/setup_binderhub.sh install

- name: Install TLJH stack
if: env.JUPYTERHUB_ENABLED == 'true'
working-directory: e2e-tests
Expand Down Expand Up @@ -1503,6 +1527,9 @@ jobs:
args+=(--wiki)
fi

if [ "${BINDERHUB_ENABLED}" = "true" ]; then
args+=(--binderhub)
fi
.github/scripts/generate_ci_config.sh "${args[@]}"
rm base_ci.config.yaml

Expand Down Expand Up @@ -1641,6 +1668,24 @@ jobs:
path: e2e-tests/weko-docker-logs.txt
retention-days: 7

- name: Collect OAuth BinderHub logs
if: always() && env.BINDERHUB_ENABLED == 'true'
working-directory: e2e-tests
run: |
docker compose -f docker/binderhub/compose.yaml logs --no-color > binderhub-logs.txt 2>&1
for container in $(docker ps -a --filter name=rdm-e2e-binder- --format '{{.Names}}'); do
echo "Container: $container" >> binderhub-logs.txt
docker logs "$container" >> binderhub-logs.txt 2>&1
done

- name: Upload OAuth BinderHub logs
if: always() && env.BINDERHUB_ENABLED == 'true'
uses: actions/upload-artifact@v4
with:
name: binderhub-logs-${{ matrix.test-group.name }}
path: e2e-tests/binderhub-logs.txt
retention-days: 7

- name: Collect TLJH logs
if: always() && env.JUPYTERHUB_ENABLED == 'true'
run: |
Expand Down Expand Up @@ -1688,6 +1733,11 @@ jobs:
run: |
.github/scripts/setup_weko.sh down ../weko

- name: Stop OAuth BinderHub stack
if: always() && env.BINDERHUB_ENABLED == 'true'
working-directory: e2e-tests
run: .github/scripts/setup_binderhub.sh down

- name: Stop TLJH stack
if: always() && env.JUPYTERHUB_ENABLED == 'true'
working-directory: e2e-tests
Expand Down
2 changes: 2 additions & 0 deletions docker/binderhub/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.state
__pycache__
1 change: 1 addition & 0 deletions docker/binderhub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.state/
12 changes: 12 additions & 0 deletions docker/binderhub/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.12-slim-trixie
# Use the host daemon through the socket; only its CLI belongs in this image.
RUN apt-get update && apt-get install -y --no-install-recommends git nodejs npm docker-cli docker-buildx ca-certificates patch && docker --version && docker buildx version && rm -rf /var/lib/apt/lists/*
RUN npm install -g configurable-http-proxy
ARG BINDERHUB_REV=9282cd4d
RUN git clone https://github.com/RCOSDP/CS-binderhub.git /opt/binderhub && cd /opt/binderhub && git checkout "$BINDERHUB_REV"
# The local builder must forward per-request RDM credentials, as the Kubernetes builder does.
COPY local-build-optional-envs.patch /tmp/local-build-optional-envs.patch
RUN cd /opt/binderhub && patch -p1 < /tmp/local-build-optional-envs.patch && pip install . dockerspawner
WORKDIR /opt/e2e
COPY jupyterhub_config.py binderhub_config.py rdm_spawner.py ./
CMD ["jupyterhub", "--config=/opt/e2e/jupyterhub_config.py"]
39 changes: 39 additions & 0 deletions docker/binderhub/binderhub_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json
from urllib.parse import urlsplit
from pathlib import Path
from binderhub.build_local import LocalRepo2dockerBuild
from binderhub.quota import LaunchQuota

root = Path(__file__).resolve().parent
d = json.loads((root / '.state/config.json').read_text())
c = get_config() # noqa
# CS forks use this host list for browser CORS responses (health checks and builds).
c.BinderHub.allowed_hosts = [urlsplit(d['rdm_origin']).hostname]
c.BinderHub.use_registry = False
c.BinderHub.builder_required = False
c.BinderHub.build_class = LocalRepo2dockerBuild
c.BinderHub.launch_quota_class = LaunchQuota
# RDM checks /health at the origin root; serve BinderHub on its own public origin.
c.BinderHub.base_url = '/'
c.HubOAuth.base_url = '/'
c.HubOAuth.hub_host = d['hub_origin']
c.HubOAuth.oauth_redirect_uri = d['binder_origin']+'/oauth_callback'
c.BinderHub.hub_url = d['hub_origin'] + '/'
c.BinderHub.auth_enabled = True
c.Launcher.allow_named_servers = True
c.Launcher.named_server_limit_per_user = 10
c.BinderHub.oauth2_provider_enabled = True
c.BinderHub.oauth_db_url = 'sqlite:///' + str(root / '.state/binderhub-oauth.sqlite')
c.BinderHub.oauth_clients = [dict(client_id='rdm-binder', client_secret=d['binder_secret'],
redirect_uri=d['rdm_origin']+'/project/binderhub/callback', description='RDM E2E')]
c.BinderHub.oauth_no_confirm_list = ['rdm-binder']
# RDM's frontend handles the provider's `auth` event by creating a personal
# token and retrying with repo_token. The provider must still be able to build
# that event's authorization URL; these client metadata are not exchanged with
# fakecas (which does not implement repository OAuth).
c.RDMProvider.hosts = [{
'hostname': [d['rdm_origin']], 'api': d['rdm_api'],
'client_id': 'binderhub-e2e-repository',
'scope': ['osf.full_read', 'osf.full_write'],
'oauth_authorize_url': 'http://192.168.168.167:8080/oauth2.0/authorize',
}]
9 changes: 9 additions & 0 deletions docker/binderhub/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
hub:
build: .
network_mode: host
environment:
OAUTHLIB_INSECURE_TRANSPORT: '1'
volumes:
- ./.state:/opt/e2e/.state
- /var/run/docker.sock:/var/run/docker.sock
54 changes: 54 additions & 0 deletions docker/binderhub/jupyterhub_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""OAuth Hub used by the existing RDM E2E Notebook suite (Linux Docker host)."""
import json
from pathlib import Path
import sys
from urllib.parse import urlsplit
root = Path(__file__).resolve().parent
sys.path.insert(0, str(root))
from rdm_spawner import LocalContainerSpawner # noqa: E402

d = json.loads((root / '.state/config.json').read_text())
c = get_config() # noqa
# CS forks use this host list for browser CORS responses (health checks and builds).
c.JupyterHub.allowed_hosts = [urlsplit(d['rdm_origin']).hostname]


# RDM already uses ports 8000 (API) and 8001 (admin).
c.JupyterHub.bind_url = 'http://0.0.0.0:18000'
c.ConfigurableHTTPProxy.api_url = 'http://127.0.0.1:18001'
c.JupyterHub.hub_port = 18081
c.JupyterHub.hub_ip = '0.0.0.0'
c.JupyterHub.hub_connect_ip = d['host_ip']
c.JupyterHub.db_url = 'sqlite:///' + str(root / '.state/jupyterhub.sqlite')
c.JupyterHub.pid_file = str(root / '.state/jupyterhub.pid')
c.JupyterHub.cookie_secret_file = str(root / '.state/jupyterhub_cookie_secret')
c.JupyterHub.authenticator_class = 'dummy'
c.Authenticator.allowed_users = {d['username']}
c.DummyAuthenticator.password = d['password']
c.JupyterHub.spawner_class = LocalContainerSpawner
LocalContainerSpawner.rdmfs_mount_root = d['mount_root']
LocalContainerSpawner.rdmfs_local_root = str(root / '.state/rdmfs')
c.JupyterHub.allow_named_servers = True
c.JupyterHub.named_server_limit_per_user = 10
c.LocalContainerSpawner.auth_enabled = True
c.LocalContainerSpawner.start_timeout = 180
c.LocalContainerSpawner.http_timeout = 120
c.DockerSpawner.allowed_images = '*'
c.DockerSpawner.remove = True
c.DockerSpawner.name_template = 'rdm-e2e-binder-{username}-{servername}'
c.JupyterHub.default_url = '/hub/home'
c.JupyterHub.load_roles = [
{'name': 'user', 'scopes': ['self', 'access:services!service=binder', 'access:services!service=rdm']},
]
c.JupyterHub.services = [
{'name': 'binder', 'admin': True, 'oauth_no_confirm': True,
'url': 'http://127.0.0.1:18010',
'oauth_redirect_uri': d['binder_origin']+'/oauth_callback',
'command': [sys.executable, '-m', 'binderhub', '--config='+str(root / 'binderhub_config.py'), '--port=18010'],
'environment': {'OAUTHLIB_INSECURE_TRANSPORT': '1',
'JUPYTERHUB_HOST': d['hub_origin'],
'JUPYTERHUB_OAUTH_CALLBACK_URL': d['binder_origin']+'/oauth_callback'}},
{'name': 'rdm', 'api_token': d['hub_secret'], 'oauth_client_id': 'service-rdm',
'oauth_redirect_uri': d['rdm_origin']+'/project/binderhub/callback', 'oauth_no_confirm': False},
{'name': 'rdm-token-admin', 'admin': True, 'api_token': d['admin_token']},
]
4 changes: 4 additions & 0 deletions docker/binderhub/local-build-optional-envs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--- a/binderhub/build_local.py
+++ b/binderhub/build_local.py
@@ -139,0 +140 @@
+ env.update(self.optional_envs or {})
Loading
Loading