-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtest-debs
executable file
·208 lines (195 loc) · 6.11 KB
/
test-debs
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
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/library.sh
source "$SELFDIR/lib/library.sh"
SERVER=
IMAGE=
EXPECTED_VARIANT=
RUBY_DEB_PATH=
RBENV_DEB_PATH=
COMMON_DEB_PATH=
APT_DISTRO_NAME=
RUBY_PACKAGE_VERSION=
DEBUG_AFTER_TESTS=false
function usage()
{
echo "Usage: ./test-debs <OPTIONS>"
echo "Test built Debian packages. Either tests local .deb files (which"
echo "is the default mode), or tests packages on an actual APT server."
echo
echo "Required options:"
echo " -S URL Test packages on the given APT server, not local files"
echo " (e.g. https://apt.fullstaqruby.org)"
echo " -i IMAGE Image name to run test in (e.g. ubuntu:18.04)"
echo " -v VARIANT Expected variant name (one of: normal, jemalloc, malloctrim)"
echo
echo "Required options (local file mode):"
echo " -r PATH Path to Ruby DEB package"
echo " -b PATH Path to Rbenv DEB package"
echo " -c PATH Path to fullstaq-ruby-common DEB package"
echo
echo "Required options (server mode):"
echo " -d NAME APT repo distribution name (e.g. ubuntu-18.04)"
echo " -n VERSION Ruby package version to test against"
echo " (e.g. 2.6; 2.6-jemalloc)"
echo
echo "Optional options:"
echo " -D Open a debug shell after tests have run"
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local ORIG_ARGV
local opt
while getopts "S:i:v:r:b:c:d:n:Dh" opt; do
case "$opt" in
S)
SERVER="$OPTARG"
;;
i)
IMAGE="$OPTARG"
;;
v)
EXPECTED_VARIANT="$OPTARG"
;;
r)
RUBY_DEB_PATH=$(absolute_path "$OPTARG")
;;
b)
RBENV_DEB_PATH=$(absolute_path "$OPTARG")
;;
c)
COMMON_DEB_PATH=$(absolute_path "$OPTARG")
;;
d)
APT_DISTRO_NAME="$OPTARG"
;;
n)
RUBY_PACKAGE_VERSION="$OPTARG"
;;
D)
DEBUG_AFTER_TESTS=true
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
ORIG_ARGV=("$@")
if [[ "$SERVER" = "" ]]; then
if [[ "$RUBY_DEB_PATH" = "" ]]; then
echo 'ERROR: please specify a Ruby DEB package path with -r.' >&2
exit 1
fi
if [[ ! -e "$RUBY_DEB_PATH" ]]; then
echo "ERROR: $RUBY_DEB_PATH does not exist." >&2
exit 1
fi
if [[ "$RBENV_DEB_PATH" = "" ]]; then
echo 'ERROR: please specify an Rbenv DEB package path with -b.' >&2
exit 1
fi
if [[ ! -e "$RBENV_DEB_PATH" ]]; then
echo "ERROR: $RBENV_DEB_PATH does not exist." >&2
exit 1
fi
if [[ "$COMMON_DEB_PATH" = "" ]]; then
echo 'ERROR: please specify a fullstaq-ruby-common DEB package path with -c.' >&2
exit 1
fi
if [[ ! -e "$COMMON_DEB_PATH" ]]; then
echo "ERROR: $COMMON_DEB_PATH does not exist." >&2
exit 1
fi
if [[ "$APT_DISTRO_NAME" != "" ]]; then
echo 'ERROR: if -S is not given, then -d may also not be given.' >&2
exit 1
fi
if [[ "$RUBY_PACKAGE_VERSION" != "" ]]; then
echo 'ERROR: if -S is not given, then -n may also not be given.' >&2
exit 1
fi
else
if [[ "$RUBY_DEB_PATH" != "" ]]; then
echo 'ERROR: if -S is given, then -r may not be given.' >&2
exit 1
fi
if [[ "$RBENV_DEB_PATH" != "" ]]; then
echo 'ERROR: if -S is given, then -b may not be given.' >&2
exit 1
fi
if [[ "$COMMON_DEB_PATH" != "" ]]; then
echo 'ERROR: if -S is given, then -c may not be given.' >&2
exit 1
fi
if [[ "$APT_DISTRO_NAME" = "" ]]; then
echo 'ERROR: please specify an APT repo distro name with -d.' >&2
exit 1
fi
if [[ "$RUBY_PACKAGE_VERSION" = "" ]]; then
echo 'ERROR: please specify a Ruby package version to test with -n.' >&2
exit 1
fi
fi
if [[ "$IMAGE" = "" ]]; then
echo 'ERROR: please specify an image name with -i.' >&2
exit 1
fi
if [[ "$EXPECTED_VARIANT" != normal && "$EXPECTED_VARIANT" != jemalloc && "$EXPECTED_VARIANT" != malloctrim ]]; then
echo 'ERROR: please specify a valid variant name with -v.' >&2
exit 1
fi
}
parse_options "$@"
if tty -s; then
TTY_ARGS=(-t -i)
else
TTY_ARGS=()
fi
RUN_ARGS=()
UTILITY_IMAGE_VERSION=$(read_single_value_file "$SELFDIR/environments/utility/image_tag")
TEMP_DIR=$(mktemp -d /tmp/test.XXXXXX)
function _cleanup()
{
rm -rf "$TEMP_DIR"
}
mkdir -p "$TEMP_DIR/repo"
if [[ "$SERVER" = "" ]]; then
echo '--- Entering preparation Docker container ---'
verbose_run docker run --rm --init "${TTY_ARGS[@]}" \
-v "$SELFDIR:/system:ro" \
-v "$RUBY_DEB_PATH:/input/$(basename "$RUBY_DEB_PATH"):ro" \
-v "$RBENV_DEB_PATH:/input/$(basename "$RBENV_DEB_PATH"):ro" \
-v "$COMMON_DEB_PATH:/input/$(basename "$COMMON_DEB_PATH"):ro" \
-v "$TEMP_DIR/repo:/output" \
--user "$(id -u):$(id -g)" \
"ghcr.io/fullstaq-ruby/server-edition-ci-images:utility-v$UTILITY_IMAGE_VERSION" \
/system/container-entrypoints/test-debs-prepare
echo
RUN_ARGS+=()
else
RUN_ARGS+=(
-e "APT_DISTRO_NAME=$APT_DISTRO_NAME"
-e "RUBY_PACKAGE_VERSION=$RUBY_PACKAGE_VERSION"
)
fi
echo '--- Entering main Docker container ---'
verbose_run docker run --rm --init "${TTY_ARGS[@]}" \
-v "$SELFDIR:/system:ro" \
-v "$TEMP_DIR/repo:/input/repo:ro" \
-e "SERVER=$SERVER" \
-e "EXPECTED_VARIANT=$EXPECTED_VARIANT" \
-e "DEBUG_AFTER_TESTS=$DEBUG_AFTER_TESTS" \
"${RUN_ARGS[@]}" \
--user root \
--entrypoint /system/container-entrypoints/test-debs \
"$IMAGE"