-
Notifications
You must be signed in to change notification settings - Fork 5
/
run.sh
executable file
·273 lines (217 loc) · 10.4 KB
/
run.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
#!/bin/bash
MAIL_FROM=""
MAIL_TO=""
DISCORD_WEBHOOK=""
RELEASE="" # e.g., rockylinux8, rockylinux9, debianbuster, debianbullseye, debianbookworm, ubuntu20, ubuntu22, ubuntu24
PACKAGE="" # e.g., cento, n2disk, nprobe, ntopng, nedge, nscrub, ntap, pfring
DOCKER="sudo docker"
TAG="development"
STABLE_SUFFIX=""
# Import functions to send out alerts
source utils/alerts.sh
function usage {
echo "Usage: run.sh [--cleanup] | [-m=stable] [-f=<mail from>] [-t=<mail to>] [-d=<discord webhook>] [-r=<release>] [-p=<package>]"
echo ""
echo "-m=<branch> : Select branch."
echo " Available branches: dev (default), stable."
echo "-r|--release=<release> : Builds for a specific release. Optional, all releases are built when not specified."
echo " Available releases: rockylinux8, rockylinux9, debianbuster (10), debianbullseye (11), debianbookworm (12), ubuntu20, ubuntu22, ubuntu24."
echo "-p|--package=<package> : Builds a specific package. Optional, all packages are built when not specified."
echo " Available packages: cento, n2disk, nprobe, ntopng, nedge, nscrub, ntap, pfring."
echo "-c|--cleanup : clears all docker images and containers"
echo ""
echo "This tool will build some empty docker containers where ntop packages"
echo "will be installed. This tool will make some tests and report"
echo "results via email, thus it is necessary to set -f and -t."
exit 0
}
function cleanup {
\rm -f *~ &> /dev/null
CONT=$(${DOCKER} ps -a -q | xargs)
if [[ $CONT ]]; then
echo "Cleaning up containers: ${CONT}"
${DOCKER} rm -f ${CONT}
fi
#IMGS=$(${DOCKER} images -q --filter "dangling=true" | xargs)
IMGS=$(${DOCKER} images -q | xargs)
if [[ $IMGS ]]; then
echo "Cleaning up images: ${IMGS}"
${DOCKER} rmi -f ${IMGS}
fi
# Purge /var/lib/docker/overlay2/
${DOCKER} system prune -a -f
}
#############
for i in "$@"
do
case $i in
-m=*|--mode=*)
if [ "${i#*=}" == "stable" ]; then
STABLE_SUFFIX="-stable"
TAG="stable"
fi
;;
-f=*|--mail-from=*)
MAIL_FROM="${i#*=}"
;;
-t=*|--mail-to=*)
MAIL_TO="${i#*=}"
;;
-d=*|--discord-webhook=*)
DISCORD_WEBHOOK="${i#*=}"
;;
-r=*|--release=*)
RELEASE="${i#*=}"
;;
-p=*|--package=*)
PACKAGE="${i#*=}"
;;
-c|--cleanup)
cleanup
exit 0
;;
-h|--help)
usage
exit 0
;;
*)
# unknown option
;;
esac
done
if [ -z "$MAIL_FROM" ] || [ -z "$MAIL_TO" ] ; then
echo "Warning: please specify -f=<from> -t=<to> to send alerts by mail"
fi
if [ -z "$DISCORD_WEBHOOK" ] ; then
echo "Warning: please specify -d=<discord webhook url> to send alerts to Discord"
fi
OUT="out-${TAG}"
/bin/rm -rf ${OUT}
mkdir -p ${OUT}/generic
# Producing Dockerfile(s)
# Ubuntu
sed -e "s:VERSION:20.04:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.ubuntu.seed > ${OUT}/generic/Dockerfile.ubuntu20
sed -e "s:VERSION:22.04:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.ubuntu.seed > ${OUT}/generic/Dockerfile.ubuntu22
sed -e "s:VERSION:24.04:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.ubuntu.seed > ${OUT}/generic/Dockerfile.ubuntu24
# Debian
#sed -e "s:VERSION:stretch:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.debian.seed > ${OUT}/generic/Dockerfile.debianstretch
sed -e "s:VERSION:buster:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.debian.seed > ${OUT}/generic/Dockerfile.debianbuster
sed -e "s:VERSION:bullseye:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.debian.seed > ${OUT}/generic/Dockerfile.debianbullseye
sed -e "s:VERSION:bookworm:g" -e "s:STABLE:${STABLE_SUFFIX}:g" docker/Dockerfile.debian.seed > ${OUT}/generic/Dockerfile.debianbookworm
# Rocky Linux
sed -e "s:DISTRIBUTION:rockylinux:g" -e "s:VERSION:8:g" -e "s:CENTOS7:#:g" -e "s:CENTOS8:#:g" -e "s:ROCKYLINUX::g" -e "s:STABLE:${STABLE_SUFFIX}:g" -e "s:POWERTOOLS:powertools:g" docker/Dockerfile.centos.seed > ${OUT}/generic/Dockerfile.rockylinux8
sed -e "s:DISTRIBUTION:rockylinux:g" -e "s:VERSION:9:g" -e "s:CENTOS7:#:g" -e "s:CENTOS8:#:g" -e "s:ROCKYLINUX::g" -e "s:STABLE:${STABLE_SUFFIX}:g" -e "s:POWERTOOLS:crb:g" docker/Dockerfile.centos.seed > ${OUT}/generic/Dockerfile.rockylinux9
INSTALLATION_FAILURES=0
INSTALLATION_FAILED_IMAGES=""
FUNCTIONAL_FAILURES=0
FUNCTIONAL_FAILED_IMAGES=""
IMAGES=""
# Cleanup all containers/images
cleanup
# ########################################################################################################################
# Build and test docker images for each supported distro and for each softare product so to test everything independently
# ########################################################################################################################
for DOCKERFILE_GENERIC in ${OUT}/generic/Dockerfile.*; do
DOCKERFILE_RELEASE="${DOCKERFILE_GENERIC##*.}"
for ENTRYPOINT in entrypoints/*.sh; do
ENTRYPOINT_SH=`basename ${ENTRYPOINT}`
PACKAGES_LIST=`cat $ENTRYPOINT | grep TEST_PACKAGES | cut -d ':' -f 2 | xargs`
IMG="${DOCKERFILE_RELEASE}.${TAG}.${PACKAGES_LIST// /.}"
DOCKERFILE=${OUT}/Dockerfile.${IMG}
# #################################################################################################################
# INSTALLATION TEST
# #################################################################################################################
#if [[ "${IMG}" =~ "ubuntu24.stable.".* ]]; then
# # Skip stable for ubuntu24
# continue
#fi
if [[ "${IMG}" =~ "debianbullseye.".*"ntap".* ]] ||
[[ "${IMG}" =~ "rockylinux.".*"ntap".* ]]; then
# Skip ntap for distrubutions with no package
continue
fi
if [ "rockylinux8.development.n2disk" == ${IMG} ] ||
[ "rockylinux8.stable.n2disk" == ${IMG} ] ||
[ "rockylinux9.development.n2disk" == ${IMG} ] ||
[ "rockylinux9.stable.n2disk" == ${IMG} ]; then
# Seems n2disk on centos8 attempts to install kernel-related stuff which is not supported on docker
continue
fi
if [ "$IMG" = "seed" ]; then
continue
fi
if [ "$PACKAGES_LIST" = "nedge" ] && [[ ${IMG} != ubuntu20.* ]] && [[ ${IMG} != ubuntu24.development.* ]]; then
# nedge is supported on Ubuntu 20 (stable, development) and 24 (development) only
continue
fi
if [ ! -z "${RELEASE}" ]; then
if [ "x${RELEASE}" != "x${DOCKERFILE_RELEASE}" ]; then
# A specific release has been requested, skip releases that are not matching
continue
fi
fi
if [ ! -z "${PACKAGE}" ]; then
if [ "x${PACKAGE}" != "x${PACKAGES_LIST}" ]; then
# A specific package has been requested, skip releases that are not matching
continue
fi
fi
echo "Preparing docker image ${IMG} [packages: $PACKAGES_LIST] [entrypoint: $ENTRYPOINT]"
sed -e "s:PACKAGES_LIST:${PACKAGES_LIST}:g" \
-e "s:ENTRYPOINT_PATH:${ENTRYPOINT}:g" \
-e "s:ENTRYPOINT_SH:${ENTRYPOINT_SH}:g" \
${DOCKERFILE_GENERIC} > ${DOCKERFILE}
MAX_ATTEMPTS=2
attempt=1
while [ $attempt -le $MAX_ATTEMPTS ]
do
echo "Running ${DOCKER} build --no-cache -t ${IMG} -f ${DOCKERFILE} ."
${DOCKER} build --no-cache -t ${IMG} -f ${DOCKERFILE} . &> ${OUT}/${IMG}${STABLE_SUFFIX}.log
if [ $? == 0 ]; then break; fi
let attempt=attempt+1
echo -e "Attempt #$attempt.."
done
if [ "$attempt" -gt "$MAX_ATTEMPTS" ];
then
echo "FAIL Failed ${DOCKER} build -t ${IMG} -f ${DOCKERFILE} . [see ${OUT}/${IMG}${STABLE_SUFFIX}.log for more details]"
let INSTALLATION_FAILURES=INSTALLATION_FAILURES+1
INSTALLATION_FAILED_IMAGES="${IMG} ${INSTALLATION_FAILED_IMAGES}"
# Sending mail with log
if [[ ! -s ${OUT}/${IMG}${STABLE_SUFFIX}.log ]]; then
echo "No log output during the BUILD phase" > "${OUT}/${IMG}${STABLE_SUFFIX}.log"
fi
sendError "Packages INSTALLATION failed on ${IMG} ${TAG}" "" "${OUT}/${IMG}${STABLE_SUFFIX}.log" "2"
else
IMAGES="${IMAGES} ${IMG}"
# #################################################################################################################
# FUNCTIONAL TESTS
# #################################################################################################################
echo -n "Testing ${IMG}... "
${DOCKER} run ${IMG} test &> ${OUT}/${IMG}${STABLE_SUFFIX}_test.log
if [ $? != 0 ]; then
echo "FAIL Failed to execute: ${DOCKER} run ${IMG} test [see ${OUT}/${IMG}${STABLE_SUFFIX}_test.log for more details]"
let FUNCTIONAL_FAILURES=FUNCTIONAL_FAILURES+1
FUNCTIONAL_FAILED_IMAGES="${IMG} ${FUNCTIONAL_FAILED_IMAGES}"
# Sending mail with log
if [[ ! -s ${OUT}/${IMG}${STABLE_SUFFIX}_test.log ]]; then
echo "No log output during the TEST phase" > "${OUT}/${IMG}${STABLE_SUFFIX}_test.log"
fi
sendError "Packages TEST failed for ${IMG} ${TAG}" "" "${OUT}/${IMG}${STABLE_SUFFIX}_test.log" "2"
else
echo "OK"
fi
fi
done
# Cleaning up created images/containers to make room on disk
cleanup
done
if [ "$INSTALLATION_FAILURES" -ne "0" ]; then
sendError "${TAG} packages INSTALLATION failed on $INSTALLATION_FAILURES images" "Unable to build docker images: ${INSTALLATION_FAILED_IMAGES}" "" "2"
else
sendSuccess "${TAG} packages INSTALLATION completed successfully" "All docker images built correctly."
fi
if [ "$FUNCTIONAL_FAILURES" -ne "0" ]; then
sendError "${TAG} packages TEST failed on $FUNCTIONAL_FAILURES images" "Unable to TEST docker images: ${FUNCTIONAL_FAILED_IMAGES}" "" "2"
else
sendSuccess "${TAG} packages TEST completed successfully" "All docker images test correctly."
fi