Mercurial > public > ssdt-docker
comparison pilot/training.sh @ 212:4de5e1a4637c
DEP-12: add training.yml and training.sh setup script for pilot training instances
author | smith@nwoca.org |
---|---|
date | Fri, 06 Oct 2017 21:24:55 +0100 |
parents | pilot/setup.sh@10c139726e68 |
children | 6f97f65c6cb6 |
comparison
equal
deleted
inserted
replaced
209:df5822269cdb | 212:4de5e1a4637c |
---|---|
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 if [ "$COMPOSE_PROJECT_NAME" == "" ] | |
56 then | |
57 echo "COMPOSE_PROJECT_NAME=${project_name}" >> .env | |
58 source .env | |
59 fi | |
60 | |
61 if [ ! -e "docker-compose.yml" ] | |
62 then | |
63 create="OK" | |
64 elif [ -e ".docker-compose.md5" ]; then | |
65 md5verify ./.docker-compose.md5 && create="OK" | |
66 fi | |
67 | |
68 if [ "$create" == "OK" ] | |
69 then | |
70 | |
71 cat $base/training.yml > ./docker-compose.yml | |
72 echo "" >> ./docker-compose.yml | |
73 | |
74 md5calc ./docker-compose.yml > .docker-compose.md5 | |
75 | |
76 echo "created docker-compose.yml for training instance ${project_name}" | |
77 | |
78 else | |
79 echo " | |
80 | |
81 Error! docker-compose.yml file has been modified or checksum missing. Can not auto-apply update(s). | |
82 Move customizations to docker-compose.override.yml then delete the docker-compose.yml | |
83 " | |
84 fi | |
85 | |
86 if [ ! -e "docker-compose.override.yml" ] | |
87 then | |
88 echo 'version: "3.3"' >> docker-compose.override.yml | |
89 fi | |
90 | |
91 if [ "$USAS_APPLICATIONID" == "" ] | |
92 then | |
93 usas_id=${COMPOSE_PROJECT_NAME}-usas | |
94 usas_key=$(openssl rand -hex 32) | |
95 usps_id=${COMPOSE_PROJECT_NAME}-usps | |
96 usps_key=$(openssl rand -hex 32) | |
97 echo "USAS_APPLICATIONID=${usas_id}" >> .env | |
98 echo "USAS_APIKEY=$usas_key" >> .env | |
99 echo "USPS_APPLICATIONID=${usps_id}" >> .env | |
100 echo "USPS_APIKEY=$usps_key" >> .env | |
101 echo "Created integration API keys. Enable integration modules after applications start" | |
102 fi | |
103 | |
104 if [ "$USAS_APP_HOST" == "" ] | |
105 then | |
106 echo "USAS_APP_HOST=usasapp-svr" >> .env | |
107 fi | |
108 | |
109 if [ "$USPS_APP_HOST" == "" ] | |
110 then | |
111 echo "USPS_APP_HOST=uspsapp-svr" >> .env | |
112 fi | |
113 | |
114 echo "Review or create docker-compose.override.yml for custom settings." | |
115 |