1
0
mirror of https://github.com/ko-build/ko.git synced 2024-12-12 08:54:09 +02:00

Compress layers when we Build them (#47)

This avoids double-compressing later.
This commit is contained in:
jonjohnsonjr 2019-06-25 16:30:25 -07:00 committed by Matt Moore
parent f46a2b6372
commit b7d1820e13

View File

@ -17,6 +17,7 @@ package build
import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
gb "go/build"
"io"
@ -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
@ -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)