# HG changeset patch # User smith@nwoca.org # Date 1442062620 14400 # Node ID 0cdc167e631984cb18c964eb54ee4a6bccd11ef6 # Parent 1bf338a321723b47a5a1f65019a30c926c8845ab DEP-2: postgres dockerfile diff -r 1bf338a32172 -r 0cdc167e6319 postgres/Dockerfile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/postgres/Dockerfile Sat Sep 12 08:57:00 2015 -0400 @@ -0,0 +1,17 @@ +# +# Docker file to create postgres image for ssdt applications + +FROM postgres:9.4.4 + +MAINTAINER Dave Smith smith@nwoca.org + +ENV PGDATA /var/lib/postgresql/data/pgdata +ENV DB_NAME database +ENV DB_USER dbuser +ENV DB_PASS dbpassword + +VOLUME "/var/log/postgresql" + +COPY setupDatabase.sh /docker-entrypoint-initdb.d/setupDatabase.sh + +RUN chmod 755 /docker-entrypoint-initdb.d/setupDatabase.sh \ No newline at end of file diff -r 1bf338a32172 -r 0cdc167e6319 postgres/setupDatabase.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/postgres/setupDatabase.sh Sat Sep 12 08:57:00 2015 -0400 @@ -0,0 +1,23 @@ +#!/bin/bash + +export PGUSER=postgres +TEST=`psql <<- EOSQL + SELECT 1 FROM pg_database WHERE datname='$DB_NAME'; +EOSQL` + +if [[ $TEST == "1" ]]; then + echo "$DB_NAME exists. continuing startup." + # database exists + # $? is 0 + exit 0 +else +echo "Creating $DB_NAME for $DB_USER" +psql <<- EOSQL + CREATE ROLE $DB_USER WITH LOGIN ENCRYPTED PASSWORD '${DB_PASS}' CREATEDB; + CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0 ENCODING 'UTF8'; + GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER; +EOSQL +fi + +echo "" +echo "$DB_NAME database created"