comparison prod/training.sh @ 234:2ae65177f74e

DEP-14: copy pilot scripts to prod
author smith@nwoca.org
date Wed, 10 Jan 2018 00:44:05 +0000
parents pilot/training.sh@6f97f65c6cb6
children b390c30aa6c6
comparison
equal deleted inserted replaced
233:3133ce001603 234:2ae65177f74e
1 #!/bin/bash
2 # Sets up a new Training project based on SSDT default configuration in the current working directory.
3 #
4 # Usage:
5 #
6 # /data/preview/training-01 $ /ssdt/compose2/preview/training.sh
7 #
8 # Will create a docker-compose.yml and .env file with default settings using the SSDT
9 # supplied training database
10 #
11 # These are special database images which recreates the database each time the container is created.
12 # Therefore, it is very easy to reset the training database simply by deleting the
13 # project containers and restarting them. for example:
14 #
15 # docker-compose down
16 # docker-compose up -d
17 #
18 source "$(dirname "${BASH_SOURCE[0]}")/../scripts/.functions.sh"
19
20 md5calc() {
21 md5sum ${1} ;
22 }
23
24 md5verify() {
25 md5sum -c --status ${1} ;
26 }
27
28 genDBHash() {
29 echo $(date +%s%N | sha256sum | base64 | head -c 32 ; echo)
30 }
31
32 base=$(dirname "${BASH_SOURCE[0]}")
33 default_name=$(basename $PWD)
34
35 args="$1$2"
36
37 usas=""
38 usps=""
39
40 if [ "$args" == "" ] || [ -z "${args##*usas*}" ]
41 then
42 usas=1
43 fi
44
45 if [ "$args" == "" ] || [ -z "${args##*usps*}" ]
46 then
47 usps=1
48 fi
49
50 echo "Preparing training project '$(basename $PWD)' with default USxS configuration"
51
52 touch .env
53 source .env
54
55 project_name=${default_name}
56
57 if [ "$COMPOSE_PROJECT_NAME" == "" ]
58 then
59 echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env
60 source .env
61 fi
62
63 if [ ! -e "docker-compose.yml" ]
64 then
65 create="OK"
66 elif [ -e ".docker-compose.md5" ]; then
67 md5verify ./.docker-compose.md5 && create="OK"
68 fi
69
70 if [ "$create" == "OK" ]
71 then
72
73 cat $base/training.yml > ./docker-compose.yml
74 echo "" >> ./docker-compose.yml
75
76 md5calc ./docker-compose.yml > .docker-compose.md5
77
78 echo "created docker-compose.yml for training instance ${project_name}"
79
80 else
81 echo "
82
83 Error! docker-compose.yml file has been modified or checksum missing. Can not auto-apply update(s).
84 Move customizations to docker-compose.override.yml then delete the docker-compose.yml
85 "
86 fi
87
88 if [ ! -e "docker-compose.override.yml" ]
89 then
90 echo 'version: "3.3"' >> docker-compose.override.yml
91 fi
92
93 if [ "$USAS_APPLICATIONID" == "" ]
94 then
95 usas_id=${COMPOSE_PROJECT_NAME}-usas
96 usas_key=$(openssl rand -hex 32)
97 usps_id=${COMPOSE_PROJECT_NAME}-usps
98 usps_key=$(openssl rand -hex 32)
99 echo "USAS_APPLICATIONID=${usas_id}" >> .env
100 echo "USAS_APIKEY=$usas_key" >> .env
101 echo "USPS_APPLICATIONID=${usps_id}" >> .env
102 echo "USPS_APIKEY=$usps_key" >> .env
103 echo "Created integration API keys. Enable integration modules after applications start"
104 fi
105
106 if [ "$USAS_APP_HOST" == "" ]
107 then
108 echo "USAS_APP_HOST=usasapp-svr" >> .env
109 fi
110
111 if [ "$USPS_APP_HOST" == "" ]
112 then
113 echo "USPS_APP_HOST=uspsapp-svr" >> .env
114 fi
115
116 echo "Review or create docker-compose.override.yml for custom settings."
117