Skip to content

Commit

Permalink
Build multi-architecture container images
Browse files Browse the repository at this point in the history
This makes it possible to use most of our images on ARM64 based systems.
We still need to spend some time to actually make bb_runner_installer a
multi-architecture image. Maybe the easiest thing is to just rewrite it
in Go, and use //go:embed to embed copies of binaries in there that are
needed for execution.
  • Loading branch information
EdSchouten committed Mar 26, 2024
1 parent 01f19a7 commit 327395d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
65 changes: 41 additions & 24 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ http_archive(
)

http_archive(
name = "io_bazel_rules_docker",
sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
name = "aspect_bazel_lib",
sha256 = "6c25c59581041ede31e117693047f972cc4700c89acf913658dc89d04c338f8d",
strip_prefix = "bazel-lib-2.5.3",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.5.3/bazel-lib-v2.5.3.tar.gz",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "register_expand_template_toolchains")

register_expand_template_toolchains()

http_archive(
name = "rules_oci",
sha256 = "4a276e9566c03491649eef63f27c2816cc222f41ccdebd97d2c5159e84917c3b",
strip_prefix = "rules_oci-1.7.4",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.7.4/rules_oci-v1.7.4.tar.gz",
)

http_archive(
Expand All @@ -37,7 +49,7 @@ http_archive(
],
)

load("@bazel_gazelle//:deps.bzl", "go_repository")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

# Override the version of gomock to one that includes support for
# generating mocks for function types. We can't do this through go.mod,
Expand Down Expand Up @@ -65,31 +77,36 @@ go_rules_dependencies()

go_register_toolchains(version = "1.21.5")

load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")

container_repositories()
gazelle_dependencies()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
load("@rules_oci//oci:pull.bzl", "oci_pull")
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")

container_deps()
oci_register_toolchains(
name = "oci",
crane_version = LATEST_CRANE_VERSION,
)

load("@io_bazel_rules_docker//container:container.bzl", "container_pull")
oci_pull(
name = "distroless_static",
digest = "sha256:7e5c6a2a4ae854242874d36171b31d26e0539c98fc6080f942f16b03e82851ab",
image = "gcr.io/distroless/static",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)

container_pull(
oci_pull(
name = "busybox",
digest = "sha256:a2490cec4484ee6c1068ba3a05f89934010c85242f736280b35343483b2264b6", # 1.31.1-uclibc
registry = "docker.io",
repository = "library/busybox",
image = "docker.io/library/busybox",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@io_bazel_rules_docker//go:image.bzl", _go_image_repos = "repositories")

_go_image_repos()

load("@com_github_bazelbuild_remote_apis//:repository_rules.bzl", "switched_rules_by_language")

switched_rules_by_language(
Expand Down Expand Up @@ -175,9 +192,9 @@ http_archive(

http_archive(
name = "aspect_rules_js",
sha256 = "00e7b97b696af63812df0ca9e9dbd18579f3edd3ab9a56f227238b8405e4051c",
strip_prefix = "rules_js-1.23.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.23.0/rules_js-v1.23.0.tar.gz",
sha256 = "63cf42b07aae34904447c74f5b41652c4933984cc325726673a5e4561d9789e7",
strip_prefix = "rules_js-1.39.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.39.1/rules_js-v1.39.1.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
Expand Down
9 changes: 3 additions & 6 deletions cmd/bb_noop_worker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official", "multiarch_go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
Expand Down Expand Up @@ -30,11 +29,9 @@ go_binary(
visibility = ["//visibility:public"],
)

go_image(
multiarch_go_image(
name = "bb_noop_worker_container",
embed = [":bb_noop_worker_lib"],
pure = "on",
visibility = ["//visibility:public"],
binary = ":bb_noop_worker",
)

container_push_official(
Expand Down
25 changes: 12 additions & 13 deletions cmd/bb_runner/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official")
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_layer")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official", "multiarch_go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

go_library(
name = "bb_runner_lib",
Expand Down Expand Up @@ -35,40 +35,39 @@ go_binary(
visibility = ["//visibility:public"],
)

container_layer(
pkg_tar(
name = "bb_runner_layer",
files = [":bb_runner"],
visibility = ["//visibility:public"],
)

container_layer(
pkg_tar(
name = "tini_layer",
files = ["@com_github_krallin_tini_tini_static_amd64//file"],
)

container_layer(
pkg_tar(
name = "install_layer",
files = ["install"],
)

container_image(
# TODO: Provide a multi-arch image for bb_runner_installer.
oci_image(
name = "bb_runner_installer",
base = "@busybox//image",
base = "@busybox",
cmd = ["/bb"],
entrypoint = ["/install"],
layers = [
tags = [
":install_layer",
":bb_runner_layer",
":tini_layer",
],
visibility = ["//visibility:public"],
)

go_image(
multiarch_go_image(
name = "bb_runner_bare_container",
embed = [":bb_runner_lib"],
pure = "on",
visibility = ["//visibility:public"],
binary = ":bb_runner",
)

container_push_official(
Expand Down
9 changes: 3 additions & 6 deletions cmd/bb_scheduler/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official", "multiarch_go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@npm//:purgecss/package_json.bzl", purgecss_bin = "bin")

Expand Down Expand Up @@ -90,11 +89,9 @@ go_binary(
visibility = ["//visibility:public"],
)

go_image(
multiarch_go_image(
name = "bb_scheduler_container",
embed = [":bb_scheduler_lib"],
pure = "on",
visibility = ["//visibility:public"],
binary = ":bb_scheduler",
)

container_push_official(
Expand Down
9 changes: 3 additions & 6 deletions cmd/bb_worker/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@com_github_buildbarn_bb_storage//tools:container.bzl", "container_push_official", "multiarch_go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
Expand Down Expand Up @@ -74,11 +73,9 @@ go_binary(
visibility = ["//visibility:public"],
)

go_image(
multiarch_go_image(
name = "bb_worker_container",
embed = [":bb_worker_lib"],
pure = "on",
visibility = ["//visibility:public"],
binary = ":bb_worker",
)

container_push_official(
Expand Down

0 comments on commit 327395d

Please sign in to comment.