Skip to content

Commit

Permalink
Compress layers when we Build them (ko-build#47)
Browse files Browse the repository at this point in the history
This avoids double-compressing later.
  • Loading branch information
jonjohnsonjr authored and mattmoor committed Jun 25, 2019
1 parent f46a2b6 commit b7d1820
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/build/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package build
import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
gb "go/build"
"io"
Expand Down Expand Up @@ -170,7 +171,14 @@ func tarAddDirectories(tw *tar.Writer, dir string) error {

func tarBinary(name, binary string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
tw := tar.NewWriter(buf)
// Compress this before calling tarball.LayerFromOpener, since it eagerly
// calculates digests and diffids. This prevents us from double compressing
// the layer when we have to actually upload the blob.
//
// https://github.com/google/go-containerregistry/issues/413
gw, _ := gzip.NewWriterLevel(buf, gzip.BestSpeed)
defer gw.Close()
tw := tar.NewWriter(gw)
defer tw.Close()

// write the parent directories to the tarball archive
Expand Down Expand Up @@ -221,7 +229,14 @@ const kodataRoot = "/var/run/ko"

func tarKoData(importpath string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
tw := tar.NewWriter(buf)
// Compress this before calling tarball.LayerFromOpener, since it eagerly
// calculates digests and diffids. This prevents us from double compressing
// the layer when we have to actually upload the blob.
//
// https://github.com/google/go-containerregistry/issues/413
gw, _ := gzip.NewWriterLevel(buf, gzip.BestSpeed)
defer gw.Close()
tw := tar.NewWriter(gw)
defer tw.Close()

root, err := kodataPath(importpath)
Expand Down

0 comments on commit b7d1820

Please sign in to comment.