From a508a79cbf1590b77d5a26c5a653295a30830fd2 Mon Sep 17 00:00:00 2001 From: Adam Cmiel Date: Fri, 22 Mar 2024 12:13:05 +0100 Subject: [PATCH] hack/build-and-push.sh: fix digest existence check The current check queries Quay's custom API and expects that the tags in the response always exist. This is not the case for deleted/expired tags. See for example: curl 'https://quay.io/api/v1/repository/redhat-appstudio-tekton-catalog/pull-request-builds/tag/?specificTag=buildah-0.1-2f4e137b5ed645c6d5279c52eaf1d20b071729f1' { "tags": [ { "name": "buildah-0.1-2f4e137b5ed645c6d5279c52eaf1d20b071729f1", "reversion": false, "start_ts": 1709804197, "end_ts": 1711038680, "manifest_digest": "sha256:ebb2fe8fe89005229962167b9a31015a023a49a7169c52edfc34d18fcb1270dd", "is_manifest_list": false, "size": 5920, "last_modified": "Thu, 07 Mar 2024 09:36:37 -0000", "expiration": "Thu, 21 Mar 2024 16:31:20 -0000" } ], "page": 1, "has_additional": false } This tag has expired (and Quay reports it as such), but our script does not notice that. Fix the problem by using `skopeo inspect` instead of querying Quay's custom API. Signed-off-by: Adam Cmiel --- hack/build-and-push.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index a1c15f1bc5..700eff4708 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -96,8 +96,10 @@ do repository=${TEST_REPO_NAME:-task-${task_name}} tag=${TEST_REPO_NAME:+${task_name}-}${task_version} task_bundle=quay.io/$MY_QUAY_USER/${repository}:${tag} - digest=$(curl -s https://quay.io/api/v1/repository/$MY_QUAY_USER/$repository/tag/?specificTag=${tag}-${task_file_sha} | yq '.tags[0].manifest_digest') - if [ "$digest" == "null" ]; then + + if digest=$(skopeo inspect --no-tags --format='{{.Digest}}' docker://"${task_bundle}-${task_file_sha}" 2>/dev/null); then + task_bundle_with_digest=${task_bundle}@${digest} + else output=$(tkn bundle push -f "$prepared_task_file" "$task_bundle" | save_ref "$task_bundle" "$OUTPUT_TASK_BUNDLE_LIST") echo "$output" task_bundle_with_digest="${output##*$'\n'}" @@ -105,8 +107,6 @@ do # copy task to new tag pointing to commit where the file was changed lastly, so that image persists # even when original tag is updated skopeo copy "docker://${task_bundle}" "docker://${task_bundle}-${task_file_sha}" - else - task_bundle_with_digest=${task_bundle}@${digest} fi # version placeholder is removed naturally by the substitution. real_task_name=$(yq e '.metadata.name' "$prepared_task_file")