[skip e2e]Refine the script of getting image tag (#26919)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
This commit is contained in:
zhuwenxing 2023-09-07 19:05:15 +08:00 committed by GitHub
parent e2528030bb
commit 3fd315f2b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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"]: