-
Notifications
You must be signed in to change notification settings - Fork 694
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
For gzip operations, use a new Go helper by default instead of which(gzip) #1613
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3d1313f
For gzip operations, use a Go helper by default rather than the gzip …
faube c15777a
Update some test digests.
faube 1da202a
Run buildifier.
faube 88f50bb
gazelle() calls are unnecessary.
faube 365fec3
Use io.Copy to avoid loading the entire file into memory.
faube 8c4f01e
Merge gzip() and gunzip() since they have more in common than not.
faube 36a9d4e
Minor documentation fixes.
faube a215030
Make arguments more explicit.
faube a516a69
Merge branch 'master' into zipper
smukherj1 4f0e320
Fix a lint warning with the function docstring
faube afd723b
Merge branch 'zipper' of github.com:faube/rules_docker into zipper
faube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2020 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ### | ||
# Build file for zipper binary. | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_binary( | ||
name = "zipper", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["zipper.go"], | ||
importpath = "github.com/bazelbuild/rules_docker", | ||
visibility = ["//visibility:private"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2020 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//////////////////////////////////////////////// | ||
// This package performs gzip operations. | ||
|
||
package main | ||
|
||
import ( | ||
"compress/gzip" | ||
"flag" | ||
"io" | ||
"log" | ||
"os" | ||
) | ||
|
||
var ( | ||
src = flag.String("src", "", "The source location of the file to zip/unzip.") | ||
dst = flag.String("dst", "", "The destination location of the file, after zip/unzip.") | ||
decompress = flag.Bool("decompress", false, "If true, perform gunzip. If false, gzip.") | ||
fast = flag.Bool("fast", false, "If true, use the fastest compression level.") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *src == "" { | ||
log.Fatalln("Required option -src was not specified.") | ||
} | ||
|
||
if *dst == "" { | ||
log.Fatalln("Required option -dst was not specified.") | ||
} | ||
|
||
var copy_from io.Reader | ||
var copy_to io.Writer | ||
|
||
f, err := os.Open(*src) | ||
if err != nil { | ||
log.Fatalf("Unable to read input file: %v", err) | ||
} | ||
t, err := os.Create(*dst) | ||
if err != nil { | ||
log.Fatalf("Unable to create output file: %v", err) | ||
} | ||
|
||
if *decompress { | ||
zr, err := gzip.NewReader(f) | ||
if err != nil { | ||
log.Fatalf("Unable to read: %v", err) | ||
} | ||
defer func() { | ||
if err := zr.Close(); err != nil { | ||
log.Fatalf("Unable to close gzip reader: %v", err) | ||
} | ||
}() | ||
copy_from = zr | ||
copy_to = t | ||
} else { | ||
level := gzip.DefaultCompression | ||
if *fast { | ||
level = gzip.BestSpeed | ||
} | ||
zw, err := gzip.NewWriterLevel(t, level) | ||
if err != nil { | ||
log.Fatalf("Unable to create gzip writer: %v", err) | ||
} | ||
defer func() { | ||
if err := zw.Close(); err != nil { | ||
log.Fatalf("Unable to close gzip writer: %v", err) | ||
} | ||
}() | ||
copy_from = f | ||
copy_to = zw | ||
} | ||
if _, err := io.Copy(copy_to, copy_from); err != nil { | ||
log.Fatalf("Unable to perform the gzip operation from %q to %q: %v", *src, *dst, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm curious why the digest changed given we're still using gzip in the Go tool. Are we specifying a different compression level than before? In any case, I expect you'll need to update a bunch of digests here (https://github.com/bazelbuild/rules_docker/blob/master/container/image_test.py) as well in case we can't get the digests to match.
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 tried digging into this a little. None of the compression levels in compress/gzip produce a digest that matches the gzip tool. There may be subtle differences in how gzip and compress/gzip package the header or something?
//container/image_test.py passes; I suspect it's because we never verify the digest of gzipped files, only manifests.
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.
SGTM. Thanks for looking into it.
This is weird. I believe manifest transitively includes the digests the compressed layers. I don't remember if the manifest contents directly list the layer digests or the manifest which includes the digest of the image config which in turn includes the digests of the compressed layers. Note that some images only include uncompressed layers. However, I think most of our images include compressed layers. I'm a little worried that the current implementation isn't actually calling the Go tool to compress the layers for the images used by this test which may be undesirable for your use case :)
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.
Please see comment below: #1613 (comment)