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
|
#!/bin/bash
ME=$(basename $0)
###############################################################################
# BEGIN user-customizable section
# Buildah main repository; unlikely to change often
BUILDAH_REPO=github.com/containers/buildah
# Tag name used to identify the base checkout
BASE_TAG=buildah-bud-in-podman
# END user-customizable section
###############################################################################
usage="Usage: $ME [--help] [--no-checkout] [--no-test] [--filter=TESTNAME]
Flags, useful for manual debugging:
--no-checkout Skip checkout step, go directly to running tests
--no-test Do checkout only, but do not run tests
--filter=NAME Passed on to bats; runs only tests that match NAME
"
# Parse command-line options (used in development only, not in CI)
do_checkout=y
do_test=y
declare -a bats_filter=()
for i; do
value=$(expr "$i" : '[^=]*=\(.*\)')
case "$i" in
--no-checkout) do_checkout= ; shift;;
--no-test) do_test= ; shift;;
--filter=*) bats_filter=("--filter" "$value"); shift;;
-h|--help) echo "$usage"; exit 0;;
*) echo "$ME: Unrecognized option '$i'" >&2; exit 1;;
esac
done
# Patches helpers.bash and potentially other files (bud.bats? Dockerfiles?)
#
# The patch file is horrible to generate:
# 1) cd to the checked-out buildah/tests directory
# 2) make your edits
# 3) git commit -asm 'blah blah blah'
# 3a) if checked-out directory already includes earlier patches,
# you may need to 'git commit --amend' instead
# 4) git format-patch HEAD^
# 5) sed -e 's/ \+$//' 0001* >../PATCH-FILE-PATH
# 6) vim that file, remove trailing empty newlines
# 7) cd back out of buildah directory, and git-commit this new patch file
#
# FIXME: this makes me nervous. The diff will probably need tweaking
# over time. I don't think we need to version it, because we
# *have* to be in lockstep with a specific buildah version,
# so problems should only arise when we re-vendor.
# But I'm still nervous and can't put my finger on the reason.
#
# Complicated invocation needed because we 'cd' down below.
BUD_TEST_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
PATCHES=${BUD_TEST_DIR}/buildah-tests.diff
# Friendlier relative path to our buildah-tests dir
BUD_TEST_DIR_REL=$(dirname $(git ls-files --full-name ${BASH_SOURCE[0]}))
# Path to podman binary; again, do it before we cd
PODMAN_BINARY=$(pwd)/bin/podman
REMOTE=
# If remote, start server & change path
if [[ "${PODBIN_NAME:-}" = "remote" ]]; then
REMOTE=1
echo "$ME: remote tests are not working yet" >&2
exit 1
fi
function die() {
failhint=
echo "$ME: $*" >&2
exit 1
}
# From here on out, any unexpected abort will try to offer helpful hints
failhint=
trap 'if [[ $? != 0 ]]; then if [[ -n $failhint ]]; then echo;echo "***************************************";echo "$failhint";echo;echo "Please see $BUD_TEST_DIR_REL/README.md for advice";fi;fi' 0
# Find the version of buildah we've vendored in, so we can run the right tests
buildah_version=$(awk "\$1 == \"$BUILDAH_REPO\" { print \$2 }" <go.mod)
if [[ -z "$buildah_version" ]]; then
# This should not happen
die "Did not find '$BUILDAH_REPO' in go.mod"
fi
# From here on out, any error is fatal
set -e
# Before pulling buildah (while still cd'ed to podman repo), try to determine
# if this is a PR, and if so if it's a revendoring of buildah. We use this to
# try to offer a helpful hint on failure.
is_revendor=
if [[ -n $CIRRUS_CHANGE_IN_REPO ]]; then
if [[ -n $DEST_BRANCH ]]; then
head=${CIRRUS_CHANGE_IN_REPO}
# Base of this PR.
base=$(set -x;git merge-base ${DEST_BRANCH} $head)
changes=$(set -x;git diff --name-status $base $head)
if [[ -n $changes ]]; then
if [[ $changes =~ vendor/$BUILDAH_REPO ]]; then
is_revendor=y
fi
fi
fi
fi
# Pull buildah, including tests
buildah_dir=test-buildah-$buildah_version
if [[ -n $do_checkout ]]; then
if [[ -d $buildah_dir ]]; then
die "Directory already exists: $buildah_dir"
fi
# buildah_version should usually be vX.Y, but sometimes a PR under test
# will need a special unreleased version (go calls then "pseudoversions").
# In the usual case, we can do a shallow git clone:
shallow_checkout="--branch $buildah_version"
if [[ $buildah_version =~ .*-.*\.[0-9]{14}-.* ]]; then
# ...but with a pseudoversion, we must git-clone the entire repo,
# then do a git checkout within it
shallow_checkout=
fi
failhint="'git clone' failed - this should never happen!"
(set -x;git clone -q $shallow_checkout https://$BUILDAH_REPO $buildah_dir)
cd $buildah_dir
if [[ -z $shallow_checkout ]]; then
# extract the SHA (rightmost field) from, e.g., v1.2-YYYMMDD-<sha>
sha=${buildah_version##*-}
failhint="'git checkout $sha' failed - this should never happen!"
(set -x;git checkout -q $sha)
fi
# Give it a recognizable tag; this will be useful if we need to update
# the set of patches
(set -x;git tag $BASE_TAG)
# Build buildah
failhint="error building buildah. This should never happen."
(set -x;make bin/buildah)
# The upcoming patch may fail. Before we try it, create a helper script
# for a developer to push a new set of diffs to podman-land.
failhint=
sed -e "s,\[BASETAG\],${BASE_TAG},g" \
-e "s,\[BUILDAHREPO\],${BUILDAH_REPO},g" \
< ${BUD_TEST_DIR}/make-new-buildah-diffs \
> make-new-buildah-diffs
chmod 755 make-new-buildah-diffs
# Apply custom patches. We do this _after_ building, although it shouldn't
# matter because these patches should only apply to test scripts and not
# to any buildah sources.
failhint="
Error applying patch file. This can happen when you vendor in a new buildah.
You will want to:
- look for 'test/*.rej'
- resolve conflicts manually
- git add test/helpers.bash
- git am --continue
- ./make-new-buildah-diffs
"
(set -x;git am --reject <$PATCHES)
# Now apply our custom skips and error-message changes. This is maintained
# in a custom script, not a .diff file, because diffs are WAY too hard for
# humans to read and update.
APPLY=apply-podman-deltas
failhint="
Error applying podman-specific deltas. This sometimes happens when you
vendor in a new buildah. You will want to:
- inspect the errors shown above
- find the corresponding lines in $BUD_TEST_DIR_REL/$APPLY
- edit/delete them as necessary
"
(set -x;$BUD_TEST_DIR/$APPLY)
else
# Called with --no-checkout
test -d $buildah_dir || die "Called with --no-checkout, but $buildah_dir does not exist"
cd $buildah_dir
fi
if [[ -n $do_test ]]; then
failhint="Error running buildah bud tests under podman."
if [[ -n $is_revendor ]]; then
failhint+="
It looks like you're vendoring in a new buildah. The likely failure
here is that there's a new test in bud.bats that uses functionality
not (yet) in podman build. You will likely need to 'skip' that test.
"
else
failhint+="
Is it possible that your PR breaks podman build in some way? Please
review the test failure and double-check your changes.
"
fi
(set -x;sudo env TMPDIR=/var/tmp \
PODMAN_BINARY=$PODMAN_BINARY \
BUILDAH_BINARY=$(pwd)/bin/buildah \
bats "${bats_filter[@]}" tests/bud.bats)
fi
|