File tree Expand file tree Collapse file tree 5 files changed +52
-8
lines changed Expand file tree Collapse file tree 5 files changed +52
-8
lines changed Original file line number Diff line number Diff line change @@ -30,3 +30,12 @@ DATA_VOLUME_HOST=jupyterhub-data
3030
3131# Data volume container mount point
3232DATA_VOLUME_CONTAINER = /data
33+
34+ # Name of JupyterHub postgres database data volume
35+ DB_VOLUME_HOST = jupyterhub-db-data
36+
37+ # Postgres volume container mount point
38+ DB_VOLUME_CONTAINER = /var/lib/postgresql/data/jupyterhub
39+
40+ # The name of the postgres database containing JupyterHub state
41+ POSTGRES_DB = jupyterhub
Original file line number Diff line number Diff line change 22# Distributed under the terms of the Modified BSD License.
33FROM jupyterhub/jupyterhub-onbuild:0.7.2
44
5- # Install dockerspawner and its dependencies
6- RUN /opt/conda/bin/pip install \
5+ # Install dockerspawner, oauth, postgres
6+ RUN /opt/conda/bin/conda install psycopg2=2.7 && \
7+ /opt/conda/bin/conda clean -tipsy && \
8+ /opt/conda/bin/pip install \
79 oauthenticator==0.5.* \
810 dockerspawner==0.7.*
911
Original file line number Diff line number Diff line change @@ -10,10 +10,15 @@ network:
1010
1111volumes :
1212 @docker volume inspect $(DATA_VOLUME_HOST ) > /dev/null 2>&1 || docker volume create --name $(DATA_VOLUME_HOST )
13+ @docker volume inspect $(DB_VOLUME_HOST ) > /dev/null 2>&1 || docker volume create --name $(DB_VOLUME_HOST )
1314
1415self-signed-cert :
1516 # make a self-signed cert
1617
18+ secrets/postgres.env :
19+ @echo " Generating postgres password in $@ "
20+ @echo " POSTGRES_PASSWORD=$( shell openssl rand -hex 32) " > $@
21+
1722secrets/jupyterhub.crt :
1823 @echo " Need an SSL certificate in secrets/jupyterhub.crt"
1924 @exit 1
3641 cert_files=
3742endif
3843
39- check-files : userlist $(cert_files )
44+ check-files : userlist $(cert_files ) secrets/oauth.env secrets/postgres.env
4045
4146pull :
4247 docker pull $(DOCKER_NOTEBOOK_IMAGE )
Original file line number Diff line number Diff line change 55version : " 2"
66
77services :
8+ hub-db :
9+ image : postgres:9.5
10+ container_name : jupyterhub-db
11+ restart : always
12+ environment :
13+ POSTGRES_DB : ${POSTGRES_DB}
14+ PGDATA : ${DB_VOLUME_CONTAINER}
15+ env_file :
16+ - secrets/postgres.env
17+ volumes :
18+ - " db:${DB_VOLUME_CONTAINER}"
19+
820 hub :
21+ depends_on :
22+ - hub-db
923 build :
1024 context : .
1125 dockerfile : Dockerfile.jupyterhub
26+ restart : always
1227 image : jupyterhub
1328 container_name : jupyterhub
1429 volumes :
@@ -19,6 +34,8 @@ services:
1934 - " data:${DATA_VOLUME_CONTAINER}"
2035 ports :
2136 - " 443:443"
37+ links :
38+ - hub-db
2239 environment :
2340 # All containers will join this network
2441 DOCKER_NETWORK_NAME : ${DOCKER_NETWORK_NAME}
@@ -28,17 +45,22 @@ services:
2845 DOCKER_NOTEBOOK_DIR : ${DOCKER_NOTEBOOK_DIR}
2946 # Using this run command (optional)
3047 DOCKER_SPAWN_CMD : ${DOCKER_SPAWN_CMD}
31- # Required to authenticate users using GitHub OAuth
32- GITHUB_CLIENT_ID : ${GITHUB_CLIENT_ID}
33- GITHUB_CLIENT_SECRET : ${GITHUB_CLIENT_SECRET}
34- OAUTH_CALLBACK_URL : ${OAUTH_CALLBACK_URL}
48+ # Postgres db info
49+ POSTGRES_DB : ${POSTGRES_DB}
50+ POSTGRES_HOST : hub-db
51+ env_file :
52+ - secrets/postgres.env
53+ - secrets/oauth.env
3554 command : >
3655 jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
3756
3857volumes :
3958 data :
4059 external :
4160 name : ${DATA_VOLUME_HOST}
61+ db :
62+ external :
63+ name : ${DB_VOLUME_HOST}
4264
4365networks :
4466 default :
Original file line number Diff line number Diff line change 5757
5858# Persist hub data on volume mounted inside container
5959data_dir = os .environ .get ('DATA_VOLUME_CONTAINER' , '/data' )
60- c . JupyterHub . db_url = os . path . join ( 'sqlite:///' , data_dir , 'jupyterhub.sqlite' )
60+
6161c .JupyterHub .cookie_secret_file = os .path .join (data_dir ,
6262 'jupyterhub_cookie_secret' )
6363
64+ c .JupyterHub .db_url = 'postgresql://postgres:{password}@{host}/{db}' .format (
65+ host = os .environ ['POSTGRES_HOST' ],
66+ password = os .environ ['POSTGRES_PASSWORD' ],
67+ db = os .environ ['POSTGRES_DB' ],
68+ )
69+
6470# Whitlelist users and admins
6571c .Authenticator .whitelist = whitelist = set ()
6672c .Authenticator .admin_users = admin = set ()
You can’t perform that action at this time.
0 commit comments