Skip to content

Commit 676131f

Browse files
jlebondustymabe
authored andcommitted
cmd-push-container-manifest: store arch-specific digest in meta.json
As discussed in #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. (cherry picked from commit c7b5757) (cherry picked from commit 2efa549) (cherry picked from commit 3685382)
1 parent 2f9b04d commit 676131f

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/cmd-push-container-manifest

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import argparse
77
import os
88
import sys
9-
import tempfile
109
from cosalib.container_manifest import create_and_push_container_manifest
1110
from cosalib.builds import Builds
1211
from cosalib.meta import GenericBuildMeta
@@ -22,7 +21,7 @@ def main():
2221
if args.images:
2322
# User provided images directly
2423
create_and_push_container_manifest(
25-
args.repo, args.tags, args.images, args.v2s2, None)
24+
args.repo, args.tags, args.images, args.v2s2)
2625
else:
2726
# Picking up images from artifacts in meta.json
2827
builds = Builds()
@@ -60,19 +59,24 @@ def main():
6059
images.append(f"oci-archive:{ociarchive}")
6160

6261
# Create/Upload the manifest list to the container registry
63-
with tempfile.NamedTemporaryFile() as digestfile:
64-
create_and_push_container_manifest(
65-
args.repo, args.tags, images, args.v2s2, digestfile.name)
66-
digestfile.seek(0)
67-
digest = digestfile.read().decode('utf-8').strip()
62+
manifest_info = create_and_push_container_manifest(
63+
args.repo, args.tags, images, args.v2s2)
6864

69-
# Update the meta.json in each build/arch metadata
70-
for _, buildmeta in buildmetas.items():
71-
buildmeta[args.metajsonname] = {
65+
# Update the `meta.json` files. Note the digest included is the
66+
# arch-specific one for each individual arch, and not the manifest list
67+
# digest. See: https://github.com/coreos/coreos-assembler/issues/3122.
68+
assert len(manifest_info['manifests']) == len(buildmetas)
69+
for manifest in manifest_info['manifests']:
70+
arch = manifest['platform']['architecture']
71+
if arch == 'arm64':
72+
arch = 'aarch64'
73+
elif arch == 'amd64':
74+
arch = 'x86_64'
75+
buildmetas[arch][args.metajsonname] = {
7276
'image': args.repo,
73-
'digest': digest
77+
'digest': manifest['digest']
7478
}
75-
buildmeta.write(artifact_name=args.metajsonname)
79+
buildmetas[arch].write(artifact_name=args.metajsonname)
7680

7781

7882
def parse_args():

src/cosalib/container_manifest.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import json
2+
13
from cosalib.utils import runcmd
24

35

4-
def create_local_container_manifest(repo, tag, images):
6+
def create_local_container_manifest(repo, tag, images) -> dict:
57
'''
6-
Create local manifest list
8+
Create local manifest list and return the final manifest JSON
79
@param images list of image specifications (including transport)
810
@param repo str registry repository
911
@param tag str manifest tag
@@ -13,6 +15,9 @@ def create_local_container_manifest(repo, tag, images):
1315
for image in images:
1416
cmd = ["podman", "manifest", "add", f"{repo}:{tag}", image]
1517
runcmd(cmd)
18+
manifest_info = runcmd(["podman", "manifest", "inspect", f"{repo}:{tag}"],
19+
capture_output=True).stdout
20+
return json.loads(manifest_info)
1621

1722

1823
def delete_local_container_manifest(repo, tag):
@@ -25,12 +30,11 @@ def delete_local_container_manifest(repo, tag):
2530
runcmd(cmd)
2631

2732

28-
def push_container_manifest(repo, tags, digestfile, v2s2=False):
33+
def push_container_manifest(repo, tags, v2s2=False):
2934
'''
3035
Push manifest to registry
3136
@param repo str registry repository
3237
@param tags list of tags to push
33-
@param digestfile str write container digest to file
3438
@param v2s2 boolean use to force v2s2 format
3539
'''
3640
base_cmd = ["podman", "manifest", "push", "--all", f"{repo}:{tags[0]}"]
@@ -39,22 +43,20 @@ def push_container_manifest(repo, tags, digestfile, v2s2=False):
3943
# to create a manifest with 2 different mediaType. It seems to be
4044
# a Quay issue.
4145
base_cmd.extend(["--remove-signatures", "-f", "v2s2"])
42-
if digestfile:
43-
base_cmd.extend([f"--digestfile={digestfile}"])
4446
runcmd(base_cmd + [f"{repo}:{tags[0]}"])
4547
for tag in tags[1:]:
4648
runcmd(base_cmd + [f"{repo}:{tag}"])
4749

4850

49-
def create_and_push_container_manifest(repo, tags, images, v2s2, digestfile):
51+
def create_and_push_container_manifest(repo, tags, images, v2s2) -> dict:
5052
'''
51-
Do it all! Create, Push, Cleanup
53+
Do it all! Create, push, cleanup, and return the final manifest JSON.
5254
@param repo str registry repository
5355
@param tags list of tags
5456
@param images list of image specifications (including transport)
5557
@param v2s2 boolean use to force v2s2 format
56-
@param digestfile str write container digest to file
5758
'''
58-
create_local_container_manifest(repo, tags[0], images)
59-
push_container_manifest(repo, tags, digestfile, v2s2)
59+
manifest_info = create_local_container_manifest(repo, tags[0], images)
60+
push_container_manifest(repo, tags, v2s2)
6061
delete_local_container_manifest(repo, tags[0])
62+
return manifest_info

0 commit comments

Comments
 (0)