Skip to content
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

Build multi-architecture container images #129

Merged
merged 4 commits into from
Mar 27, 2024
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 .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
8 changes: 4 additions & 4 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"build_and_test": {
"runs-on": "ubuntu-latest",
"steps": [
{
"name": "Installing Bazel",
"run": "curl -L https://github.com/bazelbuild/bazel/releases/download/6.0.0/bazel-6.0.0-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
},
{
"name": "Check out source code",
"uses": "actions/checkout@v1"
},
{
"name": "Installing Bazel",
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
},
{
"name": "Gazelle",
"run": "bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro go_dependencies.bzl%go_dependencies -prune && bazel run //:gazelle"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pull-requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"build_and_test": {
"runs-on": "ubuntu-latest",
"steps": [
{
"name": "Installing Bazel",
"run": "curl -L https://github.com/bazelbuild/bazel/releases/download/6.0.0/bazel-6.0.0-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
},
{
"name": "Check out source code",
"uses": "actions/checkout@v1"
},
{
"name": "Installing Bazel",
"run": "v=$(cat .bazelversion) && curl -L https://github.com/bazelbuild/bazel/releases/download/${v}/bazel-${v}-linux-x86_64 > ~/bazel && chmod +x ~/bazel && echo ~ >> ${GITHUB_PATH}"
},
{
"name": "Gazelle",
"run": "bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro go_dependencies.bzl%go_dependencies -prune && bazel run //:gazelle"
Expand Down
79 changes: 52 additions & 27 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",
digest = "sha256:97e3873d1f61ba651b632e4755fc52e1d90c9f6e4f01d9b720f37af5efed17e5", # 1.36.1-uclibc
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 @@ -127,8 +144,16 @@ http_file(
name = "com_github_krallin_tini_tini_static_amd64",
downloaded_file_path = "tini",
executable = True,
sha256 = "eadb9d6e2dc960655481d78a92d2c8bc021861045987ccd3e27c7eae5af0cf33",
urls = ["https://github.com/krallin/tini/releases/download/v0.18.0/tini-static-amd64"],
sha256 = "c5b0666b4cb676901f90dfcb37106783c5fe2077b04590973b885950611b30ee",
urls = ["https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-amd64"],
)

http_file(
name = "com_github_krallin_tini_tini_static_arm64",
downloaded_file_path = "tini",
executable = True,
sha256 = "eae1d3aa50c48fb23b8cbdf4e369d0910dfc538566bfd09df89a774aa84a48b9",
urls = ["https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64"],
)

http_archive(
Expand Down Expand Up @@ -175,9 +200,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
76 changes: 53 additions & 23 deletions cmd/bb_runner/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
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", "oci_image_index")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

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

container_layer(
multiarch_go_image(
name = "bb_runner_bare_container",
binary = ":bb_runner",
)

container_push_official(
name = "bb_runner_bare_container_push",
component = "bb-runner-bare",
image = ":bb_runner_bare_container",
)

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"],
files = select({
"@io_bazel_rules_go//go/platform:amd64": [
"@com_github_krallin_tini_tini_static_amd64//file",
],
"@io_bazel_rules_go//go/platform:arm64": [
"@com_github_krallin_tini_tini_static_arm64//file",
],
}),
tags = ["manual"],
)

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

container_image(
name = "bb_runner_installer",
base = "@busybox//image",
oci_image(
name = "bb_runner_installer_image",
base = "@busybox",
cmd = ["/bb"],
entrypoint = ["/install"],
layers = [
tags = ["manual"],
tars = [
":install_layer",
":bb_runner_layer",
":tini_layer",
],
visibility = ["//visibility:public"],
)

go_image(
name = "bb_runner_bare_container",
embed = [":bb_runner_lib"],
pure = "on",
visibility = ["//visibility:public"],
)
[
platform_transition_filegroup(
name = "bb_runner_installer_image_" + arch,
srcs = ["bb_runner_installer_image"],
target_platform = "@io_bazel_rules_go//go/toolchain:linux_" + arch,
)
for arch in [
"amd64",
"arm64",
]
]

container_push_official(
name = "bb_runner_bare_container_push",
component = "bb-runner-bare",
image = ":bb_runner_bare_container",
oci_image_index(
name = "bb_runner_installer_container",
images = [
"bb_runner_installer_image_" + arch
for arch in [
"amd64",
"arm64",
]
],
)

container_push_official(
name = "bb_runner_installer_container_push",
component = "bb-runner-installer",
image = ":bb_runner_installer",
image = ":bb_runner_installer_container",
)
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/grpc-ecosystem/g
require (
cloud.google.com/go/longrunning v0.5.5
github.com/bazelbuild/remote-apis v0.0.0-20240215191509-9ff14cecffe5
github.com/buildbarn/bb-storage v0.0.0-20240310075825-20598f43e294
github.com/buildbarn/bb-storage v0.0.0-20240326045855-53c12526d34e
github.com/buildbarn/go-xdr v0.0.0-20231115101217-a9e2aa4cf64b
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/buildbarn/bb-storage v0.0.0-20240308085957-e8fd6935d2ef h1:4Mq41hEzT6
github.com/buildbarn/bb-storage v0.0.0-20240308085957-e8fd6935d2ef/go.mod h1:0uISGKJD6Owt29w2sUlK0TeLtYdLWtBiC43yVHdgMAY=
github.com/buildbarn/bb-storage v0.0.0-20240310075825-20598f43e294 h1:Gs3nP150dcZ7Utk7OrYPpoV9/7oGZ9y1It0BGPonDnk=
github.com/buildbarn/bb-storage v0.0.0-20240310075825-20598f43e294/go.mod h1:0uISGKJD6Owt29w2sUlK0TeLtYdLWtBiC43yVHdgMAY=
github.com/buildbarn/bb-storage v0.0.0-20240326045855-53c12526d34e h1:9akyMjvUsqodoCvKKdUlN5i+GxfYa9OeZnNuenPBLfE=
github.com/buildbarn/bb-storage v0.0.0-20240326045855-53c12526d34e/go.mod h1:0uISGKJD6Owt29w2sUlK0TeLtYdLWtBiC43yVHdgMAY=
github.com/buildbarn/go-xdr v0.0.0-20231115101217-a9e2aa4cf64b h1:/sKWC0Fs5fXNo/t72BRZRLERg4v2gFoEeg2Mk+a8xak=
github.com/buildbarn/go-xdr v0.0.0-20231115101217-a9e2aa4cf64b/go.mod h1:VwInghBSUyPtNBhl7o2oCUnxOCTGgySJnRTO1Kh7XuI=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
4 changes: 2 additions & 2 deletions go_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def go_dependencies():
go_repository(
name = "com_github_buildbarn_bb_storage",
importpath = "github.com/buildbarn/bb-storage",
sum = "h1:Gs3nP150dcZ7Utk7OrYPpoV9/7oGZ9y1It0BGPonDnk=",
version = "v0.0.0-20240310075825-20598f43e294",
sum = "h1:9akyMjvUsqodoCvKKdUlN5i+GxfYa9OeZnNuenPBLfE=",
version = "v0.0.0-20240326045855-53c12526d34e",
)
go_repository(
name = "com_github_buildbarn_go_xdr",
Expand Down