Update the filter of diff-image.sh

This commit is contained in:
Shiming Zhang 2021-09-17 12:03:28 +08:00
parent 2e0c62e8db
commit 3812bf3a1f
2 changed files with 22 additions and 13 deletions

View File

@ -26,7 +26,7 @@ for line in $(cat ./domain.txt); do
DOMAIN_MAP["${key}"]="${val}" DOMAIN_MAP["${key}"]="${val}"
done done
declare -A EXCLUDED_MAP=() declare -A SKIP_MAP=()
for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.tag_patterns[] | . , "|" ) , "\n"' | sed "s/|$//g"); do for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.tag_patterns[] | . , "|" ) , "\n"' | sed "s/|$//g"); do
line="${line/ /}" line="${line/ /}"
@ -40,7 +40,7 @@ for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.t
continue continue
fi fi
EXCLUDED_MAP["${key}"]="${val}" SKIP_MAP["${key}"]="${val}"
done done
LOGFILE="./check-image.log" LOGFILE="./check-image.log"
@ -55,19 +55,19 @@ for line in ${images}; do
continue continue
fi fi
exclude="" skip=""
for key in "${!EXCLUDED_MAP[@]}"; do for key in "${!SKIP_MAP[@]}"; do
if [[ "${line}" =~ ${key} ]]; then if [[ "${line}" =~ ${key} ]]; then
exclude+="${EXCLUDED_MAP[$key]}|" skip+="${SKIP_MAP[$key]}|"
fi fi
done done
exclude="${exclude%|}" skip="${skip%|}"
domain="${line%%/*}" domain="${line%%/*}"
new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g") new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g")
count=$((count + 1)) count=$((count + 1))
echo "Diff ${count}/${images_count} image ${line} ${new_image}" echo "Diff ${count}/${images_count} image ${line} ${new_image}"
DEBUG="${DEBUG}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" PARALLET="${PARALLET}" EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || { DEBUG="${DEBUG}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" PARALLET="${PARALLET}" SKIP="${skip}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || {
echo "Error: diff image ${line} ${new_image}" echo "Error: diff image ${line} ${new_image}"
} }
done done

View File

@ -16,8 +16,11 @@ INCREMENTAL="${INCREMENTAL:-}"
# Compare only tags that are in both images # Compare only tags that are in both images
QUICKLY="${QUICKLY:-}" QUICKLY="${QUICKLY:-}"
# Exclude tags that do not need to be checked # Regexp that matches the tags
EXCLUDED="${EXCLUDED:-}" FOCUS="${FOCUS:-}"
# Regexp that matches the tags that needs to be skipped
SKIP="${SKIP:-}"
# Compare the number of tags in parallel # Compare the number of tags in parallel
PARALLET="${PARALLET:-0}" PARALLET="${PARALLET:-0}"
@ -30,7 +33,8 @@ if [[ "${DEBUG}" == "true" ]]; then
echo "IMAGE2: ${IMAGE2}" echo "IMAGE2: ${IMAGE2}"
echo "INCREMENTAL: ${INCREMENTAL}" echo "INCREMENTAL: ${INCREMENTAL}"
echo "QUICKLY: ${QUICKLY}" echo "QUICKLY: ${QUICKLY}"
echo "EXCLUDED: ${EXCLUDED}" echo "FOCUS: ${FOCUS}"
echo "SKIP: ${SKIP}"
echo "PARALLET: ${PARALLET}" echo "PARALLET: ${PARALLET}"
fi fi
@ -48,7 +52,8 @@ function check() {
echo " DEBUG=true # Output more information that is out of sync" echo " DEBUG=true # Output more information that is out of sync"
echo " INCREMENTAL=true # Allow image2 to have more tags than image1" echo " INCREMENTAL=true # Allow image2 to have more tags than image1"
echo " QUICKLY=true # Compare only tags that are in both images" echo " QUICKLY=true # Compare only tags that are in both images"
echo " EXCLUDED=<pattern> # Exclude tags that do not need to be checked" echo " FOCUS=<pattern> # Regexp that matches the tags"
echo " SKIP=<pattern> # Regexp that matches the tags that needs to be skipped"
echo " PARALLET=<size> # Compare the number of tags in parallel" echo " PARALLET=<size> # Compare the number of tags in parallel"
return 2 return 2
fi fi
@ -126,8 +131,12 @@ function list-tags() {
local image="${1:-}" local image="${1:-}"
local raw="$(skopeo list-tags --tls-verify=false "docker://${image}" | jq -r '.Tags[]' | sort)" local raw="$(skopeo list-tags --tls-verify=false "docker://${image}" | jq -r '.Tags[]' | sort)"
if [[ "${EXCLUDED}" != "" ]]; then if [[ "${FOCUS}" != "" ]]; then
raw="$(echo "${raw}" | grep -v -E "${EXCLUDED}" || :)" raw="$(echo "${raw}" | grep -E "${FOCUS}" || :)"
fi
if [[ "${SKIP}" != "" ]]; then
raw="$(echo "${raw}" | grep -v -E "${SKIP}" || :)"
fi fi
echo "${raw}" echo "${raw}"
} }