podman

Форк
0
/
run-buildah-bud-tests 
254 строки · 8.9 Кб
1
#!/bin/bash
2

3
ME=$(basename $0)
4

5
###############################################################################
6
# BEGIN user-customizable section
7

8
# Buildah main repository; unlikely to change often
9
BUILDAH_REPO=github.com/containers/buildah
10

11
# Tag name used to identify the base checkout
12
BASE_TAG=buildah-bud-in-podman
13

14
# END   user-customizable section
15
###############################################################################
16

17
usage="Usage: $ME [--help] [--no-checkout] [--no-test] [--filter=TESTNAME]
18

19
Flags, useful for manual debugging:
20

21
  --no-checkout   Skip checkout step, go directly to running tests.
22
                  Useful when rerunning tests.
23

24
  --no-test       Do checkout only, but do not run tests. Useful when
25
                  testing the apply-podman-deltas script.
26

27
  --filter=NAME   Passed on to bats; runs only tests that match NAME
28

29
  --remote        Test with podman-remote. Will start its own server.
30
"
31

32
# Parse command-line options (used in development only, not in CI)
33
do_checkout=y
34
do_test=y
35
declare -a bats_filter=()
36
for i; do
37
    value=$(expr "$i" : '[^=]*=\(.*\)')
38
    case "$i" in
39
        --no-checkout)  do_checkout= ; shift;;
40
        --no-test)      do_test=     ; shift;;
41
        --filter=*)     bats_filter=("--filter" "$value"); shift;;
42
        --remote)       PODBIN_NAME=remote;;
43
       -h|--help)       echo "$usage"; exit 0;;
44
        *)              echo "$ME: Unrecognized option '$i'" >&2; exit 1;;
45
    esac
46
done
47

48
# Patches helpers.bash and potentially other files (bud.bats? Dockerfiles?)
49
#
50
# The patch file is horrible to generate:
51
#    1) cd to the checked-out buildah/tests directory
52
#    2) make your edits
53
#    3) git commit -asm 'blah blah blah'
54
#       3a) if checked-out directory already includes earlier patches,
55
#           you may need to 'git commit --amend' instead
56
#    4) git format-patch HEAD^
57
#    5) sed -e 's/ \+$//' 0001* >../PATCH-FILE-PATH
58
#    6) vim that file, remove trailing empty newlines
59
#    7) cd back out of buildah directory, and git-commit this new patch file
60
#
61
# FIXME: this makes me nervous. The diff will probably need tweaking
62
#        over time. I don't think we need to version it, because we
63
#        *have* to be in lockstep with a specific buildah version,
64
#        so problems should only arise when we re-vendor.
65
#        But I'm still nervous and can't put my finger on the reason.
66
#
67
# Complicated invocation needed because we 'cd' down below.
68
BUD_TEST_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
69
PATCHES=${BUD_TEST_DIR}/buildah-tests.diff
70

71
# Friendlier relative path to our buildah-tests dir
72
BUD_TEST_DIR_REL=$(dirname $(git ls-files --full-name ${BASH_SOURCE[0]}))
73
# Path to podman binary; again, do it before we cd
74
PODMAN_BINARY=$(pwd)/bin/podman
75
REMOTE=
76
# If remote, start server & change path
77
if [[ "${PODBIN_NAME:-}" = "remote" ]]; then
78
    REMOTE=1
79
    PODMAN_BINARY+="-remote"
80
fi
81

82
function die() {
83
    failhint=
84
    echo "$ME: $*" >&2
85
    exit 1
86
}
87

88
# From here on out, any unexpected abort will try to offer helpful hints
89
failhint=
90
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
91

92
# Find the version of buildah we've vendored in, so we can run the right tests
93
buildah_version=$(awk "\$1 == \"$BUILDAH_REPO\" { print \$2 }" <go.mod)
94

95
if [[ -z "$buildah_version" ]]; then
96
    # This should not happen
97
    die "Did not find '$BUILDAH_REPO' in go.mod"
98
fi
99

100
# From here on out, any error is fatal
101
set -e
102

103
# Run sudo early, to refresh the credentials cache. This is a NOP under CI,
104
# but might be appreciated by developers who run this script, step away
105
# during the git-checkout-buildah step, then come back twenty minutes later
106
# to an expired sudo prompt and no tests have run. (No need to do this
107
# for checkout; only when running tests)
108
export SUDO=
109
if [[ -n $do_test ]] && ! [[ "$PRIV_NAME" == "rootless" ]]; then
110
    SUDO=sudo
111
    $SUDO --validate
112
fi
113

114
# Before pulling buildah (while still cd'ed to podman repo), try to determine
115
# if this is a PR, and if so if it's a revendoring of buildah. We use this to
116
# try to offer a helpful hint on failure.
117
is_revendor=
118
if [[ -n $CIRRUS_CHANGE_IN_REPO ]]; then
119
    if [[ -n $DEST_BRANCH ]]; then
120
        head=${CIRRUS_CHANGE_IN_REPO}
121
        # Base of this PR.
122
        base=$(set -x;git merge-base ${DEST_BRANCH} $head)
123
        changes=$(set -x;git diff --name-status $base $head)
124
        if [[ -n $changes ]]; then
125
            if [[ $changes =~ vendor/$BUILDAH_REPO ]]; then
126
                is_revendor=y
127
            fi
128
        fi
129
    fi
130
fi
131

132
# Pull buildah, including tests
133
buildah_dir=test-buildah-$buildah_version
134
if [[ -n $do_checkout ]]; then
135
    if [[ -d $buildah_dir ]]; then
136
        die "Directory already exists: $buildah_dir"
137
    fi
138

139
    # buildah_version should usually be vX.Y, but sometimes a PR under test
140
    # will need a special unreleased version (go calls then "pseudoversions").
141
    # In the usual case, we can do a shallow git clone:
142
    shallow_checkout="--branch $buildah_version"
143
    if [[ $buildah_version =~ .*-.*\.[0-9]{14}-.* ]]; then
144
        # ...but with a pseudoversion, we must git-clone the entire repo,
145
        # then do a git checkout within it
146
        shallow_checkout=
147
    fi
148

149
    failhint="'git clone' failed - this should never happen!"
150
    (set -x;git clone -q $shallow_checkout https://$BUILDAH_REPO $buildah_dir)
151

152
    # Recent versions of git (like `2.39`) disallow some operations (like `am`)
153
    # without an identity being set.  In this case, git will throw an error
154
    # with a helpful error message for humans to ponder.  However, when running
155
    # under automation, nobody cares about this condition or message, because
156
    # the environment is disposable.
157
    if [[ "$CI" == "true" ]]; then
158
        (
159
        _gc='git config --global'
160
        set -x
161
        $_gc user.email "TMcTestFace@example.com"
162
        $_gc user.name "Testy McTestface"
163
        $_gc --add safe.directory $buildah_dir
164
        )
165
    fi
166

167
    cd $buildah_dir
168
    if [[ -z $shallow_checkout ]]; then
169
        # extract the SHA (rightmost field) from, e.g., v1.2-YYYMMDD-<sha>
170
        sha=${buildah_version##*-}
171

172
        failhint="'git checkout $sha' failed - this should never happen!"
173
        (set -x;git checkout -q $sha)
174
    fi
175

176
    # Give it a recognizable tag; this will be useful if we need to update
177
    # the set of patches
178
    (set -x;git tag $BASE_TAG)
179

180
    # Build buildah and the copy helper
181
    failhint="error building buildah. This should never happen."
182
    (set -x;make bin/buildah)
183
    failhint="error building buildah's copy helper. This should never happen."
184
    (set -x;make bin/copy)
185

186
    # The upcoming patch may fail. Before we try it, create a helper script
187
    # for a developer to push a new set of diffs to podman-land.
188
    failhint=
189
    sed -e "s,\[BASETAG\],${BASE_TAG},g" \
190
        -e "s,\[BUILDAHREPO\],${BUILDAH_REPO},g" \
191
        < ${BUD_TEST_DIR}/make-new-buildah-diffs \
192
        > make-new-buildah-diffs
193
    chmod 755 make-new-buildah-diffs
194

195
    # Apply custom patches. We do this _after_ building, although it shouldn't
196
    # matter because these patches should only apply to test scripts and not
197
    # to any buildah sources.
198
    failhint="
199
Error applying patch file. This can happen when you vendor in a new buildah.
200
You will want to:
201

202
  - look for 'test/*.rej'
203
  - resolve conflicts manually
204
  - git add test/helpers.bash
205
  - git am --continue
206
  - ./make-new-buildah-diffs
207
"
208
    (set -x;git am --reject <$PATCHES)
209

210
   # Now apply our custom skips and error-message changes. This is maintained
211
    # in a custom script, not a .diff file, because diffs are WAY too hard for
212
    # humans to read and update.
213
    APPLY=apply-podman-deltas
214
    failhint="
215
Error applying podman-specific deltas. This sometimes happens when you
216
vendor in a new buildah. You will want to:
217

218
  - inspect the errors shown above
219
  - find the corresponding lines in $BUD_TEST_DIR_REL/$APPLY
220
  - edit/delete them as necessary
221
"
222
    (set -x;$BUD_TEST_DIR/$APPLY)
223
else
224
    # Called with --no-checkout
225
    test -d $buildah_dir || die "Called with --no-checkout, but $buildah_dir does not exist"
226

227
    cd $buildah_dir
228
fi
229

230
if [[ -n $do_test ]]; then
231
    failhint="Error running buildah bud tests under podman."
232
    if [[ -n $is_revendor ]]; then
233
        failhint+="
234

235
It looks like you're vendoring in a new buildah. The likely failure
236
here is that there's a new test in bud.bats that uses functionality
237
not (yet) in podman build. You will likely need to 'skip' that test.
238
"
239
    else
240
        failhint+="
241

242
Is it possible that your PR breaks podman build in some way? Please
243
review the test failure and double-check your changes.
244
"
245
    fi
246

247
    (set -x;$SUDO env TMPDIR=/var/tmp \
248
                 PODMAN_BINARY=$PODMAN_BINARY \
249
                 PODMAN_SERVER_LOG=$PODMAN_SERVER_LOG \
250
                 REMOTE=$REMOTE \
251
                 BUILDAH_BINARY=$(pwd)/bin/buildah \
252
                 COPY_BINARY=$(pwd)/bin/copy \
253
                 bats "${bats_filter[@]}" tests/bud.bats)
254
fi
255

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.