diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..19b860c1 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.4.0 diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index fa79b8d7..aa931ca7 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -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" diff --git a/.github/workflows/pull-requests.yaml b/.github/workflows/pull-requests.yaml index 7c939023..2f73626c 100644 --- a/.github/workflows/pull-requests.yaml +++ b/.github/workflows/pull-requests.yaml @@ -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" diff --git a/WORKSPACE b/WORKSPACE index 101f3cf4..580ab399 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( @@ -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, @@ -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( @@ -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( @@ -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") diff --git a/cmd/bb_noop_worker/BUILD.bazel b/cmd/bb_noop_worker/BUILD.bazel index 99253906..02724dba 100644 --- a/cmd/bb_noop_worker/BUILD.bazel +++ b/cmd/bb_noop_worker/BUILD.bazel @@ -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( @@ -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( diff --git a/cmd/bb_runner/BUILD.bazel b/cmd/bb_runner/BUILD.bazel index f8272f6d..e590c173 100644 --- a/cmd/bb_runner/BUILD.bazel +++ b/cmd/bb_runner/BUILD.bazel @@ -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", @@ -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", ) diff --git a/cmd/bb_scheduler/BUILD.bazel b/cmd/bb_scheduler/BUILD.bazel index e6c66eee..41e1477e 100644 --- a/cmd/bb_scheduler/BUILD.bazel +++ b/cmd/bb_scheduler/BUILD.bazel @@ -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") @@ -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( diff --git a/cmd/bb_worker/BUILD.bazel b/cmd/bb_worker/BUILD.bazel index 519456db..48c60dbf 100644 --- a/cmd/bb_worker/BUILD.bazel +++ b/cmd/bb_worker/BUILD.bazel @@ -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( @@ -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( diff --git a/go.mod b/go.mod index e484841b..4bf41613 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c5a2cb29..6fd67ff2 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/go_dependencies.bzl b/go_dependencies.bzl index d67b56ba..3cbd6c9e 100644 --- a/go_dependencies.bzl +++ b/go_dependencies.bzl @@ -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",