Skip to content

Commit

Permalink
Adds jupyterhub support
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalsh committed Jul 11, 2019
1 parent 024f7ce commit 2d18399
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 52 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
135 changes: 85 additions & 50 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ services:
# specific sites
- ./nginx/etc/nginx/sites-enabled/bmegio.ohsu.edu:/etc/nginx/sites-enabled/bmegio.ohsu.edu:ro
- ./nginx/etc/nginx/sites-enabled/gen3-ohsu.ddns.net:/etc/nginx/sites-enabled/gen3-ohsu.ddns.net:ro
- ./nginx/etc/nginx/sites-enabled/bmeg-jupyter.ddns.net:/etc/nginx/sites-enabled/bmeg-jupyter.ddns.net:ro
- ./nginx/etc/nginx/sites-enabled/bmeg.io:/etc/nginx/sites-enabled/bmeg.io:ro


# for letsencrypt
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
Expand All @@ -59,6 +61,7 @@ services:

depends_on:
- grip
- jupyterhub


# for letsencrypt
Expand Down Expand Up @@ -86,60 +89,92 @@ services:
- grip
- mongo


# https://github.com/jupyterhub/jupyterhub-deploy-docker
# jupyterhub database
hub-db:
image: postgres:9.5
container_name: jupyterhub-db
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
PGDATA: ${DB_VOLUME_CONTAINER}
env_file:
- secrets/jupyter.env
volumes:
- "db:${DB_VOLUME_CONTAINER}"

# jupyterhub
hub:
depends_on:
- hub-db
build:
context: jupyterhub
args:
JUPYTERHUB_VERSION: ${JUPYTERHUB_VERSION}
restart: always
image: jupyterhub
container_name: jupyterhub
volumes:
# Bind Docker socket on the host so we can connect to the daemon from
# within the container
- "/var/run/docker.sock:/var/run/docker.sock:rw"
# Bind Docker volume on host for JupyterHub database and cookie secrets
- "data:${DATA_VOLUME_CONTAINER}"
# see https://opendreamkit.org/2018/10/17/jupyterhub-docker/
jupyterhub:
build: jupyterhub # Build the container from this folder.
container_name: jupyterhub # The service will use this container name.
volumes: # Give access to Docker socket.
- /var/run/docker.sock:/var/run/docker.sock
# - ./data/certbot/conf/live/bmegio.ohsu.edu/cert.pem:/etc/letsencrypt/cert.pem
# - ./data/certbot/conf/live/bmegio.ohsu.edu/privkey.pem:/etc/letsencrypt/privkey.pem
- ./secrets/userlist:/srv/jupyterhub/userlist
- ./secrets/jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py
ports:
- "443:443"
links:
- hub-db
environment:
POSTGRES_HOST: hub-db
- /mnt/data1/bmeg/jupyter-data:/data
environment: # Env variables passed to the Hub process.
DOCKER_NOTEBOOK_IMAGE: jupyterlab_img
DOCKER_NETWORK_NAME: deployment_default
HUB_IP: jupyterhub
# SSL_KEY: /etc/letsencrypt/privkey.pem
# SSL_CERT: /etc/letsencrypt/cert.pem
env_file:
- secrets/jupyter.env
- secrets/oauth.env
command: >
jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
# docker volume create --name=jupyterhub-data
# docker volume create --name=jupyterhub-db-data
volumes:
data:
external:
name: ${DATA_VOLUME_HOST}
db:
external:
name: ${DB_VOLUME_HOST}
depends_on:
- grip

# notebook image, build via: `dc build jupyterlab`
# The extra line command: echo is there so that,
# when Docker Compose starts the service, it terminates immediately.
# Indeed this image is meant to be loaded by the Hub, not by Compose.
jupyterlab:
build: jupyterlab
image: jupyterlab_img
command: echo


# # https://github.com/jupyterhub/jupyterhub-deploy-docker
# # jupyterhub database
# hub-db:
# image: postgres:9.5
# container_name: jupyterhub-db
# restart: always
# environment:
# POSTGRES_DB: ${POSTGRES_DB}
# PGDATA: ${DB_VOLUME_CONTAINER}
# env_file:
# - secrets/jupyter.env
# volumes:
# - "db:${DB_VOLUME_CONTAINER}"
#
# # jupyterhub
# hub:
# depends_on:
# - hub-db
# build:
# context: jupyterhub
# args:
# JUPYTERHUB_VERSION: ${JUPYTERHUB_VERSION}
# # restart: always
# # image: jupyterhub
# container_name: jupyterhub
# volumes:
# # Bind Docker socket on the host so we can connect to the daemon from
# # within the container
# - "/var/run/docker.sock:/var/run/docker.sock:rw"
# # Bind Docker volume on host for JupyterHub database and cookie secrets
# - "data:${DATA_VOLUME_CONTAINER}"
# # - ./secrets/jupyterhub_config.py:/srv/jupyterhub/jupyterhub_config.py
# ports:
# - "443:443"
# links:
# - hub-db
# environment:
# POSTGRES_HOST: hub-db
# env_file:
# - secrets/jupyter.env
# - secrets/oauth.env
# command: >
# jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
#
# # docker volume create --name=jupyterhub-data
# # docker volume create --name=jupyterhub-db-data
# volumes:
# data:
# external:
# name: ${DATA_VOLUME_HOST}
# db:
# external:
# name: ${DB_VOLUME_HOST}

# networks:
# default:
Expand Down
14 changes: 14 additions & 0 deletions jupyterhub/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Do not forget to pin down the version
FROM jupyterhub/jupyterhub:1.0.0

# OLD: Copy the JupyterHub configuration in the container
# COPY jupyterhub_config.py .
# NEW: map as volume -> /srv/jupyterhub/jupyterhub_config.py

# Download script to automatically stop idle single-user servers
RUN wget https://raw.githubusercontent.com/jupyterhub/jupyterhub/1.0.0/examples/cull-idle/cull_idle_servers.py

# Install dependencies (for advanced authentication and spawning)
RUN pip install \
dockerspawner==0.11.1 \
oauthenticator==0.8.2
9 changes: 9 additions & 0 deletions jupyterlab/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM jupyter/scipy-notebook:6c3390a9292e
RUN pip install --pre jupyterhub==1.0.0

# RUN pip install jupyterhub==1.0.0

# RUN conda install --quiet --yes \
# 'r-base=3.4.1' \
# 'r-irkernel=0.8*'&& \
# conda clean -tipsy
4 changes: 2 additions & 2 deletions nginx/etc/nginx/grip.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
lua_ssl_verify_depth 5;

set_by_lua $ngo_callback_host '
if os.getenv("NGO_CALLBACK_HOST") then
return os.getenv("NGO_CALLBACK_HOST")
Expand Down Expand Up @@ -54,7 +54,7 @@
# our protected "landing page"
location /analyze/access {
include /etc/nginx/protected.conf;
root /usr/share/nginx/html;
root /usr/share/nginx/bmegio.ohsu.edu;
try_files $uri $uri/index.html $uri.html =404;
}
location /grip/ {
Expand Down
1 change: 1 addition & 0 deletions nginx/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ http {
include /etc/nginx/sites-enabled/bmeg.io;
include /etc/nginx/sites-enabled/bmegio.ohsu.edu;
include /etc/nginx/sites-enabled/gen3-ohsu.ddns.net;
include /etc/nginx/sites-enabled/bmeg-jupyter.ddns.net;
}
43 changes: 43 additions & 0 deletions nginx/etc/nginx/sites-enabled/bmeg-jupyter.ddns.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# top-level http config for websocket headers
# If Upgrade is defined, Connection = upgrade
# If Upgrade is empty, Connection = close
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}


# redirect to https
server {
listen *:80;
server_name bmeg-jupyter.ddns.net;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;

server_name bmeg-jupyter.ddns.net;
ssl_certificate /etc/letsencrypt/live/bmeg-jupyter.ddns.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/bmeg-jupyter.ddns.net/privkey.pem;


# Managing literal requests to the JupyterHub front end
location / {
proxy_pass http://jupyterhub:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# websocket headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

# for certbot challenge
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}

}

0 comments on commit 2d18399

Please sign in to comment.