podman
254 строки · 8.9 Кб
1#!/bin/bash
2
3ME=$(basename $0)4
5###############################################################################
6# BEGIN user-customizable section
7
8# Buildah main repository; unlikely to change often
9BUILDAH_REPO=github.com/containers/buildah10
11# Tag name used to identify the base checkout
12BASE_TAG=buildah-bud-in-podman13
14# END user-customizable section
15###############################################################################
16
17usage="Usage: $ME [--help] [--no-checkout] [--no-test] [--filter=TESTNAME]18
19Flags, useful for manual debugging:
20
21--no-checkout Skip checkout step, go directly to running tests.
22Useful when rerunning tests.
23
24--no-test Do checkout only, but do not run tests. Useful when
25testing 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)
33do_checkout=y34do_test=y35declare -a bats_filter=()36for i; do37value=$(expr "$i" : '[^=]*=\(.*\)')38case "$i" in39--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;;45esac46done
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.
68BUD_TEST_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))69PATCHES=${BUD_TEST_DIR}/buildah-tests.diff70
71# Friendlier relative path to our buildah-tests dir
72BUD_TEST_DIR_REL=$(dirname $(git ls-files --full-name ${BASH_SOURCE[0]}))73# Path to podman binary; again, do it before we cd
74PODMAN_BINARY=$(pwd)/bin/podman75REMOTE=76# If remote, start server & change path
77if [[ "${PODBIN_NAME:-}" = "remote" ]]; then78REMOTE=179PODMAN_BINARY+="-remote"80fi
81
82function die() {83failhint=84echo "$ME: $*" >&285exit 186}
87
88# From here on out, any unexpected abort will try to offer helpful hints
89failhint=90trap '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' 091
92# Find the version of buildah we've vendored in, so we can run the right tests
93buildah_version=$(awk "\$1 == \"$BUILDAH_REPO\" { print \$2 }" <go.mod)94
95if [[ -z "$buildah_version" ]]; then96# This should not happen97die "Did not find '$BUILDAH_REPO' in go.mod"98fi
99
100# From here on out, any error is fatal
101set -e102
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)
108export SUDO=109if [[ -n $do_test ]] && ! [[ "$PRIV_NAME" == "rootless" ]]; then110SUDO=sudo111$SUDO --validate112fi
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.
117is_revendor=118if [[ -n $CIRRUS_CHANGE_IN_REPO ]]; then119if [[ -n $DEST_BRANCH ]]; then120head=${CIRRUS_CHANGE_IN_REPO}121# Base of this PR.122base=$(set -x;git merge-base ${DEST_BRANCH} $head)123changes=$(set -x;git diff --name-status $base $head)124if [[ -n $changes ]]; then125if [[ $changes =~ vendor/$BUILDAH_REPO ]]; then126is_revendor=y127fi128fi129fi130fi
131
132# Pull buildah, including tests
133buildah_dir=test-buildah-$buildah_version134if [[ -n $do_checkout ]]; then135if [[ -d $buildah_dir ]]; then136die "Directory already exists: $buildah_dir"137fi138
139# buildah_version should usually be vX.Y, but sometimes a PR under test140# will need a special unreleased version (go calls then "pseudoversions").141# In the usual case, we can do a shallow git clone:142shallow_checkout="--branch $buildah_version"143if [[ $buildah_version =~ .*-.*\.[0-9]{14}-.* ]]; then144# ...but with a pseudoversion, we must git-clone the entire repo,145# then do a git checkout within it146shallow_checkout=147fi148
149failhint="'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 error154# with a helpful error message for humans to ponder. However, when running155# under automation, nobody cares about this condition or message, because156# the environment is disposable.157if [[ "$CI" == "true" ]]; then158(159_gc='git config --global'160set -x161$_gc user.email "TMcTestFace@example.com"162$_gc user.name "Testy McTestface"163$_gc --add safe.directory $buildah_dir164)165fi166
167cd $buildah_dir168if [[ -z $shallow_checkout ]]; then169# extract the SHA (rightmost field) from, e.g., v1.2-YYYMMDD-<sha>170sha=${buildah_version##*-}171
172failhint="'git checkout $sha' failed - this should never happen!"173(set -x;git checkout -q $sha)174fi175
176# Give it a recognizable tag; this will be useful if we need to update177# the set of patches178(set -x;git tag $BASE_TAG)179
180# Build buildah and the copy helper181failhint="error building buildah. This should never happen."182(set -x;make bin/buildah)183failhint="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 script187# for a developer to push a new set of diffs to podman-land.188failhint=189sed -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-diffs193chmod 755 make-new-buildah-diffs194
195# Apply custom patches. We do this _after_ building, although it shouldn't196# matter because these patches should only apply to test scripts and not197# to any buildah sources.198failhint="199Error applying patch file. This can happen when you vendor in a new buildah.
200You 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 maintained211# in a custom script, not a .diff file, because diffs are WAY too hard for212# humans to read and update.213APPLY=apply-podman-deltas214failhint="215Error applying podman-specific deltas. This sometimes happens when you
216vendor 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/$APPLY220- edit/delete them as necessary
221"
222(set -x;$BUD_TEST_DIR/$APPLY)223else
224# Called with --no-checkout225test -d $buildah_dir || die "Called with --no-checkout, but $buildah_dir does not exist"226
227cd $buildah_dir228fi
229
230if [[ -n $do_test ]]; then231failhint="Error running buildah bud tests under podman."232if [[ -n $is_revendor ]]; then233failhint+="234
235It looks like you're vendoring in a new buildah. The likely failure
236here is that there's a new test in bud.bats that uses functionality
237not (yet) in podman build. You will likely need to 'skip' that test.
238"
239else240failhint+="241
242Is it possible that your PR breaks podman build in some way? Please
243review the test failure and double-check your changes.
244"
245fi246
247(set -x;$SUDO env TMPDIR=/var/tmp \248PODMAN_BINARY=$PODMAN_BINARY \249PODMAN_SERVER_LOG=$PODMAN_SERVER_LOG \250REMOTE=$REMOTE \251BUILDAH_BINARY=$(pwd)/bin/buildah \252COPY_BINARY=$(pwd)/bin/copy \253bats "${bats_filter[@]}" tests/bud.bats)254fi
255