Skip to content

Commit ac4cad3

Browse files
committed
schema: also keep the manifest list digest in meta.json
Add a new `manifest-list-digest` to the OCI image objects we publish in `meta.json` for our pushed images containing a backreference to the digest of the manifest list. Otherwise, that digest is not really captured anywhere in our metadata. This could be used down the line to also add the manifest list digest to release metadata, which would be more appropriate as the aggregation point of metadata across all the arches. But the more immediate want for it is for use in `cosa sign`.
1 parent 4ec5990 commit ac4cad3

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

pkg/builds/cosa_v1.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package builds
22

33
// generated by 'make schema'
4-
// source hash: 4289a52f5ee4665caa5432d9caa653b74605117632ac045955912e624d149524
4+
// source hash: 11704f512a9b6e0c5ac178a9917e03a05ea10a7878ef9b5c0a6695d52c9cd7f5
55

66
type AdvisoryDiff []AdvisoryDiffItems
77

@@ -182,11 +182,12 @@ type PackageSetDifferences []PackageSetDifferencesItems
182182
type PackageSetDifferencesItems interface{}
183183

184184
type PrimaryImage struct {
185-
AdditionalImages []interface{} `json:"additional-images,omitempty"`
186-
Comment string `json:"comment,omitempty"`
187-
Digest string `json:"digest,omitempty"`
188-
Image string `json:"image"`
189-
Tags []PrimaryImageTag `json:"tags,omitempty"`
185+
AdditionalImages []interface{} `json:"additional-images,omitempty"`
186+
Comment string `json:"comment,omitempty"`
187+
Digest string `json:"digest,omitempty"`
188+
Image string `json:"image"`
189+
ManifestListDigest string `json:"manifest-list-digest,omitempty"`
190+
Tags []PrimaryImageTag `json:"tags,omitempty"`
190191
}
191192

192193
type PrimaryImageTag string

pkg/builds/schema_doc.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Generated by ./generate-schema.sh
2-
// Source hash: 4289a52f5ee4665caa5432d9caa653b74605117632ac045955912e624d149524
2+
// Source hash: 11704f512a9b6e0c5ac178a9917e03a05ea10a7878ef9b5c0a6695d52c9cd7f5
33
// DO NOT EDIT
44

55
package builds
@@ -98,6 +98,7 @@ var generatedSchemaJSON = `{
9898
],
9999
"optional": [
100100
"digest",
101+
"manifest-list-digest",
101102
"tags",
102103
"comment",
103104
"additional-images"
@@ -108,6 +109,11 @@ var generatedSchemaJSON = `{
108109
"type": "string",
109110
"title": "Digest"
110111
},
112+
"manifest-list-digest": {
113+
"$id": "#/image/manifest-list-digest",
114+
"type": "string",
115+
"title": "Manifest List Digest"
116+
},
111117
"comment": {
112118
"$id": "#/image/comment",
113119
"type": "string",

src/cmd-coreos-prune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Build = collections.namedtuple("Build", ["id", "images", "arch", "meta_json"])
5555
# set metadata caching to 5m
5656
CACHE_MAX_AGE_METADATA = 60 * 5
5757
# These lists are up to date as of schema hash
58-
# 4289a52f5ee4665caa5432d9caa653b74605117632ac045955912e624d149524. If changing
58+
# 11704f512a9b6e0c5ac178a9917e03a05ea10a7878ef9b5c0a6695d52c9cd7f5. If changing
5959
# this hash, ensure that the list of SUPPORTED and UNSUPPORTED artifacts below
6060
# is up to date.
6161
SUPPORTED = ["amis", "aws-winli", "gcp"]

src/cmd-push-container-manifest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def main():
103103
return
104104

105105
# Create/Upload the manifest list to the container registry
106-
manifest_info = create_and_push_container_manifest(
106+
manifest_digest, manifest_info = create_and_push_container_manifest(
107107
args.repo, args.tags, images, args.write_digest_to_file, args.v2s2)
108108
# if we pushed in v2s2 mode, we need to reload from the repo the actual
109109
# final digests: https://github.com/containers/podman/issues/16603
@@ -125,6 +125,7 @@ def main():
125125
image = {
126126
'image': args.repo,
127127
'digest': manifest['digest'],
128+
'manifest-list-digest': manifest_digest,
128129
'tags': args.tags
129130
}
130131
if buildmetas[arch].get(args.metajsonname):

src/cosalib/container_manifest.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import tempfile
23

34
from cosalib.cmdlib import runcmd
45

@@ -53,7 +54,7 @@ def delete_local_container_imgref(repo, tag):
5354
runcmd(cmd)
5455

5556

56-
def push_container_manifest(repo, tags, write_digest_to_file, v2s2=False):
57+
def push_container_manifest(repo, tags, write_digest_to_file, v2s2=False) -> str:
5758
'''
5859
Push manifest to registry
5960
@param repo str registry repository
@@ -66,14 +67,21 @@ def push_container_manifest(repo, tags, write_digest_to_file, v2s2=False):
6667
# to create a manifest with 2 different mediaType. It seems to be
6768
# a Quay issue.
6869
base_cmd.extend(["--remove-signatures", "-f", "v2s2"])
69-
if write_digest_to_file:
70-
base_cmd.extend(["--digestfile", write_digest_to_file])
71-
runcmd(base_cmd + [f"{repo}:{tags[0]}"])
70+
71+
with tempfile.NamedTemporaryFile(mode='r+', encoding='utf-8') as f:
72+
runcmd(base_cmd + [f"{repo}:{tags[0]}", "--digestfile", f.name])
73+
digest = f.read()
74+
if write_digest_to_file:
75+
with open(write_digest_to_file, mode='w', encoding='utf-8') as g:
76+
g.write(digest)
77+
7278
for tag in tags[1:]:
7379
runcmd(base_cmd + [f"{repo}:{tag}"])
7480

81+
return digest
82+
7583

76-
def create_and_push_container_manifest(repo, tags, images, write_digest_to_file, v2s2) -> dict:
84+
def create_and_push_container_manifest(repo, tags, images, write_digest_to_file, v2s2) -> tuple[str, dict]:
7785
'''
7886
Do it all! Create, push, cleanup, and return the final manifest JSON.
7987
@param repo str registry repository
@@ -85,6 +93,6 @@ def create_and_push_container_manifest(repo, tags, images, write_digest_to_file,
8593
# perhaps left over from a previous failed run -> delete
8694
delete_local_container_imgref(repo, tags[0])
8795
manifest_info = create_local_container_manifest(repo, tags[0], images)
88-
push_container_manifest(repo, tags, write_digest_to_file, v2s2)
96+
manifest_digest = push_container_manifest(repo, tags, write_digest_to_file, v2s2)
8997
delete_local_container_imgref(repo, tags[0])
90-
return manifest_info
98+
return (manifest_digest, manifest_info)

src/v1.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
],
9393
"optional": [
9494
"digest",
95+
"manifest-list-digest",
9596
"tags",
9697
"comment",
9798
"additional-images"
@@ -102,6 +103,11 @@
102103
"type": "string",
103104
"title": "Digest"
104105
},
106+
"manifest-list-digest": {
107+
"$id": "#/image/manifest-list-digest",
108+
"type": "string",
109+
"title": "Manifest List Digest"
110+
},
105111
"comment": {
106112
"$id": "#/image/comment",
107113
"type": "string",

0 commit comments

Comments
 (0)