diff --git a/examples/postgres_db/Dockerfile b/examples/postgres_db/Dockerfile new file mode 100644 index 00000000..97a1596b --- /dev/null +++ b/examples/postgres_db/Dockerfile @@ -0,0 +1,5 @@ +FROM postgres:9.3 +RUN mkdir /docker-entrypoint-initdb.d +COPY initdb.sh /docker-entrypoint-initdb.d/init.sh +# Set your own password here. +ENV JPY_PSQL_PASSWORD arglebargle diff --git a/examples/postgres_db/README.md b/examples/postgres_db/README.md new file mode 100644 index 00000000..e69de29b diff --git a/examples/postgres_db/initdb.sh b/examples/postgres_db/initdb.sh new file mode 100644 index 00000000..a8cb585d --- /dev/null +++ b/examples/postgres_db/initdb.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Start a postgres daemon, ignoring log output. + +gosu postgres pg_ctl start -w -l /dev/null + +gosu postgres psql -c "CREATE DATABASE jupyterhub;" +gosu postgres psql -c "CREATE USER jupyterhub WITH ENCRYPTED PASSWORD '$JPY_PSQL_PASSWORD';" +gosu postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE jupyterhub TO jupyterhub;" + +# Alter pg_hba.conf to actually require passwords. +# The default image exposes allows any user to connect without requiring a +# password. +sed -ri -e 's/(host all all 0.0.0.0\/0 )(trust)/\1md5/' "$PGDATA"/pg_hba.conf + +gosu postgres pg_ctl stop -w