From 667dc90ed21bf4f00aad8195a5954630fc8fc31a Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mon, 27 Jan 2025 12:05:42 +0800 Subject: [PATCH] Link to migration bundles Any task bundles that have migrations are linked by the newer task bundles by a dedicated annotation. See the following example task bundles: tb0 --> tb1 --> tb2 --> tb3 --> tb4 --> tb5 | | M M where, tb2 and tb3 point to tb1, and tb4 and tb5 point to tb3. Linking task bundles helps to reduce the number of HTTP requests made to Quay.io that query which task bundles have migrations. Terms: - tb means task bundle. - M means migration. --- hack/build-and-push.sh | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index 89aa9ceb63..54752c09fe 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -228,6 +228,7 @@ build_push_task() { local -r task_bundle=$3 local -r task_file_sha=$4 local -r has_migration=$5 + local -r prev_bundle_digest=$6 local -r task_description=$(yq e '.spec.description' "$prepared_task_file" | head -n 1) @@ -253,6 +254,8 @@ build_push_task() { ANNOTATIONS+=("dev.konflux-ci.task.migration=true") fi + ANNOTATIONS+=("dev.konflux-ci.task/previous-migration-bundle=${prev_bundle_digest}") + local -a ANNOTATION_FLAGS=() for annotation in "${ANNOTATIONS[@]}"; do ANNOTATION_FLAGS+=("--annotate" "$(escape_tkn_bundle_arg "$annotation")") @@ -431,6 +434,34 @@ attach_migration_file() { return 0 } +# Find previous bundle that has a migration and output its digest. +find_previous_bundle_with_migration() { + local -r task_name=${1:?Missing task name} + local -r task_version=${2:?Missing task version} + local -r repo=${TEST_REPO_NAME:-task-${task_name}} + + local -r url_list_recent_tags="https://quay.io/api/v1/repository/${QUAY_NAMESPACE}/${repo}/tag/?onlyActiveTags=true&limit=30" + local -r expr_filter_tags=".tags[] | select(.name | test(\"^(${task_name}-)?${task_version}-[0-9a-f]+\$\")) | .manifest_digest" + + local prev_bundle_digest has_migration + + curl --fail -sL "$url_list_recent_tags" | jq -r "$expr_filter_tags" | \ + while read -r manifest_digest; do + curl --fail -sL -o /tmp/manifest.json \ + "https://quay.io/v2/${QUAY_NAMESPACE}/${repo}/manifests/${manifest_digest}" + prev_bundle_digest=$(jq -r '.annotations."dev.konflux-ci.task/previous-migration-bundle"' &2 else + echo "info: finding the previous task bundle that has a migration" 1>&2 + prev_bundle_digest=$(find_previous_bundle_with_migration "$task_name" "$task_version") + echo "info: push new bundle $task_bundle" 1>&2 - output=$(build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha" "$has_migration") + output=$( + build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha" \ + "$has_migration" "$prev_bundle_digest" + ) task_bundle_with_digest=$(grep -m 1 "^Pushed Tekton Bundle to" <<<"$output" 2>/dev/null) task_bundle_with_digest=${task_bundle_with_digest##* } @@ -501,7 +539,6 @@ build_push_tasks() { build_push_tasks - # Used for build-definitions pull request CI only if [ -n "$ENABLE_SOURCE_BUILD" ]; then for pipeline_yaml in "$GENERATED_PIPELINES_DIR"/*.yaml; do