-
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
remove dependency on external python for sha256 #1993
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
# Build file for sha256 binary. | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["sha256.go"], | ||
importpath = "github.com/bazelbuild/rules_docker/container/go/cmd/sha256", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
go_binary( | ||
name = "sha256", | ||
embed = [":go_default_library"], | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Portable SHA256 tool. | ||
package main | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"flag" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
if len(os.Args) != 3 { | ||
log.Fatalf("Usage: %s input output", os.Args[0]) | ||
} | ||
|
||
inputfile, err := os.Open(os.Args[1]) | ||
if err != nil { | ||
log.Fatalf("error reading %s: %s", os.Args[1], err) | ||
} | ||
|
||
h := sha256.New() | ||
if _, err := io.Copy(h, inputfile); err != nil { | ||
log.Fatalf("error reading %s: %s", os.Args[1], err) | ||
} | ||
|
||
if err := inputfile.Close(); err != nil { | ||
log.Fatalf("error reading %s: %s", os.Args[1], err) | ||
} | ||
sum := h.Sum(nil) | ||
hexSum := hex.EncodeToString(sum) | ||
|
||
if err := ioutil.WriteFile(os.Args[2], []byte(hexSum), 0666); err != nil { | ||
log.Fatalf("error writing %s: %s", os.Args[2], err) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ A rule that imports a docker image into our intermediate form. | |
| <a id="container_import-layers"></a>layers | The list of layer .tar.gz files in the order they appear in the config.json's layer section, or in the order that they appear in the <code>Layers</code> field of the docker save tarballs' <code>manifest.json</code> (these may or may not be gzipped).<br><br> Note that the layers should each have a different basename. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | required | | | ||
| <a id="container_import-manifest"></a>manifest | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | | ||
| <a id="container_import-repository"></a>repository | - | String | optional | "bazel" | | ||
| <a id="container_import-sha256"></a>sha256 | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //tools/build_defs/hash:sha256 | | ||
| <a id="container_import-sha256"></a>sha256 | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //container/go/cmd/sha256:sha256 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. funny how the old doc here was wrong since it didn't include the repository name |
||
|
||
|
||
<a id="#container_layer"></a> | ||
|
@@ -126,7 +126,7 @@ A rule that assembles data into a tarball which can be use as in layers attr in | |
| <a id="container_layer-mtime"></a>mtime | - | Integer | optional | -1 | | ||
| <a id="container_layer-operating_system"></a>operating_system | - | String | optional | "linux" | | ||
| <a id="container_layer-portable_mtime"></a>portable_mtime | - | Boolean | optional | False | | ||
| <a id="container_layer-sha256"></a>sha256 | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //tools/build_defs/hash:sha256 | | ||
| <a id="container_layer-sha256"></a>sha256 | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //container/go/cmd/sha256:sha256 | | ||
| <a id="container_layer-symlinks"></a>symlinks | Symlinks to create in the Docker image.<br><br> For example,<br><br> symlinks = { "/path/to/link": "/path/to/target", ... }, | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} | | ||
| <a id="container_layer-tars"></a>tars | Tar file to extract in the layer.<br><br> A list of tar files whose content should be in the Docker image. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,8 @@ bzl_library( | |
name = "zip", | ||
srcs = ["zip.bzl"], | ||
) | ||
|
||
bzl_library( | ||
name = "hash", | ||
srcs = ["hash.bzl"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Functions for producing the hash of an artifact.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add a comment here pointing to the upstream hash.bzl in bazel_tools and explain why we forked it? that way we have a chance of comparing this against future changes to that one. |
||
|
||
def sha256(ctx, artifact, execution_requirements = None): | ||
"""Create an action to compute the SHA-256 of an artifact.""" | ||
out = ctx.actions.declare_file(artifact.basename + ".sha256") | ||
ctx.actions.run( | ||
executable = ctx.executable.sha256, | ||
arguments = [artifact.path, out.path], | ||
inputs = [artifact], | ||
outputs = [out], | ||
mnemonic = "SHA256", | ||
execution_requirements = execution_requirements, | ||
) | ||
return out | ||
|
||
tools = { | ||
"sha256": attr.label( | ||
default = Label("//container/go/cmd/sha256:sha256"), | ||
cfg = "host", | ||
executable = True, | ||
allow_files = True, | ||
), | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for pointing to that, it's a strange API shape in this file, but I think it's clever how you made it a drop-in replacement. |
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 include a comment here about the sha256.py you mentioned below so we have a chance of finding it later.