diff --git a/tests/scripts/get_image_tag_by_short_name.py b/tests/scripts/get_image_tag_by_short_name.py index 53235ab341..f04e64a91a 100644 --- a/tests/scripts/get_image_tag_by_short_name.py +++ b/tests/scripts/get_image_tag_by_short_name.py @@ -3,16 +3,23 @@ import argparse def get_image_tag_by_short_name(repository, tag): - # Send API request to get all tags - url = f"https://hub.docker.com/v2/repositories/{repository}/tags" + # Send API request to get all tags start with prefix + # ${branch}-latest means the tag is a dev build + # master-latest -> master-$date-$commit + # 2.3.0-latest -> 2.3.0-$date-$commit + # latest means the tag is a release build + # latest -> v$version + splits = tag.split("-") + prefix = splits[0] if len(splits) > 1 else "v" + url = f"https://hub.docker.com/v2/repositories/{repository}/tags?name={prefix}&ordering=last_updated" response = requests.get(url) data = response.json() - # Get the DIGEST of the "master-latest" tag + # Get the DIGEST of the short tag digest = "" - for tag_info in data["results"]: - if tag_info["name"] == tag: - digest = tag_info["images"][0]["digest"] - break + url = f"https://hub.docker.com/v2/repositories/{repository}/tags/{tag}" + response = requests.get(url) + cur_tag_info = response.json() + digest = cur_tag_info["images"][0]["digest"] res = [] # Iterate through all tags and find the ones with the same DIGEST for tag_info in data["results"]: