Merge pull request #37 from minrk/postgres
use postgres for the database
This commit is contained in:
commit
a9dfabe7c5
9
.env
9
.env
@ -30,3 +30,12 @@ DATA_VOLUME_HOST=jupyterhub-data
|
|||||||
|
|
||||||
# Data volume container mount point
|
# Data volume container mount point
|
||||||
DATA_VOLUME_CONTAINER=/data
|
DATA_VOLUME_CONTAINER=/data
|
||||||
|
|
||||||
|
# Name of JupyterHub postgres database data volume
|
||||||
|
DB_VOLUME_HOST=jupyterhub-db-data
|
||||||
|
|
||||||
|
# Postgres volume container mount point
|
||||||
|
DB_VOLUME_CONTAINER=/var/lib/postgresql/data/jupyterhub
|
||||||
|
|
||||||
|
# The name of the postgres database containing JupyterHub state
|
||||||
|
POSTGRES_DB=jupyterhub
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
FROM jupyterhub/jupyterhub-onbuild:0.7.2
|
FROM jupyterhub/jupyterhub-onbuild:0.7.2
|
||||||
|
|
||||||
# Install dockerspawner and its dependencies
|
# Install dockerspawner, oauth, postgres
|
||||||
RUN /opt/conda/bin/pip install \
|
RUN /opt/conda/bin/conda install psycopg2=2.7 && \
|
||||||
|
/opt/conda/bin/conda clean -tipsy && \
|
||||||
|
/opt/conda/bin/pip install \
|
||||||
oauthenticator==0.5.* \
|
oauthenticator==0.5.* \
|
||||||
dockerspawner==0.7.*
|
dockerspawner==0.7.*
|
||||||
|
|
||||||
|
7
Makefile
7
Makefile
@ -10,10 +10,15 @@ network:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
@docker volume inspect $(DATA_VOLUME_HOST) >/dev/null 2>&1 || docker volume create --name $(DATA_VOLUME_HOST)
|
@docker volume inspect $(DATA_VOLUME_HOST) >/dev/null 2>&1 || docker volume create --name $(DATA_VOLUME_HOST)
|
||||||
|
@docker volume inspect $(DB_VOLUME_HOST) >/dev/null 2>&1 || docker volume create --name $(DB_VOLUME_HOST)
|
||||||
|
|
||||||
self-signed-cert:
|
self-signed-cert:
|
||||||
# make a self-signed cert
|
# make a self-signed cert
|
||||||
|
|
||||||
|
secrets/postgres.env:
|
||||||
|
@echo "Generating postgres password in $@"
|
||||||
|
@echo "POSTGRES_PASSWORD=$(shell openssl rand -hex 32)" > $@
|
||||||
|
|
||||||
secrets/jupyterhub.crt:
|
secrets/jupyterhub.crt:
|
||||||
@echo "Need an SSL certificate in secrets/jupyterhub.crt"
|
@echo "Need an SSL certificate in secrets/jupyterhub.crt"
|
||||||
@exit 1
|
@exit 1
|
||||||
@ -36,7 +41,7 @@ else
|
|||||||
cert_files=
|
cert_files=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
check-files: userlist $(cert_files)
|
check-files: userlist $(cert_files) secrets/oauth.env secrets/postgres.env
|
||||||
|
|
||||||
pull:
|
pull:
|
||||||
docker pull $(DOCKER_NOTEBOOK_IMAGE)
|
docker pull $(DOCKER_NOTEBOOK_IMAGE)
|
||||||
|
@ -5,10 +5,25 @@
|
|||||||
version: "2"
|
version: "2"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
hub-db:
|
||||||
|
image: postgres:9.5
|
||||||
|
container_name: jupyterhub-db
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
|
PGDATA: ${DB_VOLUME_CONTAINER}
|
||||||
|
env_file:
|
||||||
|
- secrets/postgres.env
|
||||||
|
volumes:
|
||||||
|
- "db:${DB_VOLUME_CONTAINER}"
|
||||||
|
|
||||||
hub:
|
hub:
|
||||||
|
depends_on:
|
||||||
|
- hub-db
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile.jupyterhub
|
dockerfile: Dockerfile.jupyterhub
|
||||||
|
restart: always
|
||||||
image: jupyterhub
|
image: jupyterhub
|
||||||
container_name: jupyterhub
|
container_name: jupyterhub
|
||||||
volumes:
|
volumes:
|
||||||
@ -19,6 +34,8 @@ services:
|
|||||||
- "data:${DATA_VOLUME_CONTAINER}"
|
- "data:${DATA_VOLUME_CONTAINER}"
|
||||||
ports:
|
ports:
|
||||||
- "443:443"
|
- "443:443"
|
||||||
|
links:
|
||||||
|
- hub-db
|
||||||
environment:
|
environment:
|
||||||
# All containers will join this network
|
# All containers will join this network
|
||||||
DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}
|
DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}
|
||||||
@ -28,10 +45,12 @@ services:
|
|||||||
DOCKER_NOTEBOOK_DIR: ${DOCKER_NOTEBOOK_DIR}
|
DOCKER_NOTEBOOK_DIR: ${DOCKER_NOTEBOOK_DIR}
|
||||||
# Using this run command (optional)
|
# Using this run command (optional)
|
||||||
DOCKER_SPAWN_CMD: ${DOCKER_SPAWN_CMD}
|
DOCKER_SPAWN_CMD: ${DOCKER_SPAWN_CMD}
|
||||||
# Required to authenticate users using GitHub OAuth
|
# Postgres db info
|
||||||
GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
|
POSTGRES_DB: ${POSTGRES_DB}
|
||||||
GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}
|
POSTGRES_HOST: hub-db
|
||||||
OAUTH_CALLBACK_URL: ${OAUTH_CALLBACK_URL}
|
env_file:
|
||||||
|
- secrets/postgres.env
|
||||||
|
- secrets/oauth.env
|
||||||
command: >
|
command: >
|
||||||
jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
|
jupyterhub -f /srv/jupyterhub/jupyterhub_config.py
|
||||||
|
|
||||||
@ -39,6 +58,9 @@ volumes:
|
|||||||
data:
|
data:
|
||||||
external:
|
external:
|
||||||
name: ${DATA_VOLUME_HOST}
|
name: ${DATA_VOLUME_HOST}
|
||||||
|
db:
|
||||||
|
external:
|
||||||
|
name: ${DB_VOLUME_HOST}
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
|
@ -57,10 +57,16 @@ c.GitHubOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL']
|
|||||||
|
|
||||||
# Persist hub data on volume mounted inside container
|
# Persist hub data on volume mounted inside container
|
||||||
data_dir = os.environ.get('DATA_VOLUME_CONTAINER', '/data')
|
data_dir = os.environ.get('DATA_VOLUME_CONTAINER', '/data')
|
||||||
c.JupyterHub.db_url = os.path.join('sqlite:///', data_dir, 'jupyterhub.sqlite')
|
|
||||||
c.JupyterHub.cookie_secret_file = os.path.join(data_dir,
|
c.JupyterHub.cookie_secret_file = os.path.join(data_dir,
|
||||||
'jupyterhub_cookie_secret')
|
'jupyterhub_cookie_secret')
|
||||||
|
|
||||||
|
c.JupyterHub.db_url = 'postgresql://postgres:{password}@{host}/{db}'.format(
|
||||||
|
host=os.environ['POSTGRES_HOST'],
|
||||||
|
password=os.environ['POSTGRES_PASSWORD'],
|
||||||
|
db=os.environ['POSTGRES_DB'],
|
||||||
|
)
|
||||||
|
|
||||||
# Whitlelist users and admins
|
# Whitlelist users and admins
|
||||||
c.Authenticator.whitelist = whitelist = set()
|
c.Authenticator.whitelist = whitelist = set()
|
||||||
c.Authenticator.admin_users = admin = set()
|
c.Authenticator.admin_users = admin = set()
|
||||||
|
Loading…
Reference in New Issue
Block a user