-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtooling.sh
More file actions
executable file
·281 lines (258 loc) · 7.19 KB
/
tooling.sh
File metadata and controls
executable file
·281 lines (258 loc) · 7.19 KB
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
#!/usr/bin/env bash
set -e
set -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source "${SCRIPT_DIR}/.env"
source "${SCRIPT_DIR}/Deployment/tooling/imports.sh"
h1 "Uitsmijter Tooling"
echoBanner "Branch: ${GIT_BRANCH} | Version: ${GIT_TAG}" "~"
echo ""
help() {
echo "Choose one or more commands: "
echo ""
echo " -rm | --remove | remove Remove docker volumes, images and build directory"
echo " -b | --build | build Build the project"
echo " -l | --lint | lint Check code quality"
echo " -t | --test | test Run all UnitTests"
echo " Optional <filter> can be applied as: '--test <filter>'"
echo " like: '--test ServerTests.AppTests/testHelloWorld'"
echo " -o | --list-tests | list-tests Shows a list of tests"
echo " -e | --e2e | e2e Run end-to-end tests"
echo " Optional --filter can be applied as: 'e2e --filter <pattern>'"
echo " like: 'e2e --filter \"should respond with error\"'"
echo " -r/-c | --run[-cluster] | run[-cluster] Run Uitsmijter in docker or in a local kind-cluster"
echo " -d | --run-docker | run-docker Run Uitsmijter in a production docker environment"
echo " -s | --release | release Build a release version, can have an optional added image "
echo " name (with optional tag)"
echo " -p | --helm | helm Build the helm package"
echo " | --code | code Open a code editor"
echo " -h | --help | help Show this help message"
echo ""
echo "Additional Parameters: "
echo ""
echo " --rebuild Force rebuild images"
echo " --debug Enable debug output"
echo " --dirty Use incremental temporary runtime for the local cluster"
echo " --fast runs tests only on one virtual browser and resolution."
echo " --hold Keep cluster running after e2e tests (requires manual shutdown)"
echo ""
echo "Example:"
echo " ./tooling build run"
echo " ./tooling -b -r"
echo ""
printSeparatorLine "-"
echo "Documentation can be found at https://docs.uitsmijter.io"
echo ""
}
## Image Tag Definition
TAG="${IMAGENAME}:${GIT_BRANCH}-${GIT_HASH}"
## Parsing parameters to overwrite some default values
dockerComposeBuildParameter=""
MODE=""
DEBUG=""
USE_DIRTY=""
USE_FAST=""
USE_HOLD=""
FILTER=
PARAMS=""
COUNT=$#
if [ ${COUNT} == 0 ]; then
help
fi
while (("$#")); do
case "$1" in
-h | --help | help)
help
shift 1
exit 0
;;
-rm | --remove | remove)
MODE+="|remove"
shift 1
;;
-b | --build | build)
MODE+="|build"
shift 1
;;
-l | --lint | lint)
MODE+="|lint"
shift 1
;;
-t | --test | test)
MODE+="|test"
shift 1
if [[ -n ${1} ]] && [[ ${1} != "--"* ]]; then
# Convert dashes to underscores for Swift test compatibility
# Swift test converts target names with dashes to underscores in test identifiers
FILTER=${1//-/_}
shift 1
fi
;;
-o | --list-tests | list-tests)
MODE+="|listtests"
shift 1
if [[ -n ${1} ]] && [[ ${1} != "--"* ]]; then
# Convert dashes to underscores for Swift test compatibility
# Swift test converts target names with dashes to underscores in test identifiers
FILTER=${1//-/_}
shift 1
fi
;;
-e | --e2e | e2e)
MODE+="|e2e"
shift 1
;;
--filter)
if [[ -n ${2} ]] && [[ ${2} != "--"* ]]; then
FILTER=${2}
shift 2
else
echo "Error: --filter requires a value" >&2
exit 1
fi
;;
-r | --run | run)
MODE+="|build|run"
shift 1
;;
-c | --run-cluster | run-cluster)
MODE+="|cluster"
shift 1
;;
-d | --run-docker | run-docker)
MODE+="|docker"
shift 1
;;
-i | --images | images)
MODE+="|imagetool"
shift 1
;;
--release | release)
MODE+="|release|helm"
shift 1
;;
-p | --helm | helm)
MODE+="|helm"
shift 1
;;
--code | code)
MODE+="|code"
shift 1
;;
# Extra Parameter
--rebuild)
dockerComposeBuildParameter="--build"
shift 1
;;
--debug)
DEBUG=1
shift 1
;;
--dirty)
USE_DIRTY=1
shift 1
;;
--fast)
USE_FAST=1
shift 1
;;
--hold)
USE_HOLD=1
shift 1
;;
--) # end argument parsing
shift
break
;;
--* | -*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
echo "Possible options are: --remove --build --lint --test --e2e --run --run-cluster --release --helm and --help"
echo "Possible flags: --rebuild --debug"
exit 1
;;
*) # preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# set positional arguments in their proper place
eval set -- "$PARAMS"
# semantic checks
if [[ "${MODE}" == *"run"* ]] && [[ "${MODE}" == *"cluster"* ]]; then
echo "Uitsmijter can run as docker standalone application or in a local Kubernetes cluster. Not both." "!"
echo ""
exit 1
fi
if [[ "${MODE}" == *"release"* ]] && [[ -n "${USE_DIRTY}" ]]; then
echo "${SYMBOL_FAIL} It is not allowed to build a dirty release." "!"
echo ""
exit 1
fi
if [[ "${MODE}" != *"e2e"* ]] && [[ -n "${USE_FAST}" ]]; then
echo "${SYMBOL_FAIL} Fast makes sense for e2e tests only" "!"
echo ""
exit 1
fi
# Settings
shouldDebug "${DEBUG}"
# Execute pipeline
if [[ "${MODE}" == *"|remove"* ]]; then
removeContainer
removeImages
removeVolumes
removeBuild
fi
if [[ "${MODE}" == *"|imagetool"* ]]; then
buildImages
fi
if [[ "${MODE}" == *"|build"* ]]; then
buildIncrementalBinary "${dockerComposeBuildParameter}"
fi
if [[ "${MODE}" == *"|lint"* ]]; then
lintCode
fi
if [[ "${MODE}" == *"|test"* ]]; then
if [[ -n ${FILTER} ]]; then
FILTER=" --filter ${FILTER}"
fi
unitTests "${dockerComposeBuildParameter}" "${FILTER}"
fi
if [[ "${MODE}" == *"|listtests"* ]]; then
if [[ -n ${FILTER} ]]; then
FILTER=" --filter ${FILTER}"
fi
unitTestsList "${dockerComposeBuildParameter}" "${FILTER}"
fi
if [[ "${MODE}" == *"|run"* ]]; then
runInDocker
fi
if [[ "${MODE}" == *'|release'* ]]; then
buildRelease "${TAG}"
fi
if [[ "${MODE}" == *"|code"* ]]; then
openCode
fi
if [[ "${MODE}" == *"|helm"* ]]; then
buildHelm
fi
if [[ "${MODE}" == *'|cluster'* ]]; then
runInKubernetesInDocker "${TAG}"
fi
if [[ "${MODE}" == *'docker'* ]]; then
runInDockerProduction "${IMAGENAME}" "${GIT_BRANCH}-${GIT_HASH}"
fi
if [[ "${MODE}" == *"e2e"* ]]; then
EXTRAS=""
if [ -n "${USE_FAST}" ]; then
EXTRAS="--browser chromium"
fi
if [[ -n "${FILTER}" ]]; then
# Pass filter as a single argument by escaping it properly
EXTRAS="${EXTRAS} --grep '${FILTER}'"
fi
e2eTests "${dockerComposeBuildParameter}" "${EXTRAS}" "${TAG}" "${USE_HOLD}"
fi
echo ""
echoBanner "done." "*"
echo ""