comparison 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
comparison
equal deleted inserted replaced
135:03e39b95d904 136:72f15ffc9ad2
10 # Will create a docker-compose.yml and .env file with default settings. 10 # Will create a docker-compose.yml and .env file with default settings.
11 # 11 #
12 # 12 #
13 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/.functions.sh" 13 source "$(dirname "${BASH_SOURCE[0]}")/../../scripts/.functions.sh"
14 14
15 md5calc() {
16 md5sum ${1} ;
17 }
18
19 md5verify() {
20 md5sum -c --status ${1} ;
21 }
22
15 base=$(dirname "${BASH_SOURCE[0]}") 23 base=$(dirname "${BASH_SOURCE[0]}")
16 default_name=$(basename $PWD) 24 default_name=$(basename $PWD)
17 25
18 args="$1$2" 26 args="$1$2"
19 27
20 usas=0 28 usas=""
21 usps=0 29 usps=""
22 30
23 if [ "$args" == "" ] || [ -z "${args##*usas*}" ] 31 if [ "$args" == "" ] || [ -z "${args##*usas*}" ]
24 then 32 then
25 usas=1 33 usas=1
26 fi 34 fi
27 35
28 if [ "$args" == "" ] || [ -z "${args##*usps*}" ] 36 if [ "$args" == "" ] || [ -z "${args##*usps*}" ]
29 then 37 then
30 usps=1 38 usps=1
31 fi 39 fi
32
33 echo "args: $args usas: $usas usps: $usps"
34
35 exit
36
37 40
38 echo "Preparing '$(basename $PWD)' with default USxS configuration" 41 echo "Preparing '$(basename $PWD)' with default USxS configuration"
39 42
40 touch .env 43 touch .env
41 source .env 44 source .env
47 echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env 50 echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env
48 echo "set project name in .env file" 51 echo "set project name in .env file"
49 source .env 52 source .env
50 fi 53 fi
51 54
52 if [ ! -e "docker-compose.yml" ] ; then 55 if [ ! -e "docker-compose.yml" ]
53 cp $base/usxs-template.yml ./docker-compose.yml 56 then
54 echo "created default docker-compose.yml" 57 create="OK"
58 elif [ -e ".docker-compose.md5" ]; then
59 md5verify ./.docker-compose.md5 && create="OK"
55 fi 60 fi
56 61
62 if [ "$create" == "OK" ]
63 then
64 echo "version: \"3.1\"" > ./docker-compose.yml
65 echo "services:" >> ./docker-compose.yml
66
67 [ ! "$usas" == "" ] && cat $base/usas-services.yml >> ./docker-compose.yml
68
69 [ ! "$usps" == "" ] && cat $base/usps-services.yml >> ./docker-compose.yml
70
71 echo "volumes:" >> ./docker-compose.yml
72
73 [ ! "$usas" == "" ] && echo " usasdata:" >> ./docker-compose.yml
74 [ ! "$usps" == "" ] && echo " uspsdata:" >> ./docker-compose.yml
75
76 echo "" >> ./docker-compose.yml
77
78 md5calc ./docker-compose.yml > .docker-compose.md5
79
80 echo "created docker-compose.yml"
81
82 else
83 echo "
84
85 Error! docker-compose.yml file has been modified or checksum missing. Can auto-apply update(s).
86 Move customizations to docker-compose.override.yml then delete the docker-compose.yml
87 "
88 fi
89
57 if [ "$USAS_APPLICATIONID" == "" ] 90 if [ "$USAS_APPLICATIONID" == "" ]
58 then 91 then
59 read -e -p "Generate USAS and USPS integration config? <Y/n> " answer 92 read -e -p "Generate USAS and USPS integration config? <Y/n> " answer
60 case $answer in 93 case $answer in
61 y | Y | yes | YES ) answer="y";; 94 y | Y | yes | YES ) answer="y";;
70 usps_key=$(openssl rand -hex 32) 103 usps_key=$(openssl rand -hex 32)
71 echo "USAS_APPLICATIONID=${usas_id}" >> .env 104 echo "USAS_APPLICATIONID=${usas_id}" >> .env
72 echo "USAS_APIKEY=$usas_key" >> .env 105 echo "USAS_APIKEY=$usas_key" >> .env
73 echo "USPS_APPLICATIONID=${usps_id}" >> .env 106 echo "USPS_APPLICATIONID=${usps_id}" >> .env
74 echo "USPS_APIKEY=$usps_key" >> .env 107 echo "USPS_APIKEY=$usps_key" >> .env
75 echo "Created integration API keys. Enable integration modules after applications startup" 108 echo "Created integration API keys. Enable integration modules after applications start"
76 fi 109 fi
77 fi 110 fi
78 111
79 echo "project '$COMPOSE_PROJECT_NAME' ready with default values. Review or create a docker-compose.override.yml for custom settings." 112 echo "Review or create a docker-compose.override.yml for custom settings."
80 113