forked from bcgov/gcpe-news-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage
executable file
·353 lines (284 loc) · 9.41 KB
/
manage
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
#!/bin/bash
export MSYS_NO_PATHCONV=1
export DOCKERHOST=${APPLICATION_URL-$(docker run --rm --net=host eclipse/che-ip)}
set -e
S2I_EXE=s2i
if [ -z $(type -P "$S2I_EXE") ]; then
echo -e "The ${S2I_EXE} executable is needed and not on your path."
echo -e "It can be downloaded from here: https://github.com/openshift/source-to-image"
echo -e "Make sure you place it in a directory on your path."
exit 1
fi
SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
# =================================================================================================================
# Usage:
# -----------------------------------------------------------------------------------------------------------------
usage() {
cat <<-EOF
Usage: $0 [command] [options]
Commands:
build - Build the docker images for the project.
You need to do this first, since the builds require
a combination of Docker and S2I builds.
You can build individual components as shown below, components that have dependencies will have these dependencies built too.
Examples:
- Build the web UI only
$0 build gnd-web
- Build the API server only.
$0 build gnd-api
By default all containers that components comprise of, will be rebuilt.
$0 build
up - Creates the application containers from the built images
and starts the services based on the docker-compose.yml file.
You can pass in a list of containers to start.
By default all containers will be started.
The API_URL used by gnd-web can also be redirected.
Examples:
$0 start
$0 start gnd-web
$0 start gnd-web API_URL=http://docker.for.win.localhost:56325/api/v1
$0 start gnd-api
start - Same as up
logs - Display the logs from the docker compose run (ctrl-c to exit).
web-dev - Builds and runs a live development version of gnd-web, along with
the required supporting components. Once started, the website is
automatically compiled and updated in response to file modifications.
stop - Stops the services. This is a non-destructive process. The volumes and containers
are not deleted so they will be reused the next time you run start.
down - Brings down the services and removes the volumes (storage) and containers.
rm - Same as down
EOF
exit 1
}
# -----------------------------------------------------------------------------------------------------------------
# Default Settings:
# -----------------------------------------------------------------------------------------------------------------
DEFAULT_CONTAINERS="news-dashboard"
# -----------------------------------------------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------------------------------------------
build-web() {
#
# gnd-web
#
# The nginx-runtime image is used for the final runtime image.
# The nodejs-build image is used to build the artifacts for the angular distribution.
# The angular-on-nginx image is copy of the nginx-runtime image complete with a copy of the build artifacts.
#
echo -e "\nBuilding nginx-runtime image ..."
docker build -q \
-t 'frontend-nginx-runtime' \
-f 'openshift/templates/runtime/Dockerfile' 'openshift/templates/runtime/'
# This image only exists to pre-create the npm cache directory
# so it can be properly used as a volume, it doesn't apply to openshift
echo -e "\nBuilding frontend-yarn-builder image ..."
docker build -q \
-t 'frontend-yarn-builder' \
-f 'openshift/templates/builder/Dockerfile' 'openshift/templates/builder/'
if [ -t 0 ]; then
NPM_COLOR="always"
else
NPM_COLOR="true"
fi
echo -e "\nBuilding news-dashboard image ..."
SECONDS=0
${S2I_EXE} build \
-e "NPM_CONFIG_COLOR=${NPM_COLOR}" \
-e "NPM_CONFIG_LOGLEVEL=timing" \
-e "HTTP_PROXY=${HTTP_PROXY}" \
-e "HTTPS_PROXY=${HTTPS_PROXY}" \
-e "NG_BASE_HREF=${WEB_BASE_HREF}" \
-e "NG_DEPLOY_URL=${WEB_DEPLOY_URL}" \
--copy \
--volume "${COMPOSE_PROJECT_NAME}_gnd-npm-cache:/opt/app-root/src/.npm" \
--runtime-image frontend-nginx-runtime \
-a /opt/app-root/src/dist:app \
. frontend-yarn-builder news-dashboard
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
}
build-web-dev() {
#
# gnd-web-dev
# Alternative version of gnd-web for live development
#
echo -e "\nBuilding nodejs-build image ..."
docker build -q \
-t 'nodejs-build' \
-f '../gnd-web/openshift/templates/builder/Dockerfile' '../gnd-web/openshift/templates/builder/'
# NB: We build with DEV_MODE=true but run with DEV_MODE=false
echo -e "\nBuilding angular-dev image ..."
${S2I_EXE} build \
-e "DEV_MODE=true" \
-e "HTTP_PROXY=${HTTP_PROXY}" \
-e "HTTPS_PROXY=${HTTPS_PROXY}" \
-e "NG_BASE_HREF=${WEB_BASE_HREF}" \
-e "NG_DEPLOY_URL=${WEB_DEPLOY_URL}" \
-e "TOB_THEME=${TOB_THEME}" \
--volume "${COMPOSE_PROJECT_NAME}_npm-cache:/opt/app-root/src/.npm" \
'../.' \
'nodejs-build' \
'angular-dev'
}
build-api() {
#
# news-api
#
SECONDS=0
BASE_IMAGE="registry.access.redhat.com/dotnet/dotnet-22-rhel7:latest"
BASE_IMAGE_NAME="dotnet-22-rhel7:latest"
# do not fail if we can't pull the image.
docker pull $BASE_IMAGE || true
docker tag $BASE_IMAGE $BASE_IMAGE_NAME
echo -e "\nBuilding API image from ${BASE_IMAGE_NAME}..."
# temporarily change directory to the hub API project - as we don't want to use S2I scripts for the angular front end.
pushd ../gcpe-hub-api
${S2I_EXE} build \
-e "DOTNET_STARTUP_PROJECT=Gcpe.Hub.API/Gcpe.Hub.API.csproj" \
'.' \
"$BASE_IMAGE_NAME" \
'hub-api'
duration=$SECONDS
echo "$(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
# change back to previous directory
popd
}
buildImages() {
build-web
build-api
}
configureEnvironment() {
if [ -f .env ]; then
while read line; do
if [[ ! "$line" =~ ^\# ]] && [[ "$line" =~ .*= ]]; then
export ${line//[$'\r\n']}
fi
done <.env
fi
for arg in $@; do
case "$arg" in
*=*)
export ${arg}
;;
esac
done
export COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-news-dashboard}"
export STI_SCRIPTS_PATH=${STI_SCRIPTS_PATH:-/usr/libexec/s2i}
export RUST_LOG=${RUST_LOG:-warn}
export RUST_BACKTRACE=${RUST_BACKTRACE:-full}
#
# gnd-api
export APP_CONFIG=${APP_CONFIG:-}
export APP_MODULE=tob_anchor.boot:init_app
export API_HTTP_PORT=${API_HTTP_PORT:-8080}
export DEBUG=${DEBUG}
export OPTIMIZE_TABLE_ROW_COUNTS=${OPTIMIZE_TABLE_ROW_COUNTS-}
export INDY_DISABLED=${INDY_DISABLED-}
export SOLR_SERVICE_NAME="gnd-solr"
export SOLR_CORE_NAME=${CORE_NAME}
export SKIP_INDEXING_ON_STARTUP=${SKIP_INDEXING_ON_STARTUP-}
export WEB_CONCURRENCY=${WEB_CONCURRENCY:-5}
export APPLICATION_URL=${APPLICATION_URL-http://localhost:8080}
# gnd-web
export WEB_HTTP_PORT=${WEB_HTTP_PORT:-8080}
export WEB_BASE_HREF=${WEB_BASE_HREF:-/}
export WEB_DEPLOY_URL=${WEB_DEPLOY_URL:-/}
export API_URL=${API_URL-http://hub-api:8080/api}
export IpFilterRules='allow all;'
export RealIpFrom='127.0.0.0/16'
export HTTP_BASIC_USERNAME=${HTTP_BASIC_USERNAME:-}
export HTTP_BASIC_PASSWORD=${HTTP_BASIC_PASSWORD:-}
}
getStartupParams() {
CONTAINERS=""
ARGS="--force-recreate"
for arg in $@; do
case "$arg" in
*=*)
# Skip it
;;
-*)
ARGS+=" $arg"
;;
*)
CONTAINERS+=" $arg"
;;
esac
done
if [ -z "$CONTAINERS" ]; then
CONTAINERS="$DEFAULT_CONTAINERS"
fi
echo ${ARGS} ${CONTAINERS}
}
deleteVolumes() {
_projectName=${COMPOSE_PROJECT_NAME:-docker}
echo "Stopping and removing any running containers ..."
docker-compose down -v
_pattern="^${_projectName}_\|^docker_"
_volumes=$(docker volume ls -q | grep ${_pattern})
if [ ! -z "${_volumes}" ]; then
echo "Removing project volumes ..."
echo ${_volumes} | xargs docker volume rm
else
echo "No project volumes exist."
fi
echo "Removing build cache ..."
rm -Rf ../.cache
}
toLower() {
echo $(echo ${@} | tr '[:upper:]' '[:lower:]')
}
# =================================================================================================================
pushd ${SCRIPT_HOME} >/dev/null
COMMAND=$(toLower ${1})
shift || COMMAND=usage
case "${COMMAND}" in
start|up)
_startupParams=$(getStartupParams $@)
configureEnvironment $@
docker-compose up -d ${_startupParams}
docker-compose logs -f
;;
logs)
configureEnvironment $@
docker-compose logs -f
;;
web-dev)
_startupParams=$(getStartupParams $@)
configureEnvironment $@
[ -z "$SKIP_BUILD" ] && build-web-dev
docker-compose run --rm --service-ports gnd-web-dev
;;
stop)
configureEnvironment
docker-compose stop
;;
rm|down)
configureEnvironment
deleteVolumes
;;
build)
_startupParams=$(getStartupParams $@)
configureEnvironment $@
case "$@" in
api)
build-api
;;
web)
build-web
;;
*)
buildImages
;;
esac
;;
shell)
_startupParams=$(getStartupParams $@)
configureEnvironment $@
docker-compose run gnd-api bash
;;
*)
usage
;;
esac
popd >/dev/null