Skip to content

Commit

Permalink
Merge pull request #4275 from ktock/gzip-buildkit-differ
Browse files Browse the repository at this point in the history
diff: gzip with custom level should be compressed by BuildKit's differ
  • Loading branch information
tonistiigi authored Sep 25, 2023
2 parents 0f6482e + e3af4fd commit 5ed1f0b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cache/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
}
}

if desc.Digest == "" && !isTypeWindows(sr) && comp.Type.NeedsComputeDiffBySelf() {
if desc.Digest == "" && !isTypeWindows(sr) && comp.Type.NeedsComputeDiffBySelf(comp) {
// These compression types aren't supported by containerd differ. So try to compute diff on buildkit side.
// This case can be happen on containerd worker + non-overlayfs snapshotter (e.g. native).
// See also: https://github.com/containerd/containerd/issues/4263
Expand Down
2 changes: 1 addition & 1 deletion util/compression/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Type interface {
Compress(ctx context.Context, comp Config) (compressorFunc Compressor, finalize Finalizer)
Decompress(ctx context.Context, cs content.Store, desc ocispecs.Descriptor) (io.ReadCloser, error)
NeedsConversion(ctx context.Context, cs content.Store, desc ocispecs.Descriptor) (bool, error)
NeedsComputeDiffBySelf() bool
NeedsComputeDiffBySelf(comp Config) bool
OnlySupportOCITypes() bool
NeedsForceCompression() bool
MediaType() string
Expand Down
2 changes: 1 addition & 1 deletion util/compression/estargz.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (c estargzType) NeedsConversion(ctx context.Context, cs content.Store, desc
return true, nil
}

func (c estargzType) NeedsComputeDiffBySelf() bool {
func (c estargzType) NeedsComputeDiffBySelf(comp Config) bool {
return true
}

Expand Down
5 changes: 3 additions & 2 deletions util/compression/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func (c gzipType) NeedsConversion(ctx context.Context, cs content.Store, desc oc
return true, nil
}

func (c gzipType) NeedsComputeDiffBySelf() bool {
return false
func (c gzipType) NeedsComputeDiffBySelf(comp Config) bool {
// we allow compressing it with a customized compression level that containerd differ doesn't support so we compress it by self.
return comp.Level != nil
}

func (c gzipType) OnlySupportOCITypes() bool {
Expand Down
2 changes: 1 addition & 1 deletion util/compression/nydus.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c nydusType) NeedsConversion(ctx context.Context, cs content.Store, desc o
return true, nil
}

func (c nydusType) NeedsComputeDiffBySelf() bool {
func (c nydusType) NeedsComputeDiffBySelf(comp Config) bool {
return true
}

Expand Down
2 changes: 1 addition & 1 deletion util/compression/uncompressed.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c uncompressedType) NeedsConversion(ctx context.Context, cs content.Store,
return true, nil
}

func (c uncompressedType) NeedsComputeDiffBySelf() bool {
func (c uncompressedType) NeedsComputeDiffBySelf(comp Config) bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion util/compression/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c zstdType) NeedsConversion(ctx context.Context, cs content.Store, desc oc
return true, nil
}

func (c zstdType) NeedsComputeDiffBySelf() bool {
func (c zstdType) NeedsComputeDiffBySelf(comp Config) bool {
return true
}

Expand Down

0 comments on commit 5ed1f0b

Please sign in to comment.