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
Compress layers on push to a v2 registry #11869
Conversation
LGTM @jfrazelle Thanks for adding this to the 1.6.0 milestone! It is going to be very important for the release as it significantly reduces payload sizes which in turn reduces registry storage usage and bandwidth requirements. Smaller downloads == Faster downloads == Happier users 👍 |
ping @crosbymichael this is enhancements to make things faster if its On Fri, Mar 27, 2015 at 2:03 PM, Josh Hawn notifications@github.com wrote:
|
w = gzip.NewWriter(w) | ||
} | ||
_, err := io.Copy(w, src) | ||
if wc, ok := w.(io.Closer); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this works, you need to close the underlying file and reset the hash manually. you cannot cast the multiwriter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, i see that is going on now, if it's a gzip.Writer then the hash will not be populated, is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry it is kind of confusing. Yes it is only for closing the gzip writer, the multiwriter does not need to be closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's confusing; perhaps some docs describing the function to prevent future coders tripping over it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can be more explicit with the code:
func bufferToFile(f *os.File, src io.Reader, compress bool) (int64, digest.Digest, error) {
var (
d = digest.NewCanonicalDigester() // Uses sha256.
w = io.MultiWriter(f, &d)
gz *gzip.Writer
)
if compress {
gz = gzip.NewWriter(w)
w = gz
}
_, err := io.Copy(w, src)
if gz != nil {
gz.Close()
}
if err != nil {
return 0, "", err
}
n, err := f.Seek(0, os.SEEK_CUR)
if err != nil {
return 0, "", err
}
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return 0, "", err
}
return n, d.Digest(), nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment as @thaJeztah suggested, should be all that is required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
e9a9a08
to
1692937
Compare
Updated to make code easier to read based on @jlhawn's recommendation |
Thanks for the readability changes. I'm getting rusty and cannot read code anymore. |
@dmcgowan I was talking to @crosbymichael and @NathanMcCauley IRL about this PR and we agreed that if |
@dmcgowan can you remove that bool? |
1692937
to
82c1581
Compare
Updated |
LGTM |
@jlhawn that LGTM is not parse-able |
@dmcgowan Could you rebase against master and fix compilation errors? |
When buffering to file add support for compressing the tar contents. Since digest should be computed while writing buffer, include digest creation during buffer. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
82c1581
to
851c647
Compare
LGTM |
Compress layers on push to a v2 registry
When buffering to file add support for compressing the tar contents. Since digest should be computed while writing buffer, include digest creation during buffer.
Pull auto detects compression requiring no additional changes.
Ping @jlhawn