Deploying Jupyter Notebooks For Students and Researchers
Deploying Jupyter Notebooks For Students and Researchers
• Document
• Environment
• Web app
https://github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
What is a Notebook
Server?
• Manages authentication
pip, npm:
python3 -m pip install jupyterhub
npm install -g configurable-http-proxy
test:
jupyterhub -h
configurable-http-proxy -h
Installation (this repo)
https://conda-forge.github.io
https://docs.docker.com/engine/installation
key: /etc/letsencrypt/live/mydomain.tld/privkey.pem
cert: /etc/letsencrypt/live/mydomain.tld/fullchain.pem
Start configuring JupyterHub
jupyterhub --generate-config
c.JupyterHub.ssl_key = 'jupyterhub.key'
c.JupyterHub.ssl_cert = 'jupyterhub.crt'
c.JupyterHub.port = 443
Installing kernels for all users
In ./env:
export GITHUB_CLIENT_ID=from_github
export GITHUB_CLIENT_SECRET=from_github
export OAUTH_CALLBACK_URL=https://YOURDOMAIN/hub/oauth_callback
source ./env
Using GitHub OAuth
We need OAuthenticator:
In jupyterhub_config.py:
In jupyterhub_config.py:
• Networking configuration
• Data volumes
• DockerSpawner.container_image = 'jupyterhub/singleuser'
Customizing
Spawners
JupyterHub with supervisor
apt-get install supervisor
# /etc/supervisor/conf.d/jupyterhub.conf
[program:jupyterhub]
command=bash launch.sh
directory=/srv/jupyterhub
#!/usr/bin/env bash autostart=true
# /srv/jupyterhub/launch.sh autorestart=true
set -e startretries=3
source env exitcodes=0,2
exec jupyterhub $@ stopsignal=TERM
redirect_stderr=true
stdout_logfile=/var/log/jupyterhub.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
user=root
Reference Deployments
https://github.com/jupyterhub/jupyterhub-deploy-docker
docker-compose, DockerSpawner, Hub in Docker
https://github.com/jupyterhub/jupyterhub-deploy-teaching
ansible, no docker, nbgrader
Docker Deployment
• Docker Compose: https://docs.docker.com/compose/install/
• Create a network:
docker network create jupyterhub-network
• mkdir secrets
• secrets/jupyterhub.cer (cert)
• secrets/jupyterhub.key (key)
Docker Deployment
Make userlist:
minrk admin
takluyver
Docker Deployment
Launch: 🚀
docker-compose up
Optimizations
and best practices
• Always use SSL!