Skip to content

Commit

Permalink
cmd-push-container-manifest: add support for multiple --tag arguments
Browse files Browse the repository at this point in the history
In the RHCOS pipeline, we want to be able to tag the same image using
both the stream name and the build ID.
  • Loading branch information
jlebon committed Oct 20, 2022
1 parent 5626645 commit e4bf879
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/cmd-push-container-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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')
Expand Down
27 changes: 15 additions & 12 deletions src/cosalib/container_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,38 @@ def delete_local_container_manifest(repo, tag):
runcmd(cmd)


def push_container_manifest(repo, tag, digestfile, v2s2=False):
def push_container_manifest(repo, main_tag, add_tags, digestfile, v2s2=False):
'''
Push manifest to registry
@param repo str registry repository
@param tag str manifest tag
@param main_tag str manifest tag
@param add_tags list of additional 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}:{main_tag}"]
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}:{main_tag}"])
for tag in add_tags:
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)
main_tag = tags[0]
create_local_container_manifest(repo, main_tag, images)
push_container_manifest(repo, main_tag, tags[1:], digestfile, v2s2)
delete_local_container_manifest(repo, main_tag)

0 comments on commit e4bf879

Please sign in to comment.