Skip to content
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

converter: fix image history handle #427

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,12 @@ func convertManifest(ctx context.Context, cs content.Store, oldDesc ocispec.Desc
// This option needs to be enabled for image scenario.
opt.WithTar = true

// If the original image is already an OCI type, we should forcibly set the
// bootstrap layer to the OCI type.
if !opt.OCI && oldDesc.MediaType == ocispec.MediaTypeImageManifest {
opt.OCI = true
}

// Append bootstrap layer to manifest.
bootstrapDesc, blobDescs, err := MergeLayers(ctx, cs, manifest.Layers, opt)
if err != nil {
Expand Down Expand Up @@ -946,15 +952,23 @@ func convertManifest(ctx context.Context, cs content.Store, oldDesc ocispec.Desc
if err != nil {
return nil, errors.Wrap(err, "read image config")
}
bootstrapHistory := ocispec.History{
CreatedBy: "Nydus Converter",
Comment: "Nydus Bootstrap Layer",
}
if opt.Backend != nil {
config.RootFS.DiffIDs = []digest.Digest{digest.Digest(bootstrapDesc.Annotations[LayerAnnotationUncompressed])}
config.History = []ocispec.History{bootstrapHistory}
} else {
config.RootFS.DiffIDs = make([]digest.Digest, 0, len(manifest.Layers))
for i, layer := range manifest.Layers {
config.RootFS.DiffIDs = append(config.RootFS.DiffIDs, digest.Digest(layer.Annotations[LayerAnnotationUncompressed]))
// Remove useless annotation.
delete(manifest.Layers[i].Annotations, LayerAnnotationUncompressed)
}
// Append history item for bootstrap layer, to ensure the history consistency.
// See https://github.com/distribution/distribution/blob/e5d5810851d1f17a5070e9b6f940d8af98ea3c29/manifest/schema1/config_builder.go#L136
config.History = append(config.History, bootstrapHistory)
}
// Update image config in content store.
newConfigDesc, err := writeJSON(ctx, cs, config, manifest.Config, configLabels)
Expand Down Expand Up @@ -1096,11 +1110,15 @@ func MergeLayers(ctx context.Context, cs content.Store, descs []ocispec.Descript
if opt.FsVersion == "" {
opt.FsVersion = "6"
}
mediaType := images.MediaTypeDockerSchema2LayerGzip
if opt.OCI {
mediaType = ocispec.MediaTypeImageLayerGzip
}

bootstrapDesc := ocispec.Descriptor{
Digest: compressedDgst,
Size: bootstrapInfo.Size,
MediaType: ocispec.MediaTypeImageLayerGzip,
MediaType: mediaType,
Annotations: map[string]string{
LayerAnnotationUncompressed: uncompressedDgst.Digest().String(),
LayerAnnotationFSVersion: opt.FsVersion,
Expand Down
2 changes: 2 additions & 0 deletions pkg/converter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ type MergeOption struct {
PrefetchPatterns string
// WithTar puts bootstrap into a tar stream (no gzip).
WithTar bool
// OCI converts docker media types to OCI media types.
OCI bool
// OCIRef enables converting OCI tar(.gz) blob to nydus referenced blob.
OCIRef bool
// Backend uploads blobs generated by nydus-image builder to a backend storage.
Expand Down