changeset 36:a5175713518c

add training db images
author smith@nwoca.org
date Wed, 20 Jan 2016 13:47:23 -0500
parents 1c74d1289739
children 4cdd20de8b38
files trainingdb-usas/Dockerfile trainingdb-usps/Dockerfile trainingdb/Dockerfile trainingdb/setupDatabase.sh
diffstat 4 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trainingdb-usas/Dockerfile	Wed Jan 20 13:47:23 2016 -0500
@@ -0,0 +1,11 @@
+
+FROM docker.ssdt.io/trainingdb
+
+ADD http://files.ssdt.io/usas-training.backup.gz $BACKUP_FILE
+
+RUN chmod a+r $BACKUP_FILE
+
+env DB_NAME=usasdb \
+    DB_USER=usas \
+    DB_PASS=usasdefault
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trainingdb-usps/Dockerfile	Wed Jan 20 13:47:23 2016 -0500
@@ -0,0 +1,11 @@
+
+FROM docker.ssdt.io/trainingdb
+
+ADD http://files.ssdt.io/usps-training.backup.gz $BACKUP_FILE
+
+RUN chmod a+r $BACKUP_FILE
+
+env DB_NAME=uspsdb \
+    DB_USER=usps \
+    DB_PASS=uspsdefault
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trainingdb/Dockerfile	Wed Jan 20 13:47:23 2016 -0500
@@ -0,0 +1,13 @@
+#
+# Docker file to create postgres image for ssdt applications
+
+FROM docker.ssdt.io/ssdt-postgres:2
+
+MAINTAINER Dave Smith smith@nwoca.org
+
+ENV PGDATA=/var/pgdata/trainingdata \
+    BACKUP_FILE=/training.backup.gz
+
+COPY setupDatabase.sh /docker-entrypoint-initdb.d/
+
+RUN chmod 755 /docker-entrypoint-initdb.d/setupDatabase.sh	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trainingdb/setupDatabase.sh	Wed Jan 20 13:47:23 2016 -0500
@@ -0,0 +1,28 @@
+#!/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
+
+echo "Restoring backup file"
+
+gunzip -f $BACKUP_FILE -c | psql
+
+fi
+
+echo ""
+echo "$DB_NAME database created"