-
Notifications
You must be signed in to change notification settings - Fork 1k
/
run-public-image-tests.sh
executable file
·103 lines (75 loc) · 1.81 KB
/
run-public-image-tests.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
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
port=9000
info() {
echo "[info] $@"
}
warn() {
echo "[warn] $@" >&2
}
fatal() {
echo "[error] $@" >&2
exit 1
}
require() {
local prog missing=()
for prog; do
if ! type "$prog" &>/dev/null; then
missing+=("$prog")
fi
done
[[ ${#missing[@]} = 0 ]] || fatal "could not find reqired programs on the path: ${missing[@]}"
}
wait_for_sonarqube() {
local image=$1 i web_up=no sonarqube_up=no
for ((i = 0; i < 10; i++)); do
info "$image: waiting for web server to start ..."
if curl -sI localhost:$port | grep '^HTTP/.* 200'; then
web_up=yes
break
fi
sleep 5
done
[[ $web_up = yes ]] || return 1
for ((i = 0; i < 10; i++)); do
info "$image: waiting for sonarqube to be ready ..."
if curl -s localhost:$port/api/system/status | grep '"status":"UP"'; then
sonarqube_up=yes
break
fi
sleep 10
done
[[ "$sonarqube_up" = yes ]]
}
sanity_check_image() {
local image=$1 id result
docker system prune -fa
docker pull ${image}
id=$(docker run -d -p ${port}:9000 "$image")
info "$image: container started: $id"
if wait_for_sonarqube "$image"; then
info "$image: OK !"
result=ok
else
warn "$image: could not confirm service started"
result=failure
fi
info "$image: stopping container: $id"
docker container stop "$id"
[[ $result == ok ]]
}
require curl docker
results=()
if sanity_check_image "sonarqube"; then
results+=("success")
else
results+=("failure")
fi
echo
failures=0
echo "sonarqube => ${results[0]}"
if [[ ${results[0]} != success ]]; then
((failures++)) || :
fi
[[ ${failures} = 0 ]]