Skip to content

Commit 1c5c27a

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
hack/build-image: add --retag subcommand for regenerating image tags
There are two main use-cases for `--retag`: 1. You built the images without a particular registry and now want the images to use a fully-qualified registry name. Use `--retag` to image tags that use the registry name. Also, if you copied an image with only the FQIN and it lacks the "unqualified" forms. The samba-container CI jobs do this. 2. You built the images with a non-official registry/prefix (say, for a personal repo), tested it, and now want to push it to a more official location. You can use this command to retag the images to point at the desired repos. Signed-off-by: John Mulligan <[email protected]>
1 parent abe567b commit 1c5c27a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

hack/build-image

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,26 @@ def container_id(cli, target):
252252
return res.stdout.decode("utf8").strip()
253253

254254

255+
def container_tag(cli, target, tag, *tags):
256+
"""Add additional tags to the existing target image."""
257+
if isinstance(target, str):
258+
src = target # permit target to be a string w/ the desired source
259+
else:
260+
src = target.image_name()
261+
base_args = [
262+
container_engine(cli),
263+
"tag",
264+
src,
265+
]
266+
if "docker" not in base_args[0]:
267+
# podman can do it in one command, docker (on github ci) can not
268+
args += [tag] + list(tags)
269+
run(cli, args, check=True)
270+
return
271+
for new_tag in [tag] + list(tags):
272+
run(cli, base_args + [new_tag], check=True)
273+
274+
255275
def kind_source_dir(kind):
256276
"""Return the path to a kind's source directory."""
257277
return pathlib.Path("images") / SOURCE_DIRS[check_kind(kind)]
@@ -477,6 +497,24 @@ def push(cli, target):
477497
container_push(cli, push_name)
478498

479499

500+
def retag(cli, target):
501+
"""Command to regenerate any missing unqualified tags."""
502+
cid = container_id(cli, target)
503+
tags = []
504+
if cli.repo_base and target.repo_base != cli.repo_base:
505+
# if repo base is given on the cli, and differs from the
506+
# target, regenerate tags with the new distro base.
507+
# retag list
508+
target.repo_base = cli.repo_base
509+
# Ensure the new FQIN is part of the new tags list
510+
tags.append(target.image_name())
511+
tags += [target.image_name(tag=t) for t, _ in target.additional_tags]
512+
if tags:
513+
container_tag(cli, cid, *tags)
514+
else:
515+
logger.warning("no tags to add")
516+
517+
480518
def print_buildfile(cli, target):
481519
"""Command to print build file names."""
482520
build_file = pathlib.Path(f"{cli.buildfile_prefix}{target.flat_name()}")
@@ -654,6 +692,14 @@ def main():
654692
const=print_buildfile,
655693
help="Print the names of build status files",
656694
)
695+
behaviors.add_argument(
696+
"--retag",
697+
action="store_const",
698+
dest="main_action",
699+
const=retag,
700+
help=("Regenerate any short (unqualified) tags expected to exist"
701+
" for a given FQIN. Requires FQIN to already exist locally."),
702+
)
657703
cli = parser.parse_args()
658704

659705
if os.environ.get("BUILD_IMAGE_DEBUG") in ("1", "yes"):

0 commit comments

Comments
 (0)