Browse Source

Disable compression for build. More space usage but much faster upload

Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Guillaume J. Charmes 11 năm trước cách đây
mục cha
commit
c6350bcc24
2 tập tin đã thay đổi với 35 bổ sung12 xóa
  1. 2 1
      buildfile.go
  2. 33 11
      utils/tarsum.go

+ 2 - 1
buildfile.go

@@ -604,11 +604,12 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
 	if err != nil {
 		return "", err
 	}
-	b.context = &utils.TarSum{Reader: context}
+	b.context = &utils.TarSum{Reader: context, DisableCompression: true}
 	if err := archive.Untar(b.context, tmpdirPath, nil); err != nil {
 		return "", err
 	}
 	defer os.RemoveAll(tmpdirPath)
+
 	b.contextPath = tmpdirPath
 	filename := path.Join(tmpdirPath, "Dockerfile")
 	if _, err := os.Stat(filename); os.IsNotExist(err) {

+ 33 - 11
utils/tarsum.go

@@ -15,16 +15,34 @@ import (
 
 type TarSum struct {
 	io.Reader
-	tarR        *tar.Reader
-	tarW        *tar.Writer
-	gz          *gzip.Writer
-	bufTar      *bytes.Buffer
-	bufGz       *bytes.Buffer
-	h           hash.Hash
-	sums        map[string]string
-	currentFile string
-	finished    bool
-	first       bool
+	tarR               *tar.Reader
+	tarW               *tar.Writer
+	gz                 writeCloseFlusher
+	bufTar             *bytes.Buffer
+	bufGz              *bytes.Buffer
+	h                  hash.Hash
+	sums               map[string]string
+	currentFile        string
+	finished           bool
+	first              bool
+	DisableCompression bool
+}
+
+type writeCloseFlusher interface {
+	io.WriteCloser
+	Flush() error
+}
+
+type nopCloseFlusher struct {
+	io.Writer
+}
+
+func (n *nopCloseFlusher) Close() error {
+	return nil
+}
+
+func (n *nopCloseFlusher) Flush() error {
+	return nil
 }
 
 func (ts *TarSum) encodeHeader(h *tar.Header) error {
@@ -57,7 +75,11 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
 		ts.bufGz = bytes.NewBuffer([]byte{})
 		ts.tarR = tar.NewReader(ts.Reader)
 		ts.tarW = tar.NewWriter(ts.bufTar)
-		ts.gz = gzip.NewWriter(ts.bufGz)
+		if !ts.DisableCompression {
+			ts.gz = gzip.NewWriter(ts.bufGz)
+		} else {
+			ts.gz = &nopCloseFlusher{Writer: ts.bufGz}
+		}
 		ts.h = sha256.New()
 		ts.h.Reset()
 		ts.first = true