-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-package.sh
executable file
·148 lines (121 loc) · 6.01 KB
/
test-package.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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
if [ -n "${DEBUG:-}" ]; then
set -x
fi
# Retries a command a configurable number of times with backoff.
#
# The retry count is given by ATTEMPTS (default 5), the initial backoff
# timeout is given by TIMEOUT in seconds (default 1.)
#
# Successive backoffs double the timeout.
function with_backoff {
local max_attempts=${ATTEMPTS-5}
local timeout=${TIMEOUT-5}
local attempt=1
local exitCode=0
while (( $attempt < $max_attempts ))
do
if "$@"
then
return 0
else
exitCode=$?
fi
echo "Failure! Retrying in $timeout.." 1>&2
sleep $timeout
attempt=$(( attempt + 1 ))
timeout=$(( timeout * 2 ))
done
if [[ $exitCode != 0 ]]
then
echo "You've failed me for the last time! ($@)" 1>&2
fi
return $exitCode
}
function main() {
OPERATING_SYSTEM=${OPERATING_SYSTEM:-ubuntu}
OPERATING_SYSTEM_VERSION=${OPERATING_SYSTEM_VERSION:-22.04}
DOCKER_ARCHITECTURE=${DOCKER_ARCHITECTURE:-amd64}
PACKAGE_TYPE=${PACKAGE_TYPE:-deb}
if [[ "$OPERATING_SYSTEM" == "rhel" ]]; then
OPERATING_SYSTEM="redhat/ubi${OPERATING_SYSTEM_VERSION}"
OPERATING_SYSTEM_VERSION="latest"
fi
USE_TTY="-t"
test -t 1 && USE_TTY="-it"
docker kill package-validation-tests || true
sleep 5
docker run -d --rm \
--name package-validation-tests \
--platform="linux/$DOCKER_ARCHITECTURE" \
-v "${PWD}/package:/src" \
${OPERATING_SYSTEM}:${OPERATING_SYSTEM_VERSION} \
tail -f /dev/null || true
if [[ "$PACKAGE_TYPE" == "deb" ]]; then
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "apt-get update"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "apt-get install -y perl-base zlib1g-dev procps"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "apt install --yes /src/*.deb"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "kong version"
fi
if [[ "$PACKAGE_TYPE" == "rpm" ]]; then
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "yum install -y /src/*.rpm procps util-linux"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "kong version"
fi
if [[ "$PACKAGE_TYPE" == "apk" ]]; then
exit 0
fi
# Kong can start, restart, and stop as the Kong user
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "su - kong -c 'KONG_DATABASE=off kong start'"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "su - kong -c 'KONG_DATABASE=off kong health'"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "ps aux | grep nginx | grep -v grep | grep -q kong"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "su - kong -c 'KONG_DATABASE=off kong restart'"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "su - kong -c 'KONG_DATABASE=off kong health'"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "ps aux | grep nginx | grep -v grep | grep -q kong"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "su - kong -c 'KONG_DATABASE=off kong stop'"
# Kong can start, restart, and stop as the root user
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "KONG_DATABASE=off kong start"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "KONG_DATABASE=off kong health"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "ps aux | grep nginx | grep -v grep | grep -q root"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "KONG_DATABASE=off kong restart"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "KONG_DATABASE=off kong health"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "ps aux | grep nginx | grep -v grep | grep -q root"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "KONG_DATABASE=off kong stop"
docker exec ${USE_TTY} package-validation-tests /bin/bash -c "luarocks install version"
docker exec ${USE_TTY} package-validation-tests /bin/sh -c "ls -l /etc/kong/kong.conf.default"
docker exec ${USE_TTY} package-validation-tests /bin/sh -c "ls -l /etc/kong/kong*.logrotate"
docker exec ${USE_TTY} package-validation-tests /bin/sh -c "ls -l /usr/local/kong/include/google/protobuf/*.proto"
docker exec ${USE_TTY} package-validation-tests /bin/sh -c "ls -l /usr/local/kong/include/openssl/*.h"
docker kill package-validation-tests
if [[ "$OPERATING_SYSTEM" == "rhel" ]]; then
docker kill systemd || true
sleep 5
docker run -d --rm --name=systemd --privileged --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v ${PWD}/package:/src redhat/ubi8-init
docker exec ${USE_TTY} systemd /bin/bash -c "yum install -y /src/*.rpm procps util-linux"
docker exec ${USE_TTY} systemd /bin/bash -c "kong version"
docker exec ${USE_TTY} systemd /bin/bash -c "test -f /etc/kong/kong*.logrotate"
docker exec ${USE_TTY} systemd /bin/bash -c "mkdir -p /etc/systemd/system/kong.service.d/"
docker exec ${USE_TTY} systemd /bin/bash -c "cat <<\EOD > /etc/systemd/system/kong.service.d/override.conf
[Service]
Environment=KONG_DATABASE=off KONG_NGINX_MAIN_WORKER_PROCESSES=2
EOD"
sleep 5
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl daemon-reload"
sleep 5
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl start kong"
docker exec ${USE_TTY} systemd /bin/bash -c 'for i in {1..15}; do if test -s /usr/local/kong/pids/nginx.pid; then break; fi; echo waiting for pidfile...; sleep 1; done'
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl --no-pager status kong"
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl reload kong"
sleep 5
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl --no-pager status kong"
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl restart kong"
sleep 5
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl --no-pager status kong"
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl stop kong"
sleep 5
docker exec ${USE_TTY} systemd /bin/bash -c "systemctl --no-pager status kong || true" # systemctl will exit with 3 if unit is not active
docker kill systemd
fi
}
main