Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using pargzip for compression #558

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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