Merge pull request #35854 from ClickHouse/docker-master-head

Fix automatic bucket prefix for master
This commit is contained in:
Mikhail f. Shiryaev 2022-04-01 17:54:59 +02:00 committed by GitHub
commit 47e1ee0971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 31 deletions

View File

@ -10,6 +10,7 @@ from typing import List, Tuple
from github import Github
from build_check import get_release_or_pr
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status
from docker_images_check import DockerImage
@ -20,10 +21,10 @@ from s3_helper import S3Helper
from stopwatch import Stopwatch
from upload_result_helper import upload_results
from version_helper import (
ClickHouseVersion,
get_tagged_versions,
get_version_from_repo,
get_version_from_string,
validate_version,
)
TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check")
@ -110,42 +111,40 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()
def version_arg(version: str) -> str:
def version_arg(version: str) -> ClickHouseVersion:
try:
validate_version(version)
return version
return get_version_from_string(version)
except ValueError as e:
raise argparse.ArgumentTypeError(e)
def auto_release_type(version: str, release_type: str) -> str:
def auto_release_type(version: ClickHouseVersion, release_type: str) -> str:
if release_type != "auto":
return release_type
current_version = get_version_from_string(version)
git_versions = get_tagged_versions()
reference_version = git_versions[0]
for i in reversed(range(len(git_versions))):
if git_versions[i] < current_version:
if git_versions[i] < version:
if i == len(git_versions) - 1:
return "latest"
reference_version = git_versions[i + 1]
break
if current_version.major < reference_version.major:
if version.major < reference_version.major:
return "major"
if current_version.minor < reference_version.minor:
if version.minor < reference_version.minor:
return "minor"
if current_version.patch < reference_version.patch:
if version.patch < reference_version.patch:
return "patch"
raise ValueError(
"Release type 'tweak' is not supported for "
f"{current_version.string} < {reference_version.string}"
f"{version.string} < {reference_version.string}"
)
def gen_tags(version: str, release_type: str) -> List[str]:
def gen_tags(version: ClickHouseVersion, release_type: str) -> List[str]:
"""
22.2.2.2 + latest:
- latest
@ -168,8 +167,7 @@ def gen_tags(version: str, release_type: str) -> List[str]:
22.2.2.2 + head:
- head
"""
validate_version(version)
parts = version.split(".")
parts = version.string.split(".")
tags = []
if release_type == "latest":
tags.append(release_type)
@ -201,7 +199,12 @@ def buildx_args(bucket_prefix: str, arch: str) -> List[str]:
def build_and_push_image(
image: DockerImage, push: bool, bucket_prefix: str, os: str, tag: str, version: str
image: DockerImage,
push: bool,
bucket_prefix: str,
os: str,
tag: str,
version: ClickHouseVersion,
) -> List[Tuple[str, str]]:
result = []
if os != "ubuntu":
@ -228,7 +231,7 @@ def build_and_push_image(
cmd_args.extend(
[
f"--metadata-file={metadata_path}",
f"--build-arg=VERSION='{version}'",
f"--build-arg=VERSION='{version.string}'",
"--progress=plain",
f"--file={dockerfile}",
image.full_path,
@ -293,9 +296,10 @@ def main():
pr_info = None
if CI:
pr_info = PRInfo()
release_or_pr = get_release_or_pr(pr_info, {"package_type": ""}, args.version)
args.bucket_prefix = (
f"https://s3.amazonaws.com/{S3_BUILDS_BUCKET}/"
f"{pr_info.number}/{pr_info.sha}"
f"{release_or_pr}/{pr_info.sha}"
)
if args.push:

View File

@ -227,19 +227,20 @@ class TestDockerImageCheck(unittest.TestCase):
class TestDockerServer(unittest.TestCase):
def test_gen_tags(self):
version = get_version_from_string("22.2.2.2")
cases = (
(("22.2.2.2", "latest"), ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "major"), ["22", "22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "minor"), ["22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "patch"), ["22.2.2", "22.2.2.2"]),
(("22.2.2.2", "head"), ["head"]),
("latest", ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]),
("major", ["22", "22.2", "22.2.2", "22.2.2.2"]),
("minor", ["22.2", "22.2.2", "22.2.2.2"]),
("patch", ["22.2.2", "22.2.2.2"]),
("head", ["head"]),
)
for case in cases:
version, release_type = case[0]
release_type = case[0]
self.assertEqual(case[1], ds.gen_tags(version, release_type))
with self.assertRaises(ValueError):
ds.gen_tags("22.2.2.2", "auto")
ds.gen_tags(version, "auto")
@patch("docker_server.get_tagged_versions")
def test_auto_release_type(self, mock_tagged_versions: MagicMock):
@ -251,13 +252,13 @@ class TestDockerServer(unittest.TestCase):
get_version_from_string("2.2.2.1"),
]
cases = (
("1.0.1.1", "minor"),
("1.1.2.1", "minor"),
("1.3.1.1", "major"),
("2.1.2.1", "minor"),
("2.2.1.3", "patch"),
("2.2.3.1", "latest"),
("2.3.1.1", "latest"),
(get_version_from_string("1.0.1.1"), "minor"),
(get_version_from_string("1.1.2.1"), "minor"),
(get_version_from_string("1.3.1.1"), "major"),
(get_version_from_string("2.1.2.1"), "minor"),
(get_version_from_string("2.2.1.3"), "patch"),
(get_version_from_string("2.2.3.1"), "latest"),
(get_version_from_string("2.3.1.1"), "latest"),
)
_ = get_tagged_versions()
for case in cases: