Skip to content

Commit

Permalink
Merge pull request #431 from imeoer/cherry-pick-v0.7
Browse files Browse the repository at this point in the history
[stable/v0.7] converter: support OCI reference type
  • Loading branch information
imeoer committed Mar 21, 2023
2 parents 2abb493 + c59c7d5 commit 2b7058a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func ConvertHookFunc(opt MergeOption) converter.ConvertHookFunc {
case images.IsIndexType(newDesc.MediaType):
return convertIndex(ctx, cs, orgDesc, newDesc)
case images.IsManifestType(newDesc.MediaType):
return convertManifest(ctx, cs, newDesc, opt)
return convertManifest(ctx, cs, orgDesc, newDesc, opt)
default:
return newDesc, nil
}
Expand Down Expand Up @@ -869,6 +869,13 @@ func convertIndex(ctx context.Context, cs content.Store, orgDesc ocispec.Descrip
manifest.Platform.OSFeatures = append(manifest.Platform.OSFeatures, ManifestOSFeatureNydus)
index.Manifests[i] = manifest
}

// If the converted manifest list contains only one manifest,
// convert it directly to manifest.
if len(index.Manifests) == 1 {
return &index.Manifests[0], nil
}

// Update image index in content store.
newIndexDesc, err := writeJSON(ctx, cs, index, *newDesc, indexLabels)
if err != nil {
Expand All @@ -893,7 +900,7 @@ func isNydusImage(manifest *ocispec.Manifest) bool {
// convertManifest merges all the nydus blob layers into a
// nydus bootstrap layer, update the image config,
// and modify the image manifest.
func convertManifest(ctx context.Context, cs content.Store, newDesc *ocispec.Descriptor, opt MergeOption) (*ocispec.Descriptor, error) {
func convertManifest(ctx context.Context, cs content.Store, oldDesc ocispec.Descriptor, newDesc *ocispec.Descriptor, opt MergeOption) (*ocispec.Descriptor, error) {
var manifest ocispec.Manifest
manifestDesc := *newDesc
manifestLabels, err := readJSON(ctx, cs, &manifest, manifestDesc)
Expand Down Expand Up @@ -972,6 +979,11 @@ func convertManifest(ctx context.Context, cs content.Store, newDesc *ocispec.Des
// Update the config gc label
manifestLabels[configGCLabelKey] = newConfigDesc.Digest.String()

// Associate a reference to the original OCI manifest.
// See the `subject` field description in
// https://github.com/opencontainers/image-spec/blob/main/manifest.md#image-manifest-property-descriptions
manifest.Subject = &oldDesc

// Update image manifest in content store.
newManifestDesc, err := writeJSON(ctx, cs, manifest, manifestDesc, manifestLabels)
if err != nil {
Expand Down

0 comments on commit 2b7058a

Please sign in to comment.