Skip to content

Commit 60c9ca1

Browse files
authored
Merge branch 'main' into bleggett/retry-docker-login
2 parents 28ba586 + ade7e18 commit 60c9ca1

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

hack/build/generate-docker-script.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from packaging.version import parse, Version
88

99
from matrix import CONFIG
10-
from util import format_image_name, maybe, smart_script_split, parse_text_bool
10+
from util import format_image_name, maybe, smart_script_split, parse_text_bool, get_branch_tag_suffix
1111

1212
# Targets that are handled via docker run + host CCACHE packaging stages.
1313
CCACHE_TARGET_MAP = {
@@ -166,18 +166,28 @@ def docker_build(
166166
publish: bool,
167167
pass_build_args: bool,
168168
mark_format: Optional[str],
169+
firmware_url: str,
170+
firmware_sig_url: str,
171+
tag_suffix: Optional[str] = None,
169172
) -> list[str]:
170173
lines = []
171174

172175
version = dockerify_version(version)
173176
actual_target = CCACHE_TARGET_MAP.get(target, target)
174177

178+
# tag_version is the version string used for OCI tags; version is the
179+
# actual kernel version passed as a build arg and recorded in annotations.
180+
# They differ when building from a non-main branch to avoid tag collisions.
181+
# Tags in the list are already branch-suffixed (applied during matrix generation).
182+
tag_version = "%s-%s" % (version, tag_suffix) if tag_suffix else version
183+
oci_tags = list(tags)
184+
175185
root = format_image_name(
176186
image_name_format=CONFIG["imageNameFormat"],
177187
flavor=flavor,
178188
version_info=version_info,
179189
name=name,
180-
tag=version,
190+
tag=tag_version,
181191
)
182192

183193
image_build_command = [
@@ -192,7 +202,7 @@ def docker_build(
192202
"--target",
193203
quoted(actual_target),
194204
"--iidfile",
195-
quoted("image-id-%s-%s-%s" % (version, flavor, actual_target)),
205+
quoted("image-id-%s-%s-%s" % (tag_version, flavor, actual_target)),
196206
]
197207

198208
for build_platform in docker_platforms(architectures):
@@ -229,8 +239,8 @@ def docker_build(
229239
all_tags = [root]
230240
additional_tags = []
231241

232-
for tag in tags:
233-
if tag == version:
242+
for tag in oci_tags:
243+
if tag == tag_version:
234244
continue
235245
additional_tags.append(
236246
format_image_name(
@@ -261,7 +271,7 @@ def docker_build(
261271
"sign",
262272
"--yes",
263273
quoted(
264-
'%s@$(cat "image-id-%s-%s-%s")' % (tag, version, flavor, actual_target)
274+
'%s@$(cat "image-id-%s-%s-%s")' % (tag, tag_version, flavor, actual_target)
265275
),
266276
]
267277
lines += [""]
@@ -288,6 +298,7 @@ def generate_builds(
288298
kernel_architectures: list[str],
289299
firmware_url: str,
290300
firmware_sig_url: str,
301+
tag_suffix: Optional[str] = None,
291302
) -> list[str]:
292303
lines = []
293304
kernel_version_info = parse(kernel_version)
@@ -336,6 +347,9 @@ def generate_builds(
336347
mark_format=image_format,
337348
flavor=kernel_flavor,
338349
architectures=kernel_architectures,
350+
firmware_url=firmware_url,
351+
firmware_sig_url=firmware_sig_url,
352+
tag_suffix=tag_suffix,
339353
)
340354
return lines
341355

@@ -356,11 +370,13 @@ def generate_build_from_env() -> list[str]:
356370
kernel_architectures=root_kernel_architectures,
357371
firmware_url=root_firmware_url,
358372
firmware_sig_url=root_firmware_sig_url,
373+
tag_suffix=get_branch_tag_suffix(),
359374
)
360375

361376

362377
def generate_builds_from_matrix(matrix) -> list[str]:
363378
lines = []
379+
tag_suffix = get_branch_tag_suffix()
364380
builds = matrix["builds"] # type: list[dict[str, any]]
365381
for build in builds:
366382
build_version = build["version"]
@@ -378,6 +394,7 @@ def generate_builds_from_matrix(matrix) -> list[str]:
378394
kernel_architectures=build_architectures,
379395
firmware_url=firmware_url,
380396
firmware_sig_url=firmware_sig_url,
397+
tag_suffix=tag_suffix,
381398
)
382399
return lines
383400

hack/build/generate-matrix.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
import matrix
5-
from util import parse_text_constraint, maybe
5+
from util import parse_text_constraint, maybe, get_branch_tag_suffix
66
from packaging.version import Version, parse
77

88

@@ -29,10 +29,7 @@ def construct_all_matrix():
2929

3030

3131
def construct_manual_matrix(exact_versions):
32-
reflective = {}
33-
for version in exact_versions:
34-
reflective[version] = version
35-
return matrix.generate_matrix(reflective)
32+
return matrix.generate_matrix(matrix.build_release_tags(exact_versions))
3633

3734

3835
DEFAULT_BUILD_SPEC = "new"
@@ -110,6 +107,12 @@ def construct_manual_matrix(exact_versions):
110107
matrix.validate_produce_conflicts(final_matrix)
111108
matrix.fill_runners(final_matrix)
112109

110+
branch_suffix = get_branch_tag_suffix()
111+
if branch_suffix:
112+
for build in final_matrix:
113+
build["tags"] = ["%s-%s" % (t, branch_suffix) for t in build["tags"]]
114+
build["produces"] = ["%s-%s" % (p, branch_suffix) for p in build["produces"]]
115+
113116
print("generated %s builds" % len(final_matrix))
114117
matrix.summarize_matrix(final_matrix)
115118

hack/build/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import os
2+
import re
13
from typing import Optional
24

35
from packaging.version import Version
46
import subprocess
57

68

9+
def get_branch_tag_suffix() -> Optional[str]:
10+
ref_name = os.getenv("GITHUB_REF_NAME", "")
11+
if not ref_name or ref_name == "main":
12+
return None
13+
return re.sub(r'[^a-zA-Z0-9._-]', '_', ref_name)
14+
15+
716
def format_image_name(
817
image_name_format: str, flavor: str, version_info: Version, name: str, tag: str
918
) -> str:

0 commit comments

Comments
 (0)