Skip to content

Commit

Permalink
Merge pull request #558 from jonjohnsonjr/klauspost
Browse files Browse the repository at this point in the history
Avoid using pargzip for compression
  • Loading branch information
mattmoor authored Jul 22, 2023
2 parents 8a6dd3a + dc11745 commit f7590fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ require (
github.com/ijt/goparsify v0.0.0-20221203142333-3a5276334b8d
github.com/imdario/mergo v0.3.16
github.com/joho/godotenv v1.5.1
github.com/klauspost/compress v1.16.7
github.com/klauspost/pgzip v1.2.5
github.com/korovkin/limiter v0.0.0-20221015170604-22eb1ceceddc
github.com/lima-vm/lima v0.16.0
github.com/opencontainers/image-spec v1.1.0-rc4
Expand Down Expand Up @@ -107,8 +109,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/letsencrypt/boulder v0.0.0-20230630152916-bd29cc430fd6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down
26 changes: 23 additions & 3 deletions pkg/build/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
"strings"
"text/template"

"github.com/klauspost/compress/gzip"
"github.com/klauspost/pgzip"

"chainguard.dev/apko/pkg/log"
sign "github.com/chainguard-dev/go-apk/pkg/signature"
"github.com/chainguard-dev/go-apk/pkg/tarball"
Expand Down Expand Up @@ -237,9 +240,14 @@ func (pc *PackageBuild) generateControlSection(ctx context.Context, digest hash.
}

mw := io.MultiWriter(digest, w)
if err := tarctx.WriteTargz(ctx, mw, fsys); err != nil {
zw := gzip.NewWriter(mw)

if err := tarctx.WriteTar(ctx, zw, fsys); err != nil {
return digest, fmt.Errorf("unable to write control tarball: %w", err)
}
if err := zw.Close(); err != nil {
return digest, fmt.Errorf("flushing control section gzip: %w", err)
}

controlHash := hex.EncodeToString(digest.Sum(nil))
pc.Logger.Printf(" control.tar.gz digest: %s", controlHash)
Expand Down Expand Up @@ -635,10 +643,16 @@ func (pc *PackageBuild) emitDataSection(ctx context.Context, fsys fs.FS, w io.Wr

digest := sha256.New()
mw := io.MultiWriter(digest, w)
if err := tarctx.WriteTargz(ctx, mw, fsys); err != nil {
zw := pgzip.NewWriter(mw)

if err := tarctx.WriteTar(ctx, zw, fsys); err != nil {
return fmt.Errorf("unable to write data tarball: %w", err)
}

if err := zw.Close(); err != nil {
return fmt.Errorf("flushing data section gzip: %w", err)
}

pc.DataHash = hex.EncodeToString(digest.Sum(nil))
pc.Logger.Printf(" data.tar.gz digest: %s", pc.DataHash)

Expand Down Expand Up @@ -671,10 +685,16 @@ func (pc *PackageBuild) emitNormalSignatureSection(ctx context.Context, h hash.H
return fmt.Errorf("unable to build signature FS: %w", err)
}

if err := tarctx.WriteTargz(ctx, w, fsys); err != nil {
zw := gzip.NewWriter(w)

if err := tarctx.WriteTar(ctx, zw, fsys); err != nil {
return fmt.Errorf("unable to write signature tarball: %w", err)
}

if err := zw.Close(); err != nil {
return fmt.Errorf("flushing control section gzip: %w", err)
}

if _, err := w.Seek(0, io.SeekStart); err != nil {
return fmt.Errorf("unable to rewind signature tarball: %w", err)
}
Expand Down

0 comments on commit f7590fc

Please sign in to comment.