Skip to content

Commit

Permalink
copy: add support for ForceCompressionFormat
Browse files Browse the repository at this point in the history
ForceCompressionFormat allows end users to force selected compression format
(set in DestinationCtx.CompressionFormat) which ensures that while copying
blobs of other compression algorithms are not reused.

Following flag is a frontend wrapper for: containers#2023
Will help in:
* containers/buildah#4613
* containers/podman#18660

Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Aug 2, 2023
1 parent df835d5 commit 90d4dd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ type Options struct {
// Invalid when copying a non-multi-architecture image. That will probably
// change in the future.
EnsureCompressionVariantsExist []OptionCompressionVariant

// ForceCompressionFormat allows end users to force selected compression format
// (set in DestinationCtx.CompressionFormat) which ensures that while copying
// blobs of other compression algorithms are not reused.
ForceCompressionFormat bool
}

// OptionCompressionVariant allows to supply information about
Expand Down
10 changes: 10 additions & 0 deletions copy/multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ func (c *copier) copyMultipleImages(ctx context.Context) (copiedManifest []byte,
logrus.Debugf("Copying instance %s (%d/%d)", instance.sourceDigest, i+1, len(instanceCopyList))
c.Printf("Copying image %s (%d/%d)\n", instance.sourceDigest, i+1, len(instanceCopyList))
unparsedInstance := image.UnparsedInstance(c.rawSource, &instanceCopyList[i].sourceDigest)
singleImageOpts := copySingleImageOptions{requireCompressionFormatMatch: false}
if c.options.ForceCompressionFormat {
singleImageOpts.requireCompressionFormatMatch = true
// If CompressionFormat is nil set it to `Gzip` as default,
// since requireCompressionFormatMatch is pretty much `no-op`
// for `nil` CompressionFormat.
if c.options.DestinationCtx.CompressionFormat == nil {
singleImageOpts.compressionFormat: &compression.Gzip
}
}
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, copySingleImageOptions{requireCompressionFormatMatch: false})
if err != nil {
return nil, fmt.Errorf("copying image %d/%d from manifest list: %w", i+1, len(instanceCopyList), err)
Expand Down

0 comments on commit 90d4dd5

Please sign in to comment.