Skip to content

Commit c1688d0

Browse files
committed
switch to rules_img and add image amd64/v3 variant
1 parent faf8fe6 commit c1688d0

File tree

4 files changed

+47
-249
lines changed

4 files changed

+47
-249
lines changed

MODULE.bazel

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ bazel_dep(name = "platforms", version = "1.0.0")
1313
bazel_dep(name = "protobuf", version = "33.0")
1414
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
1515
bazel_dep(name = "rules_go", version = "0.58.3")
16+
bazel_dep(name = "rules_img", version = "0.2.9")
1617
bazel_dep(name = "rules_jsonnet", version = "0.7.2")
1718
bazel_dep(name = "rules_nodejs", version = "6.6.0")
18-
bazel_dep(name = "rules_oci", version = "2.2.6")
19-
bazel_dep(name = "rules_pkg", version = "1.1.0")
2019
bazel_dep(name = "rules_proto", version = "7.1.0")
2120
bazel_dep(name = "rules_shell", version = "0.6.1")
2221
bazel_dep(name = "toolchains_llvm", version = "1.5.0")
@@ -154,19 +153,10 @@ npm.npm_translate_lock(
154153
)
155154
use_repo(npm, "com_github_buildbarn_bb_storage_npm")
156155

157-
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
158-
oci.pull(
156+
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
157+
pull(
159158
name = "distroless_static",
160159
digest = "sha256:3f2b64ef97bd285e36132c684e6b2ae8f2723293d09aae046196cca64251acac",
161-
image = "gcr.io/distroless/static",
162-
platforms = [
163-
"linux/amd64",
164-
"linux/arm64/v8",
165-
],
166-
)
167-
use_repo(
168-
oci,
169-
"distroless_static",
170-
"distroless_static_linux_amd64",
171-
"distroless_static_linux_arm64_v8",
160+
registry = "gcr.io",
161+
repository = "distroless/static",
172162
)

MODULE.bazel.lock

Lines changed: 3 additions & 209 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/container.bzl

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,49 @@
1-
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push")
2-
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
1+
load("@rules_img//img:layer.bzl", "image_layer")
2+
load("@rules_img//img:image.bzl", "image_manifest", "image_index")
3+
load("@rules_img//img:push.bzl", "image_push")
34

45
def multiarch_go_image(name, binary):
56
"""Create a container image with two variants of the given go_binary target.
67
78
Args:
8-
name: resulting oci_image_index target
9+
name: resulting image_index target
910
binary: label of a go_binary target; it may be transitioned to another architecture
1011
"""
1112

1213
tar_target = "_{}.tar".format(name)
1314
image_target = "_{}.image".format(name)
1415

15-
pkg_tar(
16+
image_layer(
1617
name = tar_target,
17-
srcs = [binary],
18-
include_runfiles = True,
19-
package_dir = "app",
20-
extension = "tar.gz",
18+
srcs = {"app/{}".format(native.package_relative_label(binary).name): binary},
2119
)
2220

23-
oci_image(
21+
image_manifest(
2422
name = image_target,
2523
base = Label("@distroless_static"),
2624
entrypoint = ["/app/{}".format(native.package_relative_label(binary).name)],
27-
tars = [tar_target],
25+
layers = [tar_target],
2826
# Don't build un-transitioned images, as the default target architecture might be unsupported
2927
# For example when building on linux-i386.
3028
tags = ["manual"],
3129
)
3230

33-
oci_image_index(
31+
image_index(
3432
name = name,
35-
images = [image_target],
33+
manifests = [image_target],
3634
platforms = [
37-
"@rules_go//go/toolchain:linux_amd64",
38-
"@rules_go//go/toolchain:linux_arm64",
35+
"//tools/platforms:linux_amd64",
36+
"//tools/platforms:linux_amd64_v3",
37+
"//tools/platforms:linux_arm64",
3938
],
4039
visibility = ["//visibility:public"],
41-
target_compatible_with = select({
42-
Label("@platforms//os:windows"): [Label("@platforms//:incompatible")],
43-
"//conditions:default": [],
44-
}),
4540
)
4641

4742
def container_push_official(name, image, component):
48-
oci_push(
43+
image_push(
4944
name = name,
5045
image = image,
51-
repository = "ghcr.io/buildbarn/" + component,
52-
remote_tags = "@com_github_buildbarn_bb_storage//tools:stamped_tags",
53-
target_compatible_with = select({
54-
Label("@platforms//os:windows"): [Label("@platforms//:incompatible")],
55-
"//conditions:default": [],
56-
}),
46+
registry = "ghcr.io",
47+
repository = "buildbarn/" + component,
48+
tag_file = "@com_github_buildbarn_bb_storage//tools:stamped_tags",
5749
)

tools/platforms/BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package(
2+
default_visibility = ["//visibility:public"],
3+
)
4+
5+
alias(
6+
name = "linux_amd64",
7+
actual = "@rules_go//go/toolchain:linux_amd64",
8+
)
9+
10+
platform(
11+
name = "linux_amd64_v3",
12+
constraint_values = [
13+
"@rules_go//go/constraints/amd64:v3",
14+
"@rules_img//img/constraints/amd64:v3",
15+
],
16+
parents = ["@rules_go//go/toolchain:linux_amd64"],
17+
)
18+
19+
alias(
20+
name = "linux_arm64",
21+
actual = "@rules_go//go/toolchain:linux_arm64",
22+
)

0 commit comments

Comments
 (0)