From 83f59c943c337b9b793a50c5598a20df70a60bc1 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 18 Oct 2022 17:00:26 -0400 Subject: [PATCH] cmd-push-container-manifest: add support for multiple --tag arguments In the RHCOS pipeline, we want to be able to tag the same image using both the stream name and the build ID. (cherry picked from commit d3356419f496304e9fe52ea3c6e7d09c4b060ee8) (cherry picked from commit d3016da67221e0fdf7cf520331adfacb5195a856) (cherry picked from commit 6287835aa519146a75c6c88eefa20b818fd0faff) --- src/cmd-push-container-manifest | 7 ++++--- src/cosalib/container_manifest.py | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/cmd-push-container-manifest b/src/cmd-push-container-manifest index fc0c4845a4..a02867c98a 100755 --- a/src/cmd-push-container-manifest +++ b/src/cmd-push-container-manifest @@ -22,7 +22,7 @@ def main(): if args.images: # User provided images directly create_and_push_container_manifest( - args.repo, args.tag, args.images, args.v2s2, None) + args.repo, args.tags, args.images, args.v2s2, None) else: # Picking up images from artifacts in meta.json builds = Builds() @@ -62,7 +62,7 @@ def main(): # Create/Upload the manifest list to the container registry with tempfile.NamedTemporaryFile() as digestfile: create_and_push_container_manifest( - args.repo, args.tag, images, args.v2s2, digestfile.name) + args.repo, args.tags, images, args.v2s2, digestfile.name) digestfile.seek(0) digest = digestfile.read().decode('utf-8').strip() @@ -95,7 +95,8 @@ Examples: --repo quay.io/dustymabe/fedora-coreos --tag stable --artifact=ostree \\ --metajsonname=base-oscontainer --build=latest --arch=x86_64 --arch=aarch64""") parser.add_argument("--repo", required=True, help="The registry repo to target for the manifest") - parser.add_argument("--tag", required=True, help="The tag of the manifest to use") + parser.add_argument("--tag", required=True, dest='tags', action='append', + help="The tag of the manifest to use") parser.add_argument("--authfile", help="A file to use for registry auth") parser.add_argument('--v2s2', action='store_true', help='Use old image manifest version 2 schema 2 format') diff --git a/src/cosalib/container_manifest.py b/src/cosalib/container_manifest.py index e407a00e67..9cb786bb81 100644 --- a/src/cosalib/container_manifest.py +++ b/src/cosalib/container_manifest.py @@ -25,35 +25,36 @@ def delete_local_container_manifest(repo, tag): runcmd(cmd) -def push_container_manifest(repo, tag, digestfile, v2s2=False): +def push_container_manifest(repo, tags, digestfile, v2s2=False): ''' Push manifest to registry @param repo str registry repository - @param tag str manifest tag + @param tags list of tags to push @param digestfile str write container digest to file @param v2s2 boolean use to force v2s2 format ''' - cmd = ["podman", "manifest", "push", - "--all", f"{repo}:{tag}", f"{repo}:{tag}"] + base_cmd = ["podman", "manifest", "push", "--all", f"{repo}:{tags[0]}"] if v2s2: # `--remove-signatures -f v2s2` is a workaround for when you try # to create a manifest with 2 different mediaType. It seems to be # a Quay issue. - cmd.extend(["--remove-signatures", "-f", "v2s2"]) + base_cmd.extend(["--remove-signatures", "-f", "v2s2"]) if digestfile: - cmd.extend([f"--digestfile={digestfile}"]) - runcmd(cmd) + base_cmd.extend([f"--digestfile={digestfile}"]) + runcmd(base_cmd + [f"{repo}:{tags[0]}"]) + for tag in tags[1:]: + runcmd(base_cmd + [f"{repo}:{tag}"]) -def create_and_push_container_manifest(repo, tag, images, v2s2, digestfile): +def create_and_push_container_manifest(repo, tags, images, v2s2, digestfile): ''' Do it all! Create, Push, Cleanup @param repo str registry repository - @param tag str manifest tag + @param tags list of tags @param images list of image specifications (including transport) @param v2s2 boolean use to force v2s2 format @param digestfile str write container digest to file ''' - create_local_container_manifest(repo, tag, images) - push_container_manifest(repo, tag, digestfile, v2s2) - delete_local_container_manifest(repo, tag) + create_local_container_manifest(repo, tags[0], images) + push_container_manifest(repo, tags, digestfile, v2s2) + delete_local_container_manifest(repo, tags[0])