Skip to content

Rust Example #462

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

Merged
merged 16 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ You can find other examples here:
* [Golang](examples/go/Dockerfile)
* [Node.js](examples/nodejs/Dockerfile)
* [dotnet](examples/dotnet/Dockerfile)
* [Rust](examples/rust/Dockerfile)

To run any example, go the the directory for the language and run
```
Expand Down
26 changes: 26 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ load(

_go_image_repos()

# Rust repositories
http_archive(
name = "io_bazel_rules_rust",
sha256 = "b6da34e057a31b8a85e343c732de4af92a762f804fc36b0baa6c001423a70ebc",
strip_prefix = "rules_rust-55f77017a7f5b08e525ebeab6e11d8896a4499d2",
urls = [
# Master branch as of 2019-10-07
"https://github.com/bazelbuild/rules_rust/archive/55f77017a7f5b08e525ebeab6e11d8896a4499d2.tar.gz",
],
)

http_archive(
name = "bazel_skylib",
sha256 = "9a737999532daca978a158f94e77e9af6a6a169709c0cee274f0a4c3359519bd",
strip_prefix = "bazel-skylib-1.0.0",
url = "https://github.com/bazelbuild/bazel-skylib/archive/1.0.0.tar.gz",
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")

bazel_version(name = "bazel_version")

dpkg_src(
name = "debian10",
arch = "amd64",
Expand Down
15 changes: 15 additions & 0 deletions examples/rust/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Public notice: this file is for internal documentation, testing, and
# reference only. Note that repo maintainers can freely change any part of the
# repository code at any time.
package(default_visibility = ["//visibility:public"])

# Rust
load("@io_bazel_rules_docker//rust:image.bzl", "rust_image")

# NOTE: Bazel Rust rules don't support cross-compilation yet,
# so at this time it's required that you build on the same platform as the image
rust_image(
name = "rust_example",
srcs = ["src/main.rs"],
base = "//cc:cc",
)
5 changes: 5 additions & 0 deletions examples/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "hello-world-distroless"
version = "0.1.0"
authors = ["Bryant Hagadorn <[email protected]>"]

[dependencies]
8 changes: 8 additions & 0 deletions examples/rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM rust:1.41.0 as build-env
WORKDIR /app
ADD . /app
RUN cargo build --release

FROM gcr.io/distroless/cc
COPY --from=build-env /app/target/release/hello-world-distroless /
CMD ["./hello-world-distroless"]
3 changes: 3 additions & 0 deletions examples/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World!");
}