-
Notifications
You must be signed in to change notification settings - Fork 8
/
test
executable file
·164 lines (154 loc) · 4.03 KB
/
test
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
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=internal/lib/library.sh
source "$SELFDIR/internal/lib/library.sh"
# shellcheck source=internal/lib/distro_info.sh
source "$SELFDIR/internal/lib/distro_info.sh"
PASSENGER_DIR=
DISTRIBUTION=
OUTPUT_DIR=
CACHE_DIR=
RPM_ARCH=
DOCKER_ARCH=
DEBUG_CONSOLE=false
DEBUG_CONSOLE_ON_FAIL=false
PASSENGER_ENTERPRISE_LICENSE_KEY=
JENKINS=false
function usage()
{
echo "Usage: ./test [OPTIONS]"
echo "Test built packages."
echo
echo "Required options:"
echo " -p DIR Path to Passenger source code"
echo " -x DISTRO Distribution to run tests in: centos7,rocky8,rocky9"
echo " -d DIR Path to built packages"
echo " -c DIR Path to cache directory"
echo " -a ARCH Test only given RPM architecture: x86_64 or aarch64"
echo " -A ARCH Docker architecture to use: amd64 or arm64"
echo
echo "Optional options:"
echo " -O Open debugging console instead of running test script"
echo " -D Open debugging console on test failure"
echo " -e Use the given Passenger Enterprise license key"
echo " -j Indicate that this script is run from a Jenkins job"
echo
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "p:a:A:x:d:c:ODe:jh" opt; do
case "$opt" in
p)
PASSENGER_DIR="$OPTARG"
;;
a)
RPM_ARCH="$OPTARG"
;;
A)
DOCKER_ARCH="$OPTARG"
;;
x)
DISTRIBUTION="$OPTARG"
;;
d)
OUTPUT_DIR="$OPTARG"
;;
c)
CACHE_DIR="$OPTARG"
;;
O)
DEBUG_CONSOLE=true
;;
D)
DEBUG_CONSOLE_ON_FAIL=true
;;
e)
PASSENGER_ENTERPRISE_LICENSE_KEY="$OPTARG"
;;
j)
JENKINS=true
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
if [[ "$PASSENGER_DIR" = "" ]]; then
echo "ERROR: please specify a Passenger source directory with -p."
exit 1
fi
if [[ "$RPM_ARCH" = "" ]]; then
echo "ERROR: please specify an RPM architecture with -a."
exit 1
fi
if [[ "$DOCKER_ARCH" = "" ]]; then
echo "ERROR: please specify a Docker architecture with -A."
exit 1
fi
if [[ "$DISTRIBUTION" = "" ]]; then
echo "ERROR: please specify a distribution with -x."
exit 1
else
TEST_IMAGE="$(distro_name_to_testbox_image "$DISTRIBUTION")"
DYNAMIC_MODULE_SUPPORTED="$(dynamic_module_supported "$DISTRIBUTION")"
fi
if [[ "$OUTPUT_DIR" = "" ]]; then
echo "ERROR: please specify a build products directory with -d."
exit 1
fi
if [[ "$CACHE_DIR" = "" ]]; then
echo "ERROR: please specify a cache directory with -c."
exit 1
fi
}
parse_options "$@"
PASSENGER_DIR="$(absolute_path "$PASSENGER_DIR")"
OUTPUT_DIR="$(absolute_path "$OUTPUT_DIR")"
CACHE_DIR="$(absolute_path "$CACHE_DIR")"
EXTRA_ARGS=()
if [[ "$PASSENGER_ENTERPRISE_LICENSE_KEY" != "" ]]; then
PASSENGER_ENTERPRISE_LICENSE_KEY="$(absolute_path "$PASSENGER_ENTERPRISE_LICENSE_KEY")"
EXTRA_ARGS+=(-v "$PASSENGER_ENTERPRISE_LICENSE_KEY:/etc/passenger-enterprise-license:ro")
fi
if tty -s; then
EXTRA_ARGS+=(-t -i)
fi
if [[ -e /sys/kernel/security/apparmor ]]; then
EXTRA_ARGS+=(--security-opt=apparmor:unconfined)
fi
run mkdir -p "$CACHE_DIR/test-$DISTRIBUTION/yumcache"
echo "-------- Entering Docker container --------"
exec docker run \
--rm \
--platform "$PLAT" \
-v "$SELFDIR/internal:/system/internal:ro" \
-v "$PASSENGER_DIR:/passenger:ro" \
-v "$OUTPUT_DIR:/output:ro" \
-v "$CACHE_DIR:/cache" \
-v "$CACHE_DIR/test-$DISTRIBUTION/yumcache:/var/cache/yum" \
"${EXTRA_ARGS[@]}" \
-e "DISTRIBUTION=$DISTRIBUTION" \
-e "DYNAMIC_MODULE_SUPPORTED=$DYNAMIC_MODULE_SUPPORTED" \
-e "DEBUG_CONSOLE=$DEBUG_CONSOLE" \
-e "DEBUG_CONSOLE_ON_FAIL=$DEBUG_CONSOLE_ON_FAIL" \
-e "JENKINS=$JENKINS" \
-e "RPM_ARCH=$RPM_ARCH" \
-e "APP_UID=$(/usr/bin/id -u)" \
-e "APP_GID=$(/usr/bin/id -g)" \
--platform "linux/$DOCKER_ARCH" \
"$TEST_IMAGE" \
/system/internal/scripts/my_init --quiet --skip-runit --skip-startup-files -- \
/system/internal/scripts/inituidgid.sh \
/system/internal/test/misc/init.sh \
/system/internal/test/test.sh