Skip to content

Commit

Permalink
hack/build-and-push.sh: fix digest existence check
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chmeliik committed Mar 28, 2024
1 parent 70c12c6 commit a508a79
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hack/build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ 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'}"

# 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")
Expand Down

0 comments on commit a508a79

Please sign in to comment.