Skip to content

Commit

Permalink
Merge pull request #517 from PerseidMeteor/feat-remote-cache
Browse files Browse the repository at this point in the history
feat: prevent unnecessary conversions
  • Loading branch information
imeoer authored Aug 18, 2023
2 parents 732d9a6 + bf7032c commit f9cfcf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/converter/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
LayerAnnotationNydusBootstrap = "containerd.io/snapshot/nydus-bootstrap"
LayerAnnotationNydusSourceChainID = "containerd.io/snapshot/nydus-source-chainid"
LayerAnnotationNydusEncryptedBlob = "containerd.io/snapshot/nydus-encrypted-blob"
LayerAnnotationNydusSourceDigest = "containerd.io/snapshot/nydus-source-digest"
LayerAnnotationNydusTargetDigest = "containerd.io/snapshot/nydus-target-digest"

LayerAnnotationNydusReferenceBlobIDs = "containerd.io/snapshot/nydus-reference-blob-ids"

Expand Down
24 changes: 23 additions & 1 deletion pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,28 @@ func LayerConvertFunc(opt PackOption) converter.ConvertFunc {
return nil, nil
}

// Use remote cache to avoid unnecessary conversion
info, err := cs.Info(ctx, desc.Digest)
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", desc.Digest)
}
if info.Labels[LayerAnnotationNydusTargetDigest] != "" {
targetInfo, err := cs.Info(ctx, digest.Digest(info.Labels[LayerAnnotationNydusTargetDigest]))
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", desc.Digest)
}
targetDesc := ocispec.Descriptor{
Digest: targetInfo.Digest,
Size: targetInfo.Size,
MediaType: MediaTypeNydusBlob,
Annotations: map[string]string{
LayerAnnotationUncompressed: targetInfo.Digest.String(),
LayerAnnotationNydusBlob: "true",
},
}
return &targetDesc, nil
}

ra, err := cs.ReaderAt(ctx, desc)
if err != nil {
return nil, errors.Wrap(err, "get source blob reader")
Expand Down Expand Up @@ -825,7 +847,7 @@ func LayerConvertFunc(opt PackOption) converter.ConvertFunc {
}

blobDigest := digester.Digest()
info, err := cs.Info(ctx, blobDigest)
info, err = cs.Info(ctx, blobDigest)
if err != nil {
return nil, errors.Wrapf(err, "get blob info %s", blobDigest)
}
Expand Down

0 comments on commit f9cfcf0

Please sign in to comment.