From 6a2b16fd6c2a2b667c033b81d34dbe3301c11e19 Mon Sep 17 00:00:00 2001 From: zhuwenxing Date: Thu, 12 Oct 2023 05:03:36 -0500 Subject: [PATCH] [skip e2e]Fix get image tag for 2.2.0 branch (#27674) Signed-off-by: zhuwenxing --- tests/scripts/get_image_tag_by_short_name.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/scripts/get_image_tag_by_short_name.py b/tests/scripts/get_image_tag_by_short_name.py index f5ddda3eef..c3da4e52ef 100644 --- a/tests/scripts/get_image_tag_by_short_name.py +++ b/tests/scripts/get_image_tag_by_short_name.py @@ -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]