-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·457 lines (424 loc) · 14.3 KB
/
build.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#! /bin/bash
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# set -x # for debugging only: print last executed command
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if docker compose version > /dev/null 2>&1
then
COMPOSE="docker compose"
elif command -v docker-compose > /dev/null 2>&1
then
COMPOSE="docker-compose"
else
echo "Can't find docker-compose on this system."
exit 1
fi
echo "Using compose command $COMPOSE"
function misses_image {
# Function for boolean checks if an image already exists.
# Uses the docker image inspect command. If it
# finds the according image we can be save that it is there.
# This is bettern then an docker image ls & a grep check.
#
# Arguments:
# - $1 => imageName - Name of the image that we want to check.
# Supports normal image names, but also tags
# or ids.
imageName=$1
if [[ -z $(docker image inspect --format '{{.Id}}' "$imageName" 2> /dev/null) ]]; then
return
else
false
fi
}
function clean {
# Ensures that we can restart our script from an completely clean state.
rm -rf config
rm -rf styles
rm -rf gfz-command-line-tool-repository
rm -rf quakeledger
rm -rf shakyground-grid-file
rm -rf shakyground
rm -rf assetmaster
rm -rf modelprop
rm -rf deus
rm -rf tsunami-wps
rm -rf dlr-riesgos-frontend
rm -rf tum-era-critical-infrastructure-analysis
docker image rm "gfzriesgos/riesgos-wps" || echo "Skip deleting image"
docker image rm "gfzriesgos/quakeledger" || echo "Skip deleting image"
docker image rm "gfzriesgos/shakyground-grid-file" || echo "Skip deleting image"
docker image rm "gfzriesgos/shakyground" || echo "Skip deleting image"
docker image rm "gfzriesgos/assetmaster" || echo "Skip deleting image"
docker image rm "gfzriesgos/modelprop" || echo "Skip deleting image"
docker image rm "gfzriesgos/deus" || echo "Skip deleting image"
docker image rm "dlrriesgos/backend" || echo "Skip deleting image"
docker image rm "dlrriesgos/monitor" || echo "Skip deleting image"
docker image rm "dlrriesgos/frontend" || echo "Skip deleting image"
docker image rm "dlrriesgos/compare-frontend" || echo "Skip deleting image"
docker image rm "52north/tum-era-critical-infrastructure-analysis-multi" || echo "Skip deleting image"
docker image rm "52north/tum-era-critical-infrastructure-analysis-single" || echo "Skip deleting image"
docker image rm "52north/ades" || echo "Skip deleting image"
docker image rm "tsunami-wps-app01" || echo "Skip deleting image"
docker volume rm buildall_logs || echo "Skip deleting the logs volume"
docker volume rm buildall_store || echo "Skip deleting the store volume"
}
function get_busybox {
image="busybox:latest"
if misses_image $image; then
# getting an image that we know will work ...
docker pull busybox:1.35.0
# ... but renaming it to 'latest' because thats what sysrel requires.
docker image tag busybox:1.35.0 busybox:latest
else
echo "Already exists: $image"
fi
}
function build_riesgos_wps {
image="gfzriesgos/riesgos-wps"
repo="https://github.com/riesgos/gfz-command-line-tool-repository"
if misses_image $image; then
echo "Building $image ... "
if [ ! -d gfz-command-line-tool-repository ]; then
git clone "$repo"
fi
cd gfz-command-line-tool-repository
docker build -t $image:latest -f assistance/Dockerfile .
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
if [ ! -d "styles" ]; then
mkdir -p "styles"
fi
if [ ! -f "styles/shakemap-pga.sld" ]; then
if [ ! -f "gfz-command-line-tool-repository/assistance/SLD/shakemap-pga.sld" ]; then
git clone "$repo"
fi
cp gfz-command-line-tool-repository/assistance/SLD/* styles
fi
}
function build_quakeledger {
image="gfzriesgos/quakeledger"
repo="https://github.com/gfzriesgos/quakeledger"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d quakeledger ]; then
git clone "$repo"
fi
cd quakeledger
docker image build --tag $image:latest --file ./metadata/Dockerfile .
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
# And add the json config to our configs folder.
if [ ! -d "configs" ]; then
mkdir -p "configs"
fi
if [ ! -f "config/quakeledger.json" ]; then
if [ ! -f "quakeledger/metadata/quakeledger.json" ]; then
git clone "$repo"
fi
cp quakeledger/metadata/quakeledger.json configs
fi
}
function build_shakyground_grid {
# We reuse this new image later as the base image for shakyground.
# So that all the grid files are already there.
image="gfzriesgos/shakyground-grid-file"
repo="https://github.com/gfzriesgos/shakyground-grid-file"
if misses_image $image; then
if [ ! -d shakyground-grid-file ]; then
git clone "$repo"
fi
cd shakyground-grid-file
docker image build --tag $image:latest --file ./Dockerfile .
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
}
function build_shakyground {
image="gfzriesgos/shakyground"
repo="https://github.com/gfzriesgos/shakyground"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d shakyground ]; then
git clone "$repo"
fi
cd shakyground
# Replace the FROM entry in the dockerfile
# so that we use our latest shakyground-grid-file image
sed -i -e 's/FROM gfzriesgos\/shakyground-grid-file:.*$/FROM gfzriesgos\/shakyground-grid-file:latest/' ./metadata/Dockerfile
docker image build --tag $image:latest --file ./metadata/Dockerfile .
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
# And add the json config to our configs folder.
if [ ! -d "configs" ]; then
mkdir -p "configs"
fi
if [ ! -f "config/shakyground.json" ]; then
if [ ! -f "shakyground/metadata/shakyground.json" ]; then
git clone "$repo"
fi
cp shakyground/metadata/shakyground.json configs
fi
}
function build_assetmaster {
image="gfzriesgos/assetmaster"
repo="https://github.com/gfzriesgos/assetmaster"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d assetmaster ]; then
git clone "$repo"
fi
cd assetmaster
docker image build --tag $image --file ./metadata/Dockerfile .
cp metadata/assetmaster.json ../configs
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
# And add the json config to our configs folder.
if [ ! -d "configs" ]; then
mkdir -p "configs"
fi
if [ ! -f "config/assetmaster.json" ]; then
if [ ! -f "assetmaster/metadata/assetmaster.json" ]; then
git clone "$repo"
fi
cp assetmaster/metadata/assetmaster.json configs
fi
}
function build_modelprop {
image="gfzriesgos/modelprop"
repo="https://github.com/gfzriesgos/modelprop"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d modelprop ]; then
git clone "$repo"
fi
cd modelprop
docker image build --tag $image --file ./metadata/Dockerfile .
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
# And add the json config to our configs folder.
if [ ! -d "configs" ]; then
mkdir -p "configs"
fi
if [ ! -f "config/modelprop.json" ]; then
if [ ! -f "modelprop/metadata/modelprop.json" ]; then
git clone "$repo"
fi
cp modelprop/metadata/modelprop.json configs
fi
}
function build_deus {
image="gfzriesgos/deus"
repo="https://github.com/gfzriesgos/deus"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d deus ]; then
git clone "$repo"
fi
cd deus
docker image build --tag $image --file ./metadata/Dockerfile .
cp metadata/deus.json ../configs
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
if [ ! -d "configs" ]; then
mkdir -p "configs"
fi
if [ ! -f "config/deus.json" ]; then
if [ ! -f "deus/metadata/deus.json" ]; then
git clone "$repo"
fi
cp deus/metadata/deus.json configs
fi
# The json configuration files for neptunus & volcanus
# belong to deus. So copy them as well.
if [ ! -f "config/volcanus.json" ]; then
if [ ! -f "deus/metadata/volcanus.json" ]; then
git clone "$repo"
fi
cp deus/metadata/volcanus.json configs
fi
if [ ! -f "config/neptunus.json" ]; then
if [ ! -f "deus/metadata/neptunus.json" ]; then
git clone "$repo"
fi
cp deus/metadata/neptunus.json configs
fi
}
function build_tssim {
image="tsunami-wps-app01"
if misses_image $image; then
echo "Building $image ..."
if [ ! -d "tsunami-wps" ]; then
git clone https://gitlab.awi.de/tsunawi/web-services/tsunami-wps
fi
cd tsunami-wps
git checkout full-docker-build-config
curl https://nextcloud.awi.de/s/aNXgXxN9qk5RZRz/download/riesgos_tsunami_data.tgz -o riesgos_tsunami_data.tgz
tar -xzf riesgos_tsunami_data.tgz
curl https://nextcloud.awi.de/s/rMGYacxWzM9y5PX/download/riesgos_tsunami_inun_data.tgz -o riesgos_tsunami_inun_data.tgz
tar -xzf riesgos_tsunami_inun_data.tgz
$COMPOSE build
cd $SCRIPT_DIR
else
echo "Already exists: $image"
fi
}
function build_sysrel {
#TODO maybe split docker-compose to build one image each (currently -single and -multi are built together)
buildIt=false
sysrelImages=("52north/tum-era-critical-infrastructure-analysis-multi" "52north/tum-era-critical-infrastructure-analysis-single" "52north/ades")
for image in "${sysrelImages[@]}"
do
if misses_image "$image"; then
buildIt=true
fi
done
if [ "$buildIt" = false ]; then
echo "Already exists: sysrel"
else
echo "Building sysrel ..."
if [ ! -d "tum-era-critical-infrastructure-analysis" ]; then
git clone https://github.com/52North/tum-era-critical-infrastructure-analysis
fi
cd tum-era-critical-infrastructure-analysis
$COMPOSE build
cd javaPS
$COMPOSE build
fi
cd $SCRIPT_DIR
}
function build_frontend {
# Checking if rebuilding is required
buildIt=false
frontendImages=("dlrriesgos/frontend" "dlrriesgos/compare-frontend" "dlrriesgos/backend")
for image in "${frontendImages[@]}"
do
if misses_image "$image"; then
buildIt=true
fi
done
# Build if required
if [ "$buildIt" = false ]; then
echo "Already exists: frontend"
else
if [ ! -d "dlr-riesgos-frontend" ]; then
git clone https://github.com/riesgos/dlr-riesgos-frontend # --branch=2.0.6-main <-- once we have a stable tag
fi
sleep 1
if [ ! -d ./dlr-riesgos-frontend ]; then
echo "Weird, cannot find dlr-riesgos-frontend directory"
exit 1
elif [ ! -f .env ]; then
echo "Weird, cannot find .env file"
exit 1
fi
cp .env ./dlr-riesgos-frontend
cd ./dlr-riesgos-frontend
$COMPOSE build
cd $SCRIPT_DIR
fi
}
function build_all {
get_busybox
build_riesgos_wps
build_quakeledger
build_shakyground_grid
build_shakyground
build_assetmaster
build_modelprop
build_deus
build_tssim
build_sysrel
build_frontend
}
function run_all {
$COMPOSE --env-file .env up -d
}
function complain_if_command_is_missing {
toolName=$1
if $(which "$toolName" > /dev/null); then
return
else
echo "Can't find $toolName on this system."
exit 1
fi
}
function check_dependencies {
complain_if_command_is_missing git
complain_if_command_is_missing mkdir
complain_if_command_is_missing sed
complain_if_command_is_missing tar
complain_if_command_is_missing curl
# Honestly if we don't have docker, then this script will fail much
# earlier. Same if we don't have any version of docker compose.
complain_if_command_is_missing docker
}
function main {
# Main function to dispatch to several actions.
# Idea is to make the functions here easier to test.
# If we give it an parameter, we invoke other functions.
# If we don't give anohter parameter, then we run the
# build_all.
if [ -z ${1+x} ]; then
# In case we don't have any subcommand then
# we want to build and run all.
check_dependencies
build_all
elif [ "$1" == "all" ]; then
check_dependencies
build_all
elif [ "$1" == "run" ]; then
run_all
elif [ "$1" == "misses_image" ]; then
image=$2
if misses_image "$image"; then
echo "$image is missing"
else
echo "$image is already there"
fi
elif [ "$1" == "clean" ]; then
clean
elif [ "$1" == "check" ]; then
check_dependencies
elif [ "$1" == "riesgos-wps" ]; then
build_riesgos_wps
elif [ "$1" == "quakeledger" ]; then
build_quakeledger
elif [ "$1" == "shakyground-grid" ]; then
build_shakyground_grid
elif [ "$1" == "shakyground" ]; then
build_shakyground
elif [ "$1" == "assetmaster" ]; then
build_assetmaster
elif [ "$1" == "modelprop" ]; then
build_modelprop
elif [ "$1" == "deus" ]; then
build_deus
elif [ "$1" == "tssim" ]; then
build_tssim
elif [ "$1" == "sysrel" ]; then
build_sysrel
elif [ "$1" == "frontend" ]; then
build_frontend
else
echo "no known command found for: $1"
fi
}
main "$@"
#echo "Building backend ..."
#echo "Building frontend ..."
#echo "Done!"