-
Notifications
You must be signed in to change notification settings - Fork 32
common/libimage/manifests.list.Add(): add from lists without images #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -518,6 +518,7 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag | |
| Features, OSFeatures, Annotations []string | ||
| Size int64 | ||
| ConfigInfo types.BlobInfo | ||
| MediaType string | ||
| ArtifactType string | ||
| URLs []string | ||
| } | ||
|
|
@@ -550,6 +551,7 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag | |
| Features: append([]string{}, lists.Docker().Manifests[i].Platform.Features...), | ||
| OSFeatures: append([]string{}, platform.OSFeatures...), | ||
| Size: instance.Size, | ||
| MediaType: instance.MediaType, | ||
| ArtifactType: instance.ArtifactType, | ||
| Annotations: mapToSlice(instance.Annotations), | ||
| URLs: instance.URLs, | ||
|
|
@@ -583,10 +585,12 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag | |
| Features: append([]string{}, lists.Docker().Manifests[i].Platform.Features...), | ||
| OSFeatures: append([]string{}, platform.OSFeatures...), | ||
| Size: instance.Size, | ||
| MediaType: instance.MediaType, | ||
| ArtifactType: instance.ArtifactType, | ||
| Annotations: mapToSlice(instance.Annotations), | ||
| URLs: instance.URLs, | ||
| } | ||
| manifestDigest = instanceDigest | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes behavior - … well, I’m not sure it is useful either way. But, Podman’s |
||
| instanceInfos = append(instanceInfos, instanceInfo) | ||
| added = true | ||
| } | ||
|
|
@@ -606,22 +610,28 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag | |
| instanceInfo.ArtifactType = m.ArtifactType | ||
| } | ||
| } | ||
| instanceInfo.MediaType = primaryManifestType | ||
| instanceInfo.Size = int64(len(primaryManifestBytes)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Consider setting these in the |
||
| instanceInfos = append(instanceInfos, instanceInfo) | ||
| } | ||
|
|
||
| knownConfigTypes := []string{manifest.DockerV2Schema2ConfigMediaType, v1.MediaTypeImageConfig} | ||
| for _, instanceInfo := range instanceInfos { | ||
| var hasPlatformConfig bool | ||
| unparsedInstance := image.UnparsedInstance(src, instanceInfo.instanceDigest) | ||
| manifestBytes, manifestType, err := unparsedInstance.Manifest(ctx) | ||
| if err != nil { | ||
| return "", fmt.Errorf("reading manifest from %q, instance %q: %w", transports.ImageName(ref), instanceInfo.instanceDigest, err) | ||
| } | ||
| instanceManifest, err := manifest.FromBlob(manifestBytes, manifestType) | ||
| if err != nil { | ||
| return "", fmt.Errorf("parsing manifest from %q, instance %q: %w", transports.ImageName(ref), instanceInfo.instanceDigest, err) | ||
| if mb, mt, err := unparsedInstance.Manifest(ctx); err == nil { | ||
| if instanceManifest, err := manifest.FromBlob(mb, mt); err == nil { | ||
| instanceDigest, err := manifest.Digest(mb) | ||
| if err != nil { | ||
| return "", fmt.Errorf("computing digest of manifest from %q: %w", transports.ImageName(ref), err) | ||
| } | ||
| instanceInfo.instanceDigest = &instanceDigest | ||
| instanceInfo.MediaType = mt | ||
| instanceInfo.Size = int64(len(mb)) | ||
|
Comment on lines
+628
to
+630
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem unnecessary or undesirable — if we have a list (and a digest reference to that list, guaranteeing integrity), the values in the list are “more authoritative” than what the registry returns. And, from the other code paths, it seems that all of these values are known via other means (yes, in case of a tagged reference to a single-platform manifest, we do trust the registry, but only in that case). |
||
| instanceInfo.ConfigInfo = instanceManifest.ConfigInfo() | ||
| hasPlatformConfig = instanceInfo.ArtifactType == "" && slices.Contains(knownConfigTypes, instanceInfo.ConfigInfo.MediaType) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s not clear to me why silently setting |
||
| } | ||
| } | ||
| instanceInfo.ConfigInfo = instanceManifest.ConfigInfo() | ||
| hasPlatformConfig := instanceInfo.ArtifactType == "" && slices.Contains(knownConfigTypes, instanceInfo.ConfigInfo.MediaType) | ||
| needToParsePlatformConfig := (instanceInfo.OS == "" || instanceInfo.Architecture == "") | ||
| if hasPlatformConfig && needToParsePlatformConfig { | ||
| img, err := image.FromUnparsedImage(ctx, sys, unparsedInstance) | ||
|
|
@@ -643,16 +653,15 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag | |
| } | ||
| } | ||
| if instanceInfo.instanceDigest == nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be simpler to do all of this earlier, in the |
||
| manifestDigest, err = manifest.Digest(manifestBytes) | ||
| manifestDigest, err = manifest.Digest(primaryManifestBytes) | ||
| if err != nil { | ||
| return "", fmt.Errorf("computing digest of manifest from %q: %w", transports.ImageName(ref), err) | ||
| } | ||
| instanceInfo.instanceDigest = &manifestDigest | ||
| instanceInfo.Size = int64(len(manifestBytes)) | ||
| } else if manifestDigest == "" { | ||
| manifestDigest = *instanceInfo.instanceDigest | ||
| } | ||
| err = l.List.AddInstance(*instanceInfo.instanceDigest, instanceInfo.Size, manifestType, instanceInfo.OS, instanceInfo.Architecture, instanceInfo.OSVersion, instanceInfo.OSFeatures, instanceInfo.Variant, instanceInfo.Features, instanceInfo.Annotations) | ||
| err = l.List.AddInstance(*instanceInfo.instanceDigest, instanceInfo.Size, instanceInfo.MediaType, instanceInfo.OS, instanceInfo.Architecture, instanceInfo.OSVersion, instanceInfo.OSFeatures, instanceInfo.Variant, instanceInfo.Features, instanceInfo.Annotations) | ||
| if err != nil { | ||
| return "", fmt.Errorf("adding instance with digest %q: %w", *instanceInfo.instanceDigest, err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but: below, is the
!addedcase reachable? The digest chosen bylist.ChooseInstanceshould always be found, shouldn’t it?I’m primarily worried about the
!addedpath below not addingMediaType, making this harder to follow. Shouldn’t!addedbe an “this is supposed to be never reached” error path?