-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathBUILD.bazel
95 lines (86 loc) · 2.13 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push")
# OCI Container Rules
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc", "rust_doc_test")
# Custom macro
load("//:build/container.bzl", "build_sha265_tag")
# Build binary
rust_binary(
name = "bin",
srcs = glob([
"src/*/*.rs",
"src/*.rs",
]),
crate_root = "src/main.rs",
rustc_flags = select({
"//:release": [
"-Clink-arg=-flto",
"-Ccodegen-units=1",
"-Cpanic=abort",
"-Copt-level=3",
"-Cstrip=symbols",
],
"//conditions:default": [
"-Copt-level=0",
],
}),
tags = [
"rest-tokio",
"service",
],
visibility = ["//visibility:public"],
deps = [
# External crates
"@crates//:arc-swap",
"@crates//:serde",
"@crates//:serde_json",
"@crates//:tokio",
"@crates//:tokio-cron-scheduler",
"@crates//:warp",
],
)
# Build documentation
rust_doc(
name = "doc",
crate = ":bin",
tags = ["doc"],
visibility = ["//visibility:public"],
)
# Test documentation
rust_doc_test(
name = "doc_test",
crate = ":bin",
tags = ["doc-test"],
visibility = ["//visibility:public"],
)
# 1) Compress the Rust binary to tar
pkg_tar(
name = "tar",
srcs = [":bin"],
)
# 2) Build container image
# https://github.com/bazel-contrib/rules_oci/blob/main/docs/image.md
oci_image(
name = "image",
base = "@distroless",
entrypoint = ["/bin"],
exposed_ports = ["4242"],
tars = [":tar"],
visibility = ["//visibility:public"],
)
# 3) Build an unique and immutable image tag
build_sha265_tag(
name = "remote_tag",
image = ":image",
input = "image.json.sha256",
output = "_tag.txt",
)
# 4) Define a registry to publish the image
# https://github.com/bazel-contrib/rules_oci/blob/main/docs/push.md)
oci_push(
name = "push",
image = ":image",
remote_tags = ":remote_tag",
repository = "my.registry.com/rest-tokio",
visibility = ["//visibility:public"],
)