Skip to content

Commit

Permalink
cmd-push-container-manifest: store arch-specific digest in meta.json
Browse files Browse the repository at this point in the history
As discussed in coreos#3122,
ART needs the arch-specific digest in the `meta.json` rather than the
manifest list digest. FCOS isn't planning to use the digest so doesn't
care about which one gets chosen.

Update `cosa push-container-manifest` to use the arch-specific digest.
  • Loading branch information
jlebon committed Oct 21, 2022
1 parent 9837db6 commit 9addd2c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
23 changes: 12 additions & 11 deletions src/cmd-push-container-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import argparse
import os
import sys
import tempfile
from cosalib.container_manifest import create_and_push_container_manifest
from cosalib.builds import Builds
from cosalib.meta import GenericBuildMeta
Expand All @@ -22,7 +21,7 @@ def main():
if args.images:
# User provided images directly
create_and_push_container_manifest(
args.repo, args.tags, args.images, args.v2s2, None)
args.repo, args.tags, args.images, args.v2s2)
else:
# Picking up images from artifacts in meta.json
builds = Builds()
Expand Down Expand Up @@ -60,17 +59,19 @@ def main():
images.append(f"oci-archive:{ociarchive}")

# Create/Upload the manifest list to the container registry
with tempfile.NamedTemporaryFile() as digestfile:
create_and_push_container_manifest(
args.repo, args.tags, images, args.v2s2, digestfile.name)
digestfile.seek(0)
digest = digestfile.read().decode('utf-8').strip()
manifest = create_and_push_container_manifest(
args.repo, args.tags, images, args.v2s2)

# Update the meta.json in each build/arch metadata
for _, buildmeta in buildmetas.items():
buildmeta[args.metajsonname] = {
assert len(manifest['manifests']) == len(buildmetas)
for manifest in manifest['manifests']:
arch = manifest['platform']['architecture']
if arch == 'arm64':
arch = 'aarch64'
elif arch == 'amd64':
arch = 'x86_64'
buildmetas[arch][args.metajsonname] = {
'image': args.repo,
'digest': digest
'digest': manifest['digest']
}
buildmeta.write(artifact_name=args.metajsonname)

Expand Down
15 changes: 8 additions & 7 deletions src/cosalib/container_manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from cosalib.cmdlib import runcmd


Expand Down Expand Up @@ -25,13 +27,12 @@ def delete_local_container_manifest(repo, tag):
runcmd(cmd)


def push_container_manifest(repo, main_tag, add_tags, digestfile, v2s2=False):
def push_container_manifest(repo, main_tag, add_tags, v2s2=False):
'''
Push manifest to registry
@param repo str registry repository
@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
'''
base_cmd = ["podman", "manifest", "push", "--all", f"{repo}:{main_tag}"]
Expand All @@ -40,23 +41,23 @@ def push_container_manifest(repo, main_tag, add_tags, digestfile, v2s2=False):
# to create a manifest with 2 different mediaType. It seems to be
# a Quay issue.
base_cmd.extend(["--remove-signatures", "-f", "v2s2"])
if digestfile:
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, tags, images, v2s2, digestfile):
def create_and_push_container_manifest(repo, tags, images, v2s2):
'''
Do it all! Create, Push, Cleanup
@param repo str registry repository
@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
'''
main_tag = tags[0]
create_local_container_manifest(repo, main_tag, images)
push_container_manifest(repo, main_tag, tags[1:], digestfile, v2s2)
push_container_manifest(repo, main_tag, tags[1:], v2s2)
inspect = runcmd(["podman", "manifest", "inspect", f"{repo}:{main_tag}"],
capture_output=True).stdout
delete_local_container_manifest(repo, main_tag)
return json.loads(inspect)

0 comments on commit 9addd2c

Please sign in to comment.