Skip to content

Commit

Permalink
copy: comput blob compression on reused blobs based on source MediaType
Browse files Browse the repository at this point in the history
When copying blobs, if the source LayerInfo array includes MediaType
information, use it to compute the compression that was used for a
source blob, and if we end up reusing a blob with the same digest, use
that computed information.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed Feb 10, 2021
1 parent 49d6011 commit e019220
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,17 @@ func (ic *imageCopier) copyLayers(ctx context.Context) error {
srcInfosUpdated = true
}

for i := range srcInfos {
if srcInfos[i].CompressionAlgorithm == nil {
switch srcInfos[i].MediaType {
case manifest.DockerV2Schema2LayerMediaType, imgspecv1.MediaTypeImageLayerGzip:
srcInfos[i].CompressionAlgorithm = &compression.Gzip
case imgspecv1.MediaTypeImageLayerZstd:
srcInfos[i].CompressionAlgorithm = &compression.Zstd
}
}
}

type copyLayerData struct {
destInfo types.BlobInfo
diffID digest.Digest
Expand Down Expand Up @@ -1097,6 +1108,11 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to
Artifact: srcInfo,
}
}

if blobInfo.Digest == srcInfo.Digest && blobInfo.CompressionAlgorithm == nil {
blobInfo.CompressionOperation = srcInfo.CompressionOperation
blobInfo.CompressionAlgorithm = srcInfo.CompressionAlgorithm
}
return blobInfo, cachedDiffID, nil
}
}
Expand Down

0 comments on commit e019220

Please sign in to comment.