diff --git a/README.md b/README.md index bcc9a571c4a9aa22ad936df6b4ed27afe7538ef1..e9e1631c2382c7a4e15a7c9398fa0218a1e8687d 100644 --- a/README.md +++ b/README.md @@ -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 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 # 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: ``` -## Build and run +### Build and run ```shell 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_ __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, -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 -docker-compose down # should remove the container jupyterhub -docker rm $(docker ps -qa -f "name=jupyter-") # should remove the jupyter-<username> containers +docker-compose down && docker rm $(docker ps -qa -f "name=jupyter-") ``` +## 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 diff --git a/jupyterhub-rstudio-gitlab/.env b/jupyterhub-rstudio-gitlab/.env index ab31af03def50891517b2f5f763b255f28c954e0..fc045d10e282b8c774da9a04b349bb934b2c3bb8 100644 --- a/jupyterhub-rstudio-gitlab/.env +++ b/jupyterhub-rstudio-gitlab/.env @@ -1,5 +1,5 @@ # Name of our Docker Compose project -COMPOSE_PROJECT_NAME=rocker_binder -OAUTH_CALLBACK_URL= # "https://<jupyterhub_server>/hub/oauth_callback", same has to be written in the gitlab application form +COMPOSE_PROJECT_NAME=rocker_binder_gitlab +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_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxx" # iven by gitlab application +GITLAB_CLIENT_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # given by gitlab application diff --git a/jupyterhub-rstudio-gitlab/docker-compose.yml b/jupyterhub-rstudio-gitlab/docker-compose.yml index 9bca46016b99b98925ffdc822553fb3867b1b528..e2b3b65c59aeda500eabf5b788892256ea0c2fcf 100644 --- a/jupyterhub-rstudio-gitlab/docker-compose.yml +++ b/jupyterhub-rstudio-gitlab/docker-compose.yml @@ -8,6 +8,7 @@ services: container_name: ${COMPOSE_PROJECT_NAME}_hub # The service will use this container name. volumes: # Give access to Docker socket. - /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. DOCKER_JUPYTER_IMAGE: rstudio_img DOCKER_NETWORK_NAME: ${COMPOSE_PROJECT_NAME}_default diff --git a/jupyterhub-rstudio-gitlab/jupyterhub/jupyterhub_config.py b/jupyterhub-rstudio-gitlab/jupyterhub/jupyterhub_config.py index b99c6b7d5280a276cd8b2429ac3114175f10d511..ebc706fc0f74d25cbb46e7c64405e04390b84e1d 100644 --- a/jupyterhub-rstudio-gitlab/jupyterhub/jupyterhub_config.py +++ b/jupyterhub-rstudio-gitlab/jupyterhub/jupyterhub_config.py @@ -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_secret = os.environ['GITLAB_CLIENT_SECRET'] 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 diff --git a/jupyterhub-rstudio/rstudio/Dockerfile b/jupyterhub-rstudio/rstudio/Dockerfile index c92a47629f465494061252dd909739538e46ab3e..9bd1d86d6db3278a36280123b247c37c083bf9b6 100644 --- a/jupyterhub-rstudio/rstudio/Dockerfile +++ b/jupyterhub-rstudio/rstudio/Dockerfile @@ -1,10 +1,10 @@ -FROM rocker/binder:a6bef4d6eb4b +FROM rocker/binder:4.2.1 ARG JUPYTERHUB_VERSION=3.0.0 USER root RUN pip3 install --no-cache \ - jupyterhub==$JUPYTERHUB_VERSION notebook - + jupyterhub==$JUPYTERHUB_VERSION + USER ${NB_USER} WORKDIR /home/${NB_USER} CMD ["jupyterhub-singleuser"]