From 3812bf3a1f43f2f884369c998f16271652f5452f Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Fri, 17 Sep 2021 12:03:28 +0800 Subject: [PATCH] Update the filter of diff-image.sh --- scripts/check-image.sh | 14 +++++++------- scripts/diff-image.sh | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/check-image.sh b/scripts/check-image.sh index b7d4a79..fd7c998 100755 --- a/scripts/check-image.sh +++ b/scripts/check-image.sh @@ -26,7 +26,7 @@ for line in $(cat ./domain.txt); do DOMAIN_MAP["${key}"]="${val}" 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 line="${line/ /}" @@ -40,7 +40,7 @@ for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.t continue fi - EXCLUDED_MAP["${key}"]="${val}" + SKIP_MAP["${key}"]="${val}" done LOGFILE="./check-image.log" @@ -55,19 +55,19 @@ for line in ${images}; do continue fi - exclude="" - for key in "${!EXCLUDED_MAP[@]}"; do + skip="" + for key in "${!SKIP_MAP[@]}"; do if [[ "${line}" =~ ${key} ]]; then - exclude+="${EXCLUDED_MAP[$key]}|" + skip+="${SKIP_MAP[$key]}|" fi done - exclude="${exclude%|}" + skip="${skip%|}" domain="${line%%/*}" new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g") count=$((count + 1)) 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}" } done diff --git a/scripts/diff-image.sh b/scripts/diff-image.sh index 705ff00..5dd97d3 100755 --- a/scripts/diff-image.sh +++ b/scripts/diff-image.sh @@ -16,8 +16,11 @@ INCREMENTAL="${INCREMENTAL:-}" # Compare only tags that are in both images QUICKLY="${QUICKLY:-}" -# Exclude tags that do not need to be checked -EXCLUDED="${EXCLUDED:-}" +# Regexp that matches the tags +FOCUS="${FOCUS:-}" + +# Regexp that matches the tags that needs to be skipped +SKIP="${SKIP:-}" # Compare the number of tags in parallel PARALLET="${PARALLET:-0}" @@ -30,7 +33,8 @@ if [[ "${DEBUG}" == "true" ]]; then echo "IMAGE2: ${IMAGE2}" echo "INCREMENTAL: ${INCREMENTAL}" echo "QUICKLY: ${QUICKLY}" - echo "EXCLUDED: ${EXCLUDED}" + echo "FOCUS: ${FOCUS}" + echo "SKIP: ${SKIP}" echo "PARALLET: ${PARALLET}" fi @@ -48,7 +52,8 @@ function check() { echo " DEBUG=true # Output more information that is out of sync" echo " INCREMENTAL=true # Allow image2 to have more tags than image1" echo " QUICKLY=true # Compare only tags that are in both images" - echo " EXCLUDED= # Exclude tags that do not need to be checked" + echo " FOCUS= # Regexp that matches the tags" + echo " SKIP= # Regexp that matches the tags that needs to be skipped" echo " PARALLET= # Compare the number of tags in parallel" return 2 fi @@ -126,8 +131,12 @@ function list-tags() { local image="${1:-}" local raw="$(skopeo list-tags --tls-verify=false "docker://${image}" | jq -r '.Tags[]' | sort)" - if [[ "${EXCLUDED}" != "" ]]; then - raw="$(echo "${raw}" | grep -v -E "${EXCLUDED}" || :)" + if [[ "${FOCUS}" != "" ]]; then + raw="$(echo "${raw}" | grep -E "${FOCUS}" || :)" + fi + + if [[ "${SKIP}" != "" ]]; then + raw="$(echo "${raw}" | grep -v -E "${SKIP}" || :)" fi echo "${raw}" }