Skip to content

Commit d131f00

Browse files
committed
image/save: Fix untagged images not present in index.json
Saving an image via digested reference, ID or truncated ID doesn't store the image reference in the archive. This also causes the save code to not add the image's manifest to the index.json. This commit explicitly adds the untagged manifests to the index.json if no tagged manifests were added. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 7d4ee14 commit d131f00

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

image/tarexport/save.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ func (s *saveSession) save(outStream io.Writer) error {
260260
}
261261
size := int64(len(data))
262262

263+
untaggedMfstDesc := ocispec.Descriptor{
264+
MediaType: ocispec.MediaTypeImageManifest,
265+
Digest: dgst,
266+
Size: size,
267+
Platform: m.Config.Platform,
268+
}
263269
for _, ref := range imageDescr.refs {
264270
familiarName := reference.FamiliarName(ref)
265271
if _, ok := reposLegacy[familiarName]; !ok {
@@ -268,16 +274,17 @@ func (s *saveSession) save(outStream io.Writer) error {
268274
reposLegacy[familiarName][ref.Tag()] = digest.Digest(imageDescr.layers[len(imageDescr.layers)-1]).Encoded()
269275
repoTags = append(repoTags, reference.FamiliarString(ref))
270276

271-
manifestDescriptors = append(manifestDescriptors, ocispec.Descriptor{
272-
MediaType: ocispec.MediaTypeImageManifest,
273-
Digest: dgst,
274-
Size: size,
275-
Platform: m.Config.Platform,
276-
Annotations: map[string]string{
277-
images.AnnotationImageName: ref.String(),
278-
ocispec.AnnotationRefName: ref.Tag(),
279-
},
280-
})
277+
taggedManifest := untaggedMfstDesc
278+
taggedManifest.Annotations = map[string]string{
279+
images.AnnotationImageName: ref.String(),
280+
ocispec.AnnotationRefName: ref.Tag(),
281+
}
282+
manifestDescriptors = append(manifestDescriptors, taggedManifest)
283+
}
284+
285+
// If no ref was assigned, make sure still add the image is still included in index.json.
286+
if len(manifestDescriptors) == 0 {
287+
manifestDescriptors = append(manifestDescriptors, untaggedMfstDesc)
281288
}
282289

283290
for _, l := range imageDescr.layers {

0 commit comments

Comments
 (0)