Add quickly compare feature

This commit is contained in:
Shiming Zhang 2021-09-14 11:09:09 +08:00
parent 8b5190e06c
commit 31f741922b
2 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ set -o pipefail
DEBUG="${DEBUG:-}"
INCREMENTAL="${INCREMENTAL:-}"
QUICKLY="${QUICKLY:-}"
declare -A DOMAIN_MAP=()
@ -61,7 +62,7 @@ for line in $(cat ./mirror.txt); do
domain="${line%%/*}"
new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g")
echo "Diff image ${line} ${new_image}"
DEBUG="${DEBUG}" INCREMENTAL="${INCREMENTAL}" EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || {
DEBUG="${DEBUG}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || {
echo "Error: diff image ${line} ${new_image}"
}
done

View File

@ -13,6 +13,9 @@ DEBUG="${DEBUG:-}"
# Allow image2 to have more tags than image1
INCREMENTAL="${INCREMENTAL:-}"
# Compare only tags that are in both images
QUICKLY="${QUICKLY:-}"
# Exclude tags that do not need to be checked
EXCLUDED="${EXCLUDED:-}"
@ -109,6 +112,17 @@ function diff-image-with-tag() {
local image1="${1:-}"
local image2="${2:-}"
if [[ "${QUICKLY}" == "true" ]]; then
local tag1="${image1##*:}"
local tag2="${image2##*:}"
if [[ "${tag1}" != "${tag2}" ]]; then
echo "${SELF}: UNSYNC: ${image1} and ${image2} are not in synchronized" >&2
return 1
fi
echo "${SELF}: SYNC: ${image1} and ${image2} are in synchronized" >&2
return 0
fi
local inspect1="$(inspect ${image1})"
local inspect2="$(inspect ${image2})"
local diff_raw=$(diff --unified <(echo "${inspect1}") <(echo "${inspect2}"))