Skip to content

Commit

Permalink
Merge pull request #11869 from dmcgowan/v2-push-gzipped
Browse files Browse the repository at this point in the history
Compress layers on push to a v2 registry
  • Loading branch information
crosbymichael committed Mar 30, 2015
2 parents f3a0485 + 851c647 commit 72dfd67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 18 additions & 6 deletions graph/graph.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package graph

import (
"compress/gzip"
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
Expand All @@ -13,6 +15,7 @@ import (
"time"

"github.com/Sirupsen/logrus"
"github.com/docker/distribution/digest"
"github.com/docker/docker/autogen/dockerversion"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/image"
Expand Down Expand Up @@ -242,18 +245,27 @@ func (graph *Graph) newTempFile() (*os.File, error) {
return ioutil.TempFile(tmp, "")
}

func bufferToFile(f *os.File, src io.Reader) (int64, error) {
n, err := io.Copy(f, src)
func bufferToFile(f *os.File, src io.Reader) (int64, digest.Digest, error) {
var (
h = sha256.New()
w = gzip.NewWriter(io.MultiWriter(f, h))
)
_, err := io.Copy(w, src)
w.Close()
if err != nil {
return n, err
return 0, "", err
}
if err = f.Sync(); err != nil {
return n, err
return 0, "", err
}
n, err := f.Seek(0, os.SEEK_CUR)
if err != nil {
return 0, "", err
}
if _, err := f.Seek(0, 0); err != nil {
return n, err
return 0, "", err
}
return n, nil
return n, digest.NewDigest("sha256", h), nil
}

// setupInitLayer populates a directory with mountpoints suitable
Expand Down
9 changes: 1 addition & 8 deletions graph/push.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package graph

import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
Expand All @@ -13,7 +12,6 @@ import (
"sync"

"github.com/Sirupsen/logrus"
"github.com/docker/distribution/digest"
"github.com/docker/docker/engine"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/progressreader"
Expand Down Expand Up @@ -465,12 +463,7 @@ func (s *TagStore) pushV2Image(r *registry.Session, img *image.Image, endpoint *
os.Remove(tf.Name())
}()

h := sha256.New()
size, err := bufferToFile(tf, io.TeeReader(arch, h))
if err != nil {
return "", err
}
dgst := digest.NewDigest("sha256", h)
size, dgst, err := bufferToFile(tf, arch)

// Send the layer
logrus.Debugf("rendered layer for %s of [%d] size", img.ID, size)
Expand Down

0 comments on commit 72dfd67

Please sign in to comment.