From 37603418cebba7c242695896961f414b0a66702a Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Thu, 16 Sep 2021 15:02:41 +0800 Subject: [PATCH] Support parallel differential tags --- .github/workflows/deep-sync-check.yml | 1 + scripts/check-image.sh | 5 +++-- scripts/diff-image.sh | 27 ++++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deep-sync-check.yml b/.github/workflows/deep-sync-check.yml index 4af3af9..03be006 100644 --- a/.github/workflows/deep-sync-check.yml +++ b/.github/workflows/deep-sync-check.yml @@ -18,6 +18,7 @@ jobs: INCREMENTAL: "true" DEBUG: "true" QUICKLY: "" + PARALLET: "10" run: | ./scripts/check-image.sh - name: Update badge diff --git a/scripts/check-image.sh b/scripts/check-image.sh index 30bd35f..0a6fc5b 100755 --- a/scripts/check-image.sh +++ b/scripts/check-image.sh @@ -7,6 +7,7 @@ set -o pipefail DEBUG="${DEBUG:-}" INCREMENTAL="${INCREMENTAL:-}" QUICKLY="${QUICKLY:-}" +PARALLET="${PARALLET:-0}" declare -A DOMAIN_MAP=() @@ -45,7 +46,7 @@ done LOGFILE="./check-image.log" echo >"${LOGFILE}" -for line in $(cat ./mirror.txt); do +for line in $(cat ./mirror.txt | shuf); do line="${line/ /}" if [[ "$line" == "" ]]; then continue @@ -62,7 +63,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}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" EXCLUDED="${exclude}" ./scripts/diff-image.sh "${line}" "${new_image}" 2>&1 | tee -a "${LOGFILE}" || { + DEBUG="${DEBUG}" QUICKLY="${QUICKLY}" INCREMENTAL="${INCREMENTAL}" PARALLET="${PARALLET}" EXCLUDED="${exclude}" ./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 76cab78..898a421 100755 --- a/scripts/diff-image.sh +++ b/scripts/diff-image.sh @@ -19,6 +19,9 @@ QUICKLY="${QUICKLY:-}" # Exclude tags that do not need to be checked EXCLUDED="${EXCLUDED:-}" +# Compare the number of tags in parallel +PARALLET="${PARALLET:-0}" + SELF="$(basename "${BASH_SOURCE[0]}")" function check() { @@ -36,6 +39,7 @@ function check() { 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 " PARALLET= # Compare the number of tags in parallel" return 2 fi @@ -204,6 +208,15 @@ function diff-image() { return 0 } +function wait_jobs() { + local job_num=${1:-3} + local perc=$(jobs -p | wc -l) + while [ "${perc}" -gt "${job_num}" ]; do + sleep 1 + perc=$(jobs -p | wc -l) + done +} + function main() { local image1="${1:-}" local image2="${2:-}" @@ -216,9 +229,17 @@ function main() { local list=$(diff-image "${image1}" "${image2}") local unsync=() - for tag in ${list}; do - diff-image-with-tag "${image1}:${tag}" "${image2}:${tag}" >/dev/null || unsync+=("${tag}") - done + if [[ "${QUICKLY}" != "true" ]] || [[ "${PARALLET}" -eq 0 ]]; then + for tag in ${list}; do + diff-image-with-tag "${image1}:${tag}" "${image2}:${tag}" >/dev/null || unsync+=("${tag}") + done + else + for tag in ${list}; do + wait_jobs "${PARALLET}" + diff-image-with-tag "${image1}:${tag}" "${image2}:${tag}" >/dev/null || unsync+=("${tag}") & + done + wait + fi if [[ "${#unsync[@]}" -gt 0 ]]; then echo "${SELF}: INFO: ${image1} and ${image2} are not in synchronized, there are unsynchronized tags ${#unsync[@]}: ${unsync[*]}" >&2