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 <pawel.gronowski@docker.com>
(cherry picked from commit d131f00fff
)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
5a0015f72c
commit
78174d2e74
1 changed files with 17 additions and 10 deletions
|
@ -260,6 +260,12 @@ func (s *saveSession) save(outStream io.Writer) error {
|
|||
}
|
||||
size := int64(len(data))
|
||||
|
||||
untaggedMfstDesc := ocispec.Descriptor{
|
||||
MediaType: ocispec.MediaTypeImageManifest,
|
||||
Digest: dgst,
|
||||
Size: size,
|
||||
Platform: m.Config.Platform,
|
||||
}
|
||||
for _, ref := range imageDescr.refs {
|
||||
familiarName := reference.FamiliarName(ref)
|
||||
if _, ok := reposLegacy[familiarName]; !ok {
|
||||
|
@ -268,16 +274,17 @@ func (s *saveSession) save(outStream io.Writer) error {
|
|||
reposLegacy[familiarName][ref.Tag()] = digest.Digest(imageDescr.layers[len(imageDescr.layers)-1]).Encoded()
|
||||
repoTags = append(repoTags, reference.FamiliarString(ref))
|
||||
|
||||
manifestDescriptors = append(manifestDescriptors, ocispec.Descriptor{
|
||||
MediaType: ocispec.MediaTypeImageManifest,
|
||||
Digest: dgst,
|
||||
Size: size,
|
||||
Platform: m.Config.Platform,
|
||||
Annotations: map[string]string{
|
||||
images.AnnotationImageName: ref.String(),
|
||||
ocispec.AnnotationRefName: ref.Tag(),
|
||||
},
|
||||
})
|
||||
taggedManifest := untaggedMfstDesc
|
||||
taggedManifest.Annotations = map[string]string{
|
||||
images.AnnotationImageName: ref.String(),
|
||||
ocispec.AnnotationRefName: ref.Tag(),
|
||||
}
|
||||
manifestDescriptors = append(manifestDescriptors, taggedManifest)
|
||||
}
|
||||
|
||||
// If no ref was assigned, make sure still add the image is still included in index.json.
|
||||
if len(manifestDescriptors) == 0 {
|
||||
manifestDescriptors = append(manifestDescriptors, untaggedMfstDesc)
|
||||
}
|
||||
|
||||
for _, l := range imageDescr.layers {
|
||||
|
|
Loading…
Add table
Reference in a new issue