From 5318c7eb9f17a8f089c8c0e552cd2eef32d79dd3 Mon Sep 17 00:00:00 2001 From: driazati <9407960+driazati@users.noreply.github.com> Date: Wed, 27 Jul 2022 15:08:42 -0700 Subject: [PATCH] [ci][docker] Use RFC image tags only (#11938) This ignores image names like `123-123-abc-validated` Co-authored-by: driazati --- tests/python/ci/test_ci.py | 20 ++++++++++++-------- tests/scripts/open_docker_update_pr.py | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/python/ci/test_ci.py b/tests/python/ci/test_ci.py index 0ed3f1701506..7864830269d7 100644 --- a/tests/python/ci/test_ci.py +++ b/tests/python/ci/test_ci.py @@ -834,7 +834,7 @@ def run(source_type, data, check): "results": [ { "last_updated": "2022-06-01T00:00:00.123456Z", - "name": "abc-abc-123", + "name": "123-123-abc", }, ] }, @@ -842,7 +842,7 @@ def run(source_type, data, check): "results": [ { "last_updated": "2022-06-01T00:00:00.123456Z", - "name": "abc-abc-123", + "name": "123-123-abc", }, ] }, @@ -852,9 +852,13 @@ def run(source_type, data, check): dict( tlcpackstaging_body={ "results": [ + { + "last_updated": "2022-06-01T01:00:00.123456Z", + "name": "234-234-abc-staging", + }, { "last_updated": "2022-06-01T00:00:00.123456Z", - "name": "abc-abc-234-staging", + "name": "456-456-abc", }, ] }, @@ -862,13 +866,13 @@ def run(source_type, data, check): "results": [ { "last_updated": "2022-06-01T00:00:00.123456Z", - "name": "abc-abc-123", + "name": "123-123-abc", }, ] }, expected="Using tlcpackstaging tag on tlcpack", expected_images=[ - "ci_arm = 'tlcpack/ci-arm:abc-abc-234-staging'", + "ci_arm = 'tlcpack/ci-arm:456-456-abc'", ], ), dict( @@ -876,7 +880,7 @@ def run(source_type, data, check): "results": [ { "last_updated": "2022-06-01T00:00:00.123456Z", - "name": "abc-abc-123", + "name": "123-123-abc", }, ] }, @@ -884,13 +888,13 @@ def run(source_type, data, check): "results": [ { "last_updated": "2022-06-01T00:01:00.123456Z", - "name": "abc-abc-234", + "name": "234-234-abc", }, ] }, expected="Found newer image, using: tlcpack", expected_images=[ - "ci_arm = 'tlcpack/ci-arm:abc-abc-234'", + "ci_arm = 'tlcpack/ci-arm:234-234-abc'", ], ), ) diff --git a/tests/scripts/open_docker_update_pr.py b/tests/scripts/open_docker_update_pr.py index f583f00d5cbb..516c8c1a7d8c 100755 --- a/tests/scripts/open_docker_update_pr.py +++ b/tests/scripts/open_docker_update_pr.py @@ -22,6 +22,7 @@ import datetime import os import json +import re from urllib import error from typing import List, Dict, Any, Optional, Callable from git_utils import git, parse_remote, GitHubRepo @@ -52,6 +53,10 @@ def parse_docker_date(d: str) -> datetime.datetime: return datetime.datetime.strptime(d, "%Y-%m-%dT%H:%M:%S.%fZ") +def check_tag(tag: Dict[str, Any]) -> bool: + return re.match(r"^[0-9]+-[0-9]+-[a-z0-9]+$", tag["name"]) is not None + + def latest_tag(user: str, repo: str) -> List[Dict[str, Any]]: """ Queries Docker Hub and finds the most recent tag for the specified image/repo pair @@ -63,6 +68,7 @@ def latest_tag(user: str, repo: str) -> List[Dict[str, Any]]: result["last_updated"] = parse_docker_date(result["last_updated"]) results = list(sorted(results, key=lambda d: d["last_updated"])) + results = [tag for tag in results if check_tag(tag)] return results[-1]