-
Notifications
You must be signed in to change notification settings - Fork 22
/
bootstrap.sh
executable file
·184 lines (156 loc) · 4.41 KB
/
bootstrap.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
#!/bin/sh
print_help()
{
cat <<EOF
Build and deploy Shanoir NG
usage:
$0 --clean|--force|--no-deploy [--no-build] [--no-keycloak] [--no-dcm4chee] [-h|--help]
CAUTION: THIS COMMAND IS DESTRUCTIVE, do not use it on an existing production
instance. It will overwrite the data hosted in the external volumes declared in
docker compose.yml (note: as a safety precaution, the command will fail if
'--clean' or '--force' option is not used).
Options:
--clean perform a clean deployment (will run 'docker compose down -v' to destroy all existing volumes)
--force force deploying over the existing volumes (might be a little faster, use it in dev only)
--no-deploy skip the deployment stage
--no-build skip the build stage
--no-keycloak do not run Keycloak (used if Keycloak is external)
--no-dcm4chee do not run dcm4chee (used if dcm4chee is external)
-h|--help print this help
EOF
exit 0
}
wait_tcp_ready()
{
local container="$1"
local tcp_port="$2"
docker compose exec -T "$container" bash -c "
( set -e
while true; do
if true < '/dev/tcp/localhost/$tcp_port' ; then
echo 'connected to $container port $tcp_port'
exit 0
fi
sleep 1
done
) 2>/dev/null
"
}
die()
{
echo "error: $*" >&2
exit 1
}
step()
{
echo "======== $* ========"
}
set -e
build=1
deploy=1
keycloak=1
dcm4chee=1
clean=
force=
while [ $# -ne 0 ] ; do
case "$1" in
-h|--help) print_help ;;
--clean) clean=1 ;;
--force) force=1 ;;
--no-build) build= ;;
--no-keycloak) keycloak= ;;
--no-dcm4chee) dcm4chee= ;;
--no-deploy) deploy= ;;
*) die "unknown option '$1'"
esac
shift
done
if [ -z "$clean$force" ] && [ -n "$deploy" ] ; then
die "you must provide at least --clean, --force or --no-deploy"
fi
if [ -n "$build" ] ; then
#
# Build stage
#
step "build shanoir"
# 1. build a docker image with the java toolchain
DEV_IMG=shanoir-ng-dev
docker build -t "$DEV_IMG" --target=jdk docker-compose
# 2. run the maven build
mkdir -p /tmp/home
docker run --rm -t -i -v "$PWD:/src" -u "`id -u`:`id -g`" -e HOME="/src/tmp/home" \
-e MAVEN_OPTS="-Dmaven.repo.local=/src/tmp/home/.m2/repository" \
-w /src "$DEV_IMG" sh -c 'cd shanoir-ng-parent && mvn clean install -DskipTests'
# 3. build the docker images
docker compose -f docker-compose-dev.yml build
fi
if [ -n "$deploy" ] ; then
#
# Clean stage
#
if [ -n "$clean" ] ; then
# full clean (--clean)
# -> destroy all external volumes
step "clean"
docker compose down -v
else
# overwrite (--force)
# -> just remove all existing containers
#
# Note: we must ensure that all containers are removed because:
# - 'docker compose run' should not be used when the
# corresponding service is up
# - 'docker compose logs' may display old logs if the container
# is not destroyed
step "stop shanoir"
docker compose down
fi
#
# Deploy stage
#
# 1. database
step "init: database"
docker compose up -d database
wait_tcp_ready database 3306
# 2. keycloak-database + keycloak
if [ -n "$keycloak" ] ; then
step "init: keycloak-database"
docker compose -f docker-compose-dev.yml up -d keycloak-database
wait_tcp_ready keycloak-database 3306
step "init: keycloak"
docker compose run --rm -e SHANOIR_MIGRATION=init keycloak
step "start: keycloak"
docker compose -f docker-compose-dev.yml up -d keycloak
docker-compose/common/oneshot --pgrp '\| *' \
' INFO \[io.quarkus\] .* Keycloak .* started in [0-9]*' \
-- docker compose logs --no-color --follow keycloak >/dev/null
fi
# 3. infrastructure services: dcm4chee
if [ -n "$dcm4chee" ] ; then
step "start: infrastructure services: dcm4chee"
for infra_ms_dcm4chee in ldap dcm4chee-database dcm4chee-arc
do
step "start: $infra_ms_dcm4chee infrastructure microservices dcm4chee"
docker compose -f docker-compose-dev.yml up -d "$infra_ms_dcm4chee"
done
fi
# 4. infrastructure services
step "start: infrastructure services"
for infra_ms in rabbitmq solr
do
step "start: $infra_ms infrastructure microservice"
docker compose -f docker-compose-dev.yml up -d "$infra_ms"
done
# 5. Shanoir-NG microservices
step "start: sh-ng microservices"
for ms in users studies datasets import preclinical nifti-conversion
do
step "init: $ms microservice"
docker compose run --rm -e SHANOIR_MIGRATION=init "$ms"
step "start: $ms microservice"
docker compose -f docker-compose-dev.yml up -d "$ms"
done
# 6. nginx
step "start: nginx"
docker compose -f docker-compose-dev.yml up -d nginx
fi