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
|
#!/bin/bash
set -e -o pipefail
### Functions
fatal_msg () {
printf 'πππ error: %s πππ\n' "$1" 1>&2
}
usage () {
cat <<'EOF' 1>&2
Test that ch-image can upgrade storage directories generated by old versions,
i.e., unpack each old storage directory from a tarball, then try to upgrade it
and run the test suite.
Usage:
$ old-storage.sh SCOPE WORKDIR (DIR|TAR1) [TAR2 ...]
WORKDIR is where ch-image storage are unpacked. It must be empty and have
enough space for one storage directory.
TARn are old storage directories archived as tarballs. These must have certain
properties:
1. Named storage-$VERSION.$ARCH.tar.gz, e.g. βstorage-0.27.x86_64.tar.gzβ.
(Note: $ARCH is not currently validated but may be in the future.)
2. Is a tarbomb, e.g.:
$ tar tf storage-0.26.x86_64.tar.gz | head -3
./
./dlcache/
./dlcache/alpine:3.9.fat.json
3. The result of:
$ rm -Rf $(ch-image storage-path) && ch-test -b ch-image build
or equivalent, though mostly rather than fully successful tests are fine.
Note: Best practice is to generate the tarball at the time of release,
because old test suites often donβt pass due to changing source images.
If a directory DIR is given instead, use all tarballs in that directory that
have last-modified dates less than one year in the past. (See #1507.)
EOF
}
INFO () {
printf 'π£ %s\n' "$1"
}
### Parse arguments & setup
if [[ $1 = --help || $1 = -? ]]; then
usage
exit 0
fi
if [[ $# -lt 3 ]]; then
usage
exit 1
fi
scope=$1; shift
workdir=$1; shift
trap 'fatal_msg "command failed on line $LINENO"' ERR
PATH=$(cd "$(dirname "$0")" && pwd)/../bin:$PATH
export PATH
if [[ -d $1 ]]; then
oldtars=$(find "$1" -mindepth 1 -mtime -365 -print | sort)
else
oldtars=$(printf '%s ' "$@") # https://www.shellcheck.net/wiki/SC2124
fi
summary=''
pass_ct=0
fail_ct=0
### Main loop
INFO "workdir: $workdir"
for oldtar in $oldtars; do
base=$(basename "$oldtar")
base=${base%.*} # rm .gz
base=${base%.*} # rm .tar
base=${base%.*} # rm architecture
storage=${workdir}/${base}
INFO "old tar: $oldtar ($(stat -c %y "$oldtar"))"
INFO "unpacking: $storage"
[[ -d $workdir ]]
[[ ! -d $storage ]]
mkdir "$storage"
tar xf "$oldtar" -C "$storage"
[[ -d $storage ]]
export CH_IMAGE_STORAGE=$storage
INFO "unpacked: $(du -sh "$storage" | cut -f1) bytes in $(du --inodes -sh "$storage" | cut -f1) inodes"
case ${storage#*-} in
0.29|0.30|0.31)
INFO "working around bug fixed by PR #1662"
(cd "$storage"/bucache && git branch -D alpine+latest)
;;
esac
INFO "upgrading"
ch-image list
# These are images that contain references to things on the internet that
# go out of date, so builds based on them fail. Re-pull them to get a
# current base image.
ch-image pull archlinux:latest
INFO "testing"
if (ch-test -b ch-image --pedantic=no -s "$scope" all); then
pass_ct=$((pass_ct + 1))
summary+="π ${oldtar}: PASS"$'\n'
else
fail_ct=$((fail_ct + 1))
summary+="π€¦ ${oldtar}: FAIL"$'\n'
fi
INFO "deleting: $storage"
rm -Rf --one-file-system "$storage"
[[ ! -d $storage ]]
done
cat <<EOF
π»π»π» Summary π»π»π»
${summary}
pass: ${pass_ct}
fail: ${fail_ct}
EOF
if [[ $fail_ct -gt 0 ]]; then
echo
fatal_msg 'one or more old storage test suites failed'
exit 1
fi
|