forked from buchgr/bazel-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.bazel
205 lines (187 loc) · 6.11 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
gazelle(
name = "gazelle",
prefix = "github.com/buchgr/bazel-remote/v2",
)
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/buchgr/bazel-remote/v2",
visibility = ["//visibility:private"],
deps = [
"//cache/disk:go_default_library",
"//config:go_default_library",
"//server:go_default_library",
"//utils/flags:go_default_library",
"//utils/idle:go_default_library",
"//utils/rlimit:go_default_library",
"@com_github_abbot_go_http_auth//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promhttp:go_default_library",
"@com_github_slok_go_http_metrics//metrics/prometheus:go_default_library",
"@com_github_slok_go_http_metrics//middleware:go_default_library",
"@com_github_slok_go_http_metrics//middleware/std:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
"@org_golang_x_sync//semaphore:go_default_library",
],
)
go_binary(
name = "bazel-remote",
cgo = True,
embed = [":go_default_library"],
pure = "off",
static = "off",
visibility = ["//visibility:public"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
go_binary(
name = "bazel-remote-linux-amd64",
cgo = True,
embed = [":go_default_library"],
goarch = "amd64",
goos = "linux",
pure = "off",
static = "off",
visibility = ["//visibility:public"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
go_binary(
name = "bazel-remote-linux-arm64",
cgo = True,
embed = [":go_default_library"],
goarch = "arm64",
goos = "linux",
pure = "off",
static = "on",
visibility = ["//visibility:public"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
go_binary(
name = "bazel-remote-darwin-amd64",
cgo = True,
embed = [":go_default_library"],
goarch = "amd64",
goos = "darwin",
pure = "off",
#static = "on", # With static enabled, I get the following error: "ld: library not found for -lcrt0.o"
visibility = ["//visibility:public"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
go_binary(
name = "bazel-remote-darwin-arm64",
cgo = True,
embed = [":go_default_library"],
goarch = "arm64",
goos = "darwin",
pure = "off",
#static = "on", # With static enabled, I get the following error: "ld: library not found for -lcrt0.o"
visibility = ["//visibility:public"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
# The distroless static container image's nonroot user id.
BAZEL_REMOTE_USER_ID = 65532
go_image(
name = "bazel-remote-base",
base = "@cgo_amd64_base//image", # Does not include openssl.
cgo = True,
embed = [":go_default_library"],
goarch = "amd64",
goos = "linux",
pure = "off",
static = "on",
visibility = ["//visibility:private"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
go_image(
name = "bazel-remote-base-arm64",
base = "@cgo_arm64_base//image", # Does not include openssl.
cgo = True,
embed = [":go_default_library"],
goarch = "arm64",
goos = "linux",
pure = "off",
static = "on",
visibility = ["//visibility:private"],
x_defs = {"main.gitCommit": "{STABLE_GIT_COMMIT}"},
)
container_image(
name = "bazel-remote-image",
architecture = "amd64",
base = ":bazel-remote-base",
entrypoint = [
"/app/bazel-remote-base.binary",
"--http_address=:8080",
"--dir=/data",
# Listen on all addresses, not just 127.0.0.1, so this can
# be reached from outside the container (with a -p mapping).
# Specify a port to enable the profiling http server.
"--profile_address=:6060",
],
ports = ["8080"],
tars = [
"//docker:data_dir_tar",
],
user = str(BAZEL_REMOTE_USER_ID),
visibility = ["//visibility:public"],
)
container_image(
name = "bazel-remote-image-arm64",
architecture = "arm64",
base = ":bazel-remote-base-arm64",
entrypoint = [
"/app/bazel-remote-base-arm64.binary",
"--http_address=:8080",
"--dir=/data",
# Listen on all addresses, not just 127.0.0.1, so this can
# be reached from outside the container (with a -p mapping).
# Specify a port to enable the profiling http server.
"--profile_address=:6060",
],
ports = ["8080"],
tars = [
"//docker:data_dir_tar",
],
user = str(BAZEL_REMOTE_USER_ID),
visibility = ["//visibility:public"],
)
# The following container_push targets push to "tmp-amd64" and "tmp-arm64"
# tags, so they can be combined into a multiarch tag on dockerhub. This
# isn't currently possible with rules_docker, so instead we rely on some
# external commands to be run after the tmp-* tags are pushed. See the
# docker/push_to_dockerhub script.
#
# Background:
# https://github.com/bazelbuild/rules_docker/issues/1599
container_push(
name = "push_to_dockerhub_amd64",
format = "Docker",
image = ":bazel-remote-image",
registry = "index.docker.io",
repository = "buchgr/bazel-remote-cache",
tag = "tmp-amd64",
visibility = ["//visibility:public"],
)
container_push(
name = "push_to_dockerhub_arm64",
format = "Docker",
image = ":bazel-remote-image-arm64",
registry = "index.docker.io",
repository = "buchgr/bazel-remote-cache",
tag = "tmp-arm64",
visibility = ["//visibility:public"],
)