changeset 149:ab4effbe8d43

DEP-12: generate unique DB passwords for application databases
author smith@nwoca.org
date Tue, 18 Jul 2017 19:39:38 +0100
parents d20c6ff9a821
children de0771f14dd0
files pilot/setup.sh
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pilot/setup.sh	Mon Jul 10 18:24:40 2017 +0100
+++ b/pilot/setup.sh	Tue Jul 18 19:39:38 2017 +0100
@@ -18,6 +18,10 @@
    md5sum -c --status ${1} ;
 }
 
+genDBHash() {
+ echo $(date +%s%N | sha256sum | base64 | head -c 32 ; echo)
+}
+
 base=$(dirname "${BASH_SOURCE[0]}")
 default_name=$(basename $PWD)
 
@@ -59,7 +63,9 @@
 
 if [ "$create" == "OK" ] 
 then
-    echo "version: \"3.3\""     > ./docker-compose.yml
+    echo "# **** DO NOT MODIFY THIS FILE. ****" > ./docker-compose.yml
+    echo "# Place customizations in docker-compose.override.yml and .env" >> ./docker-compose.yml
+    echo "version: \"3.3\""     >> ./docker-compose.yml
     echo "services:"            >> ./docker-compose.yml
 
     [ ! "$usas" == "" ] &&  cat $base/usas-services.yml >> ./docker-compose.yml
@@ -68,12 +74,21 @@
 
     echo "volumes:" >> ./docker-compose.yml
 
-    [ ! "$usas" == "" ] &&  echo "  usasdata:" >> ./docker-compose.yml
-    [ ! "$usps" == "" ] &&  echo "  uspsdata:" >> ./docker-compose.yml
-
+    if [ ! "$usas" == "" ]
+    then    
+        echo "  usasdata:" >> ./docker-compose.yml
+        [ "$USAS_DB_PASSWORD" == "" ] && echo "USAS_DB_PASSWORD=$(genDBHash)" >> ./.env
+    fi
+    
+    if [ ! "$usps" == "" ]
+    then
+      echo "  uspsdata:" >> ./docker-compose.yml
+      [ "$USPS_DB_PASSWORD" == "" ] &&  echo "USPS_DB_PASSWORD=$(genDBHash)" >> ./.env
+    fi
+    
     echo "" >> ./docker-compose.yml
 
-     md5calc ./docker-compose.yml > .docker-compose.md5
+    md5calc ./docker-compose.yml > .docker-compose.md5
 
     echo "created docker-compose.yml"