Skip to content

Commit

Permalink
fix(gzip)!: change the default block size (project-stacker#529)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the default gzip block size is changed to 256<<12, was
previously 256<<10.

A tar layer with the same content but compressed with different gzip
blocksize will result in different sha256sums in the final OCI Image.
Ecosystem tools have one current size in use and stacker's current size
differ.

Interactions between a stacker-built OCI image and ecosystem tools which
recompress lower layers results in bloated registries which will have
identical tar content but different compressed sha256 blobs.

Unfortunately, the OCI image spec doesn't standardize/encode this in the
specification document. Hence, we change to the current common block
size used in the ecosystem here in the stacker implementation.

We now link against our own fork: github.com/project-stacker/umoci
which may change depending on the PR getting merged to upstream.

Signed-off-by: Ramkumar Chinchani <[email protected]>
(cherry picked from commit 0cf2d70)
Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Nov 17, 2023
1 parent 5c91928 commit 4f4977a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"time"

"github.com/klauspost/pgzip"
Expand All @@ -29,6 +30,14 @@ import (
"stackerbuild.io/stacker/pkg/types"
)

var tarEx sync.Mutex

// Container image layers are often tar.gz, however there is nothing in the
// spec or documentation which standardizes compression params which can cause
// different layer hashes even for the same tar. So picking compression params
// that most tooling appears to be using.
const gzipBlockSize = mutate.GzipBlockSize(256 << 12)

func safeOverlayName(d digest.Digest) string {
// dirs used in overlay lowerdir args can't have : in them, so lets
// sanitize it
Expand Down Expand Up @@ -418,7 +427,7 @@ func generateLayer(config types.StackerConfig, oci casext.Engine, mutators []*mu
defer blob.Close()

if layerType.Type == "tar" {
desc, err = mutator.Add(context.Background(), mediaType, blob, history, mutate.GzipCompressor, nil)
desc, err = mutator.Add(context.Background(), mediaType, blob, history, mutate.GzipCompressor.WithOpt(gzipBlockSize), nil)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 4f4977a

Please sign in to comment.