diff compose3/preview/setup.sh @ 136:72f15ffc9ad2

DEP-12: convert compose files to 3.1. remove template. update bash script to create composite docker-files without extends. prevent overwriting manual changes to docker-comose.yml
author smith@nwoca.org
date Mon, 15 May 2017 23:07:10 +0100
parents 03e39b95d904
children
line wrap: on
line diff
--- a/compose3/preview/setup.sh	Mon May 15 21:33:24 2017 +0100
+++ b/compose3/preview/setup.sh	Mon May 15 23:07:10 2017 +0100
@@ -12,13 +12,21 @@
 # 
 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/.functions.sh"
 
+md5calc() {
+   md5sum ${1} ;
+}
+
+md5verify() {
+   md5sum -c --status ${1} ;
+}
+
 base=$(dirname "${BASH_SOURCE[0]}")
 default_name=$(basename $PWD)
 
 args="$1$2"
 
-usas=0
-usps=0
+usas=""
+usps=""
 
 if [ "$args" == "" ] || [ -z "${args##*usas*}" ]
 then
@@ -30,11 +38,6 @@
    usps=1
 fi
 
-echo "args: $args usas: $usas usps: $usps"
-
-exit 
-
-
 echo "Preparing '$(basename $PWD)' with default USxS configuration" 
 
 touch .env
@@ -49,11 +52,41 @@
    source .env
 fi
 
-if [ ! -e "docker-compose.yml" ] ; then
-    cp $base/usxs-template.yml ./docker-compose.yml
-    echo "created default docker-compose.yml"
+if [ ! -e "docker-compose.yml" ] 
+then 
+   create="OK"
+elif [ -e ".docker-compose.md5" ]; then
+   md5verify ./.docker-compose.md5 && create="OK"
 fi
 
+if [ "$create" == "OK" ] 
+then
+    echo "version: \"3.1\""     > ./docker-compose.yml
+    echo "services:"            >> ./docker-compose.yml
+
+    [ ! "$usas" == "" ] &&  cat $base/usas-services.yml >> ./docker-compose.yml
+
+    [ ! "$usps" == "" ] &&  cat $base/usps-services.yml >> ./docker-compose.yml
+
+    echo "volumes:" >> ./docker-compose.yml
+
+    [ ! "$usas" == "" ] &&  echo "  usasdata:" >> ./docker-compose.yml
+    [ ! "$usps" == "" ] &&  echo "  uspsdata:" >> ./docker-compose.yml
+
+    echo "" >> ./docker-compose.yml
+
+     md5calc ./docker-compose.yml > .docker-compose.md5
+
+    echo "created docker-compose.yml"
+    
+else
+    echo "
+    
+    Error! docker-compose.yml file has been modified or checksum missing.  Can auto-apply update(s).
+           Move customizations to docker-compose.override.yml then delete the docker-compose.yml
+"
+fi
+   
 if [ "$USAS_APPLICATIONID" == "" ]
 then
    read -e -p "Generate USAS and USPS integration config? <Y/n> " answer
@@ -72,9 +105,9 @@
      echo "USAS_APIKEY=$usas_key"           >> .env
      echo "USPS_APPLICATIONID=${usps_id}"   >> .env
      echo "USPS_APIKEY=$usps_key"           >> .env
-     echo "Created integration API keys.  Enable integration modules after applications startup"
+     echo "Created integration API keys.  Enable integration modules after applications start"
    fi
 fi
 
-echo "project '$COMPOSE_PROJECT_NAME' ready with default values.  Review or create a docker-compose.override.yml for custom settings."
+echo "Review or create a docker-compose.override.yml for custom settings."