-
Notifications
You must be signed in to change notification settings - Fork 2
/
hmiServerDev.sh
executable file
·231 lines (209 loc) · 6.25 KB
/
hmiServerDev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env bash
# Description: This script is used to start the server locally for development purposes.
# It will decrypt the secrets file, start the server, then remove the secrets file.
SERVER_DIR="packages/server"
SECRET_FILES=()
SECRET_FILES+=("${SERVER_DIR}/src/main/resources/application-secrets.properties")
SECRET_FILES+=("containers/secrets.env")
VAULT_PASSWORD=""~/askem-vault-id.txt""
export COMPOSE_PROJECT_NAME="terarium"
function decrypt_secrets() {
echo "Decrypting local secrets vault"
for SECRET_FILE in "${SECRET_FILES[@]}"; do
echo "decrypting file: ${SECRET_FILE}"
ansible-vault decrypt --vault-password-file ${VAULT_PASSWORD} --output ${SECRET_FILE} ${SECRET_FILE}.encrypted
done
}
function encrypt_secrets() {
echo "Encrypting local secrets vault"
for SECRET_FILE in "${SECRET_FILES[@]}"; do
echo "encrypting file: ${SECRET_FILE}"
ansible-vault encrypt --vault-password-file ${VAULT_PASSWORD} --output ${SECRET_FILE}.encrypted ${SECRET_FILE}
done
}
function delete_secrets() {
echo "Deleting local secrets vault"
for SECRET_FILE in "${SECRET_FILES[@]}"; do
echo "deleting file: ${SECRET_FILE}"
rm ${SECRET_FILE}
done
}
function deploy_local() {
echo "Deploying containers for development against local services"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-local.yml pull
docker compose --env-file containers/.env --file containers/docker-compose-local.yml up --detach --wait
}
function deploy_full() {
echo "Locally run all containers"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-full.yml pull
docker compose --env-file containers/.env --file containers/docker-compose-full.yml up --detach --wait
}
function deploy_local_lean() {
echo "Deploying containers for development against local services"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-local-lean.yml up --detach --wait
}
function stop_local() {
echo "Stopping local dev containers"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-local.yml down
}
function stop_full() {
echo "Stopping all containers"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-full.yml down
}
function stop_local_lean() {
echo "Stopping local dev containers"
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-local-lean.yml down
}
function start_local() {
echo "Starting local server"
cd ${SERVER_DIR} || exit
./gradlew bootRun --args='--spring.profiles.active=default,secrets,local'
cd - || exit
}
function build_docker_compose() {
cat containers/common.env containers/secrets.env > containers/.env
docker compose --env-file containers/.env --file containers/docker-compose-full.yml $(for customfile in `ls docker-compose.custom*.y*ml 2> /dev/null`; do echo -n " -f $customfile"; done) config > ./docker-compose.yml
}
while [[ $# -gt 0 ]]; do
case ${1} in
-h | --help)
COMMAND="help"
;;
start)
COMMAND="start"
ENVIRONMENT="$2"
SERVER="$3"
shift
shift
;;
stop)
COMMAND="stop"
ENVIRONMENT="$2"
shift
;;
encrypt)
COMMAND="encrypt"
;;
decrypt)
COMMAND="decrypt"
;;
docker-compose)
COMMAND="docker-compose"
;;
*)
echo "hmiServerDev.sh: illegal option"
break
;;
esac
shift
done
# Default COMMAND to start if empty
COMMAND=${COMMAND:-"help"}
ENVIRONMENT=${ENVIRONMENT:-"local"}
SERVER=${SERVER:-"false"}
# We keep staging as a valid environment for legacy purposes
VALID_ENVIRONMENTS=("local" "staging" "full" "ll")
ENVIRONMENT_IS_VALID=0
for env in ${VALID_ENVIRONMENTS[@]}; do
echo "checking $ENVIRONMENT against $env"
if [ "${env}" = "${ENVIRONMENT}" ]; then
echo "setting ENVIRONMENT_IS_VALID to 1"
ENVIRONMENT_IS_VALID=1
fi
done
echo "value of ENVIRONMENT_IS_VALID is ${ENVIRONMENT_IS_VALID}"
if [ ${ENVIRONMENT_IS_VALID} -eq 0 ]; then
echo "Illegal ENVIRONMENT \"${ENVIRONMENT}\""
COMMAND="help"
else
echo "COMMAND: $COMMAND"
echo "ENVIRONMENT: $ENVIRONMENT"
echo "SERVER: $SERVER"
fi
case ${COMMAND} in
start)
decrypt_secrets
case ${ENVIRONMENT} in
local)
deploy_local
;;
staging)
deploy_local
;;
full)
deploy_full
;;
ll)
deploy_local_lean
;;
esac
if [ ${SERVER} == "run" ]; then
if [ ${ENVIRONMENT} == "local" ]; then
start_local
elif [ ${ENVIRONMENT} == "staging" ]; then
start_local
fi
delete_secrets
fi
;;
stop)
decrypt_secrets
case ${ENVIRONMENT} in
local)
stop_local
;;
staging)
stop_local
;;
full)
stop_full
;;
ll)
stop_local_lean
;;
esac
delete_secrets
;;
decrypt)
decrypt_secrets
;;
encrypt)
encrypt_secrets
;;
docker-compose)
decrypt_secrets
build_docker_compose
delete_secrets
;;
help)
echo "
DESCRIPTION:
Terarium Development scripts
SYNOPSIS:
hmiServerDev.sh [start ENVIRONMENT [run] (optional) | encrypt | decrypt]
start
ENVIRONMENT
local | full | ll (default: local) Indicate which environment to develop against
(ll: local_lean to run local with the absolute minimal support to run hmiServer for development)
run (default: null) Indicate whether to run the server after starting the containers
stop
ENVIRONMENT
local | full | ll (default: local) Indicate which containers to stop
OTHER COMMANDS:
encrypt
Encrypts the secrets file
decrypt
Decrypts the secrets file
docker-compose
Generates a combined single docker-compose.yml file for local development
help
Displays this help message
"
;;
esac