From 5d7ff135f6f44148e8a977b88cc71c8066239ac5 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 14 Feb 2025 11:44:35 -0500 Subject: [PATCH] script/build-with-container: support custom tag suffixes Previously, one could use the `--tag` option to completely override the container tag generated by the script. However, there are cases where one may want to add information to the tag rather than override it. Allow the tag value to start with a plus (+) character that indicates that the remainder of the string is to be suffixed to the generated tag. Signed-off-by: John Mulligan (cherry picked from commit 30836c4ed4b9332f22b31897ce4ece0ad4da6fc0) --- src/script/build-with-container.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/script/build-with-container.py b/src/script/build-with-container.py index d7ec7c0ad1254..32f4d37088f0b 100755 --- a/src/script/build-with-container.py +++ b/src/script/build-with-container.py @@ -284,7 +284,10 @@ class Context: return f"{base}:{self.target_tag()}" def target_tag(self): - if self.cli.tag: + suffix = "" + if self.cli.tag and self.cli.tag.startswith("+"): + suffix = f".{self.cli.tag[1:]}" + elif self.cli.tag: return self.cli.tag branch = self.cli.current_branch if not branch: @@ -292,7 +295,7 @@ class Context: branch = _git_current_branch(self).replace("/", "-") except subprocess.CalledProcessError: branch = "UNKNOWN" - return f"{branch}.{self.cli.distro}" + return f"{branch}.{self.cli.distro}{suffix}" def base_branch(self): # because git truly is the *stupid* content tracker there's not a @@ -301,7 +304,7 @@ class Context: # container bootstrap we default to `main` even when that's not true. # One can explicltly set the base branch on the command line to invoke # customizations (that don't yet exist) or invalidate image caching. - return self.cli.base_branch or 'main' + return self.cli.base_branch or "main" @property def from_image(self): @@ -678,7 +681,8 @@ def parse_cli(build_step_names): parser.add_argument( "--tag", "-t", - help="Specify a container tag", + help="Specify a container tag. Append to the auto generated tag" + " by prefixing the supplied value with the plus (+) character", ) parser.add_argument( "--base-branch", -- 2.39.5