Commit 08cc4b18 authored by Florian de Boissieu's avatar Florian de Boissieu
Browse files

update examples and documentation

parent f385dec9
No related merge requests found
Showing with 59 additions and 14 deletions
+59 -14
...@@ -32,9 +32,6 @@ dockerspawner to launch a user docker, and a `jupyterhub_config.py` file to conf ...@@ -32,9 +32,6 @@ dockerspawner to launch a user docker, and a `jupyterhub_config.py` file to conf
# Do not forget to pin down the version # Do not forget to pin down the version
FROM jupyterhub/jupyterhub:3.0.0 FROM jupyterhub/jupyterhub:3.0.0
# Copy the JupyterHub configuration in the container
COPY jupyterhub_config.py .
# Download script to automatically stop idle single-user servers # Download script to automatically stop idle single-user servers
# RUN wget https://raw.githubusercontent.com/jupyterhub/jupyterhub/0.9.3/examples/cull-idle/cull_idle_servers.py # RUN wget https://raw.githubusercontent.com/jupyterhub/jupyterhub/0.9.3/examples/cull-idle/cull_idle_servers.py
...@@ -75,7 +72,7 @@ File `docker-compose.yml` contains: ...@@ -75,7 +72,7 @@ File `docker-compose.yml` contains:
``` ```
## Build and run ### Build and run
```shell ```shell
docker-compose build --no-cache # builds without keeping docker layers in cache docker-compose build --no-cache # builds without keeping docker layers in cache
...@@ -90,12 +87,58 @@ Then try to sign in from the browser at http://localhost:8000 or http://<server_ ...@@ -90,12 +87,58 @@ Then try to sign in from the browser at http://localhost:8000 or http://<server_
__Warning:__ the user containers are persistent so that it is not reinitialized at each start of the hub, __Warning:__ the user containers are persistent so that it is not reinitialized at each start of the hub,
which is a pretty nice thing. However, it means that if you want to clean completely the hub __and__ the user containers, which is a pretty nice thing. However, it means that if you want to clean completely the hub __and__ the user containers,
you need to remove specifically the user containers in addition to setting down the services: you need to remove specifically the user containers in addition to setting down the services.
The following code should remove jupyterhub and user containers respectively.
```shell ```shell
docker-compose down # should remove the container jupyterhub docker-compose down && docker rm $(docker ps -qa -f "name=jupyter-")
docker rm $(docker ps -qa -f "name=jupyter-") # should remove the jupyter-<username> containers
``` ```
## Rstudio
An Rstudio-session can be launched from inside a jupyterlab session with
[jupyter-rsession-proxy](https://github.com/jupyterhub/jupyter-rsession-proxy).
The docker image [rocker/binder](https://rocker-project.org/images/versioned/binder.html) and
specially script [install_jupyter.sh](https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_jupyter.sh)
gives a good example of how it can be done. Actually it installs JupyterLab, jupyter-rsession-proxy and IRkernel
on top of the rocker/geospatial image, and defines the default command with jupyterhub-singleuser
making the container controllable by jupyterhub.
The directory `jupyterhub-rstudio` shows an example of such a configuration.
Following [jupyterhub documentation](https://jupyterhub-dockerspawner.readthedocs.io/en/latest/docker-image.html#how-to-build-your-own-docker-image)
the image rocker/binder is adapted to be spawn by jupyterhub:
```docker
FROM rocker/binder:4.2.1
ARG JUPYTERHUB_VERSION=3.0.0
USER root
RUN pip3 install --no-cache \
jupyterhub==$JUPYTERHUB_VERSION
USER ${NB_USER}
WORKDIR /home/${NB_USER}
CMD ["jupyterhub-singleuser"]
```
One can notice that no user is created as there is a default user named "rstudio" in rocker images.
A section is then added to `docker-compose.yml` in order to configure the build of rstudio image, named here `rstudio_img`
and its call by jupyterhub.
Use command lines of section [Build and run] to run and access the server.
## Adding GitLab OAuth
Directory `jupyterhub-rstudio-gitlab` is showing an example with on the way to configure jupyterhub in order to call GitLab OAuth
as authenticator. In order to do so, :
- package oautenticator is installed in jupyterhub docker image.
- an application has to be defined in gitlab user settings: it needs scope read_user.
The URI is defined with https://<jupyterhub server>/hub/oauth_callback.
- a section is added in jupyterhub_config.py using the URI, the client ID and client secret defined in the gitlab application.
These variables are stored in .env file and called in jupyterhub_config.py.
# Authors # Authors
......
# Name of our Docker Compose project # Name of our Docker Compose project
COMPOSE_PROJECT_NAME=rocker_binder COMPOSE_PROJECT_NAME=rocker_binder_gitlab
OAUTH_CALLBACK_URL= # "https://<jupyterhub_server>/hub/oauth_callback", same has to be written in the gitlab application form OAUTH_CALLBACK_URL= "https://<jupyterhub_server>/hub/oauth_callback" # the same link has to be written in the gitlab application form in section URI
GITLAB_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # given by gitlab application GITLAB_CLIENT_ID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # given by gitlab application
GITLAB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxx" # iven by gitlab application GITLAB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # given by gitlab application
...@@ -8,6 +8,7 @@ services: ...@@ -8,6 +8,7 @@ services:
container_name: ${COMPOSE_PROJECT_NAME}_hub # The service will use this container name. container_name: ${COMPOSE_PROJECT_NAME}_hub # The service will use this container name.
volumes: # Give access to Docker socket. volumes: # Give access to Docker socket.
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./jupyterhub/jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py
environment: # Env variables passed to the Hub process. environment: # Env variables passed to the Hub process.
DOCKER_JUPYTER_IMAGE: rstudio_img DOCKER_JUPYTER_IMAGE: rstudio_img
DOCKER_NETWORK_NAME: ${COMPOSE_PROJECT_NAME}_default DOCKER_NETWORK_NAME: ${COMPOSE_PROJECT_NAME}_default
......
...@@ -14,7 +14,8 @@ c.GitLabOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL'] ...@@ -14,7 +14,8 @@ c.GitLabOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL']
c.GitLabOAuthenticator.client_id = os.environ['GITLAB_CLIENT_ID'] c.GitLabOAuthenticator.client_id = os.environ['GITLAB_CLIENT_ID']
c.GitLabOAuthenticator.client_secret = os.environ['GITLAB_CLIENT_SECRET'] c.GitLabOAuthenticator.client_secret = os.environ['GITLAB_CLIENT_SECRET']
c.GitLabOAuthenticator.scope = ['read_user'] # level necessary for to read users c.GitLabOAuthenticator.scope = ['read_user'] # level necessary for to read users
c.GitLabOAuthenticator.allowed_users = ['<username1>', '<username2>'] # c.GitLabOAuthenticator.allowed_users = ['<username1>', '<username2>'] # to allow specific users
# c.GitLabOAuthenticator.allowed_groups = ['<group1>', '<group2>'] # to allow whole groups
FROM rocker/binder:a6bef4d6eb4b FROM rocker/binder:4.2.1
ARG JUPYTERHUB_VERSION=3.0.0 ARG JUPYTERHUB_VERSION=3.0.0
USER root USER root
RUN pip3 install --no-cache \ RUN pip3 install --no-cache \
jupyterhub==$JUPYTERHUB_VERSION notebook jupyterhub==$JUPYTERHUB_VERSION
USER ${NB_USER} USER ${NB_USER}
WORKDIR /home/${NB_USER} WORKDIR /home/${NB_USER}
CMD ["jupyterhub-singleuser"] CMD ["jupyterhub-singleuser"]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment