[skip e2e]Fix get image tag for 2.2.0 branch (#27674)

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
This commit is contained in:
zhuwenxing 2023-10-12 05:03:36 -05:00 committed by GitHub
parent 5b405ca28a
commit 6a2b16fd6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,12 +18,17 @@ def get_image_tag_by_short_name(repository, tag, arch):
data = response.json()
# Get the latest tag with the same arch and prefix
sorted_imgaes = sorted(data["results"], key=lambda x: x["last_updated"], reverse=True)
sorted_images = sorted(data["results"], key=lambda x: x["last_updated"], reverse=True)
candidate_tag = None
for tag_info in sorted_imgaes:
if tag_info["name"].endswith(arch):
for tag_info in sorted_images:
# print(tag_info)
if arch in [x["architecture"] for x in tag_info["images"]]:
candidate_tag = tag_info["name"]
break
if candidate_tag == tag:
continue
else:
# print(f"candidate_tag: {candidate_tag}")
break
# Get the DIGEST of the short tag
url = f"https://hub.docker.com/v2/repositories/{repository}/tags/{tag}"
response = requests.get(url)
@ -35,7 +40,7 @@ def get_image_tag_by_short_name(repository, tag, arch):
if "digest" in tag_info["images"][0] and tag_info["images"][0]["digest"] == digest:
# Extract the image name
image_name = tag_info["name"].split(":")[0]
if image_name != tag and arch in image_name:
if image_name != tag and arch in [x["architecture"] for x in tag_info["images"]]:
res.append(image_name)
# In case of no match, try to find the latest tag with the same arch
# there is a case: push master-xxx-arm64 and master-latest, but master-latest-amd64 is not pushed,
@ -44,7 +49,10 @@ def get_image_tag_by_short_name(repository, tag, arch):
image_name = tag_info["name"].split(":")[0]
if image_name != tag and arch in image_name:
res.append(image_name)
# print(res)
if len(res) == 0 or candidate_tag > res[0]:
if candidate_tag is None:
return tag
return candidate_tag
else:
return res[0]