From 6842299d88885d2f69c047e37a2eba8958613ff9 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Mon, 13 Sep 2021 17:26:07 +0800 Subject: [PATCH] Support excluded tag --- scripts/check-image.sh | 27 ++++++++++++++++++++++++++- scripts/diff-image.sh | 10 +++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/scripts/check-image.sh b/scripts/check-image.sh index 31fde5d..7f2124d 100755 --- a/scripts/check-image.sh +++ b/scripts/check-image.sh @@ -21,16 +21,41 @@ for line in $(cat ./domain.txt); do DOMAIN_MAP["${key}"]="${val}" done +declare -A EXCLUDED_MAP=() + +for line in $(cat not_sync.yaml | yq -j '.not_sync[] | .image_pattern , "=", (.tag_patterns[] | . , "|" ) , "\n"' | sed "s/|$//g"); do + line="${line/ /}" + if [[ "$line" == "" ]]; then + continue + fi + key="${line%%=*}" + val="${line##*=}" + if [[ "${key}" == "" || "${val}" == "" ]]; then + echo "Error: invalid line: ${line}" + continue + fi + + EXCLUDED_MAP["${key}"]="${val}" +done + for line in $(cat ./mirror.txt); do line="${line/ /}" if [[ "$line" == "" ]]; then continue fi + exclude="" + for key in "${!EXCLUDED_MAP[@]}"; do + if [[ "${line}" =~ ${key} ]]; then + exclude+="${EXCLUDED_MAP[$key]}|" + fi + done + exclude="${exclude%|}" + domain="${line%%/*}" new_image=$(echo "${line}" | sed "s/^${domain}/${DOMAIN_MAP["${domain}"]}/g") echo "Diff image ${line} ${new_image}" - DEBUG=true INCREMENTAL=true ./scripts/diff-image.sh "${line}" "${new_image}" || { + DEBUG=true INCREMENTAL=true EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" || { echo "Error: diff image ${line} ${new_image}" } done diff --git a/scripts/diff-image.sh b/scripts/diff-image.sh index 9553939..da4a4fb 100755 --- a/scripts/diff-image.sh +++ b/scripts/diff-image.sh @@ -13,6 +13,9 @@ DEBUG="${DEBUG:-}" # Allow image2 to have more tags than image1 INCREMENTAL="${INCREMENTAL:-}" +# Exclude tags that do not need to be checked +EXCLUDED="${EXCLUDED:-}" + SELF="$(basename "${BASH_SOURCE[0]}")" function check() { @@ -94,7 +97,12 @@ function inspect() { function list-tags() { local image="${1:-}" - 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 + raw="$(echo "${raw}" | grep -v -E "${EXCLUDED}")" + fi + echo "${raw}" } function diff-image-with-tag() {