Skip to content

Commit

Permalink
Migrate bb-remote-asset to bzlmod (#38)
Browse files Browse the repository at this point in the history
At the same time, bring the entire build infrastructure for this project
in sync with the other bb-* components. This means that we now also
build multi-architecture container images.
  • Loading branch information
EdSchouten authored Mar 31, 2024
1 parent a116bef commit d3fcdae
Show file tree
Hide file tree
Showing 36 changed files with 13,674 additions and 2,978 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.1.1
60 changes: 30 additions & 30 deletions .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
"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": "Restore Bazel cache",
"uses": "actions/cache@v1",
"with": {
"key": "bazel",
"path": "~/.cache/bazel"
}
"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": "Bazel mod tidy",
"run": "bazel mod tidy"
},
{
"name": "Gazelle",
"run": "bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro go_dependencies.bzl%go_dependencies -prune && bazel run //:gazelle"
"run": "rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/') && bazel run //:gazelle"
},
{
"name": "Buildifier",
"run": "sed '/^$/d' go_dependencies.bzl > go_dependencies.bzl.new && mv go_dependencies.bzl.new go_dependencies.bzl && bazel run @com_github_bazelbuild_buildtools//:buildifier"
"run": "bazel run @com_github_bazelbuild_buildtools//:buildifier"
},
{
"name": "Gofmt",
Expand All @@ -41,23 +37,27 @@
},
{
"name": "Protobuf generation",
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query --output=label 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
},
{
"name": "Embedded asset generation",
"run": "bazel build $(git grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |//\\1:|' | sort -u)\ngit grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |\\1/|' | while read o; do\n if [ -e \"bazel-bin/$o\" ]; then\n rm -rf \"$o\"\n cp -r \"bazel-bin/$o\" \"$o\"\n find \"$o\" -type f -exec chmod -x {} +\n fi\ndone\n"
},
{
"name": "Test style conformance",
"run": "git diff --exit-code HEAD --"
"run": "git add . && git diff --exit-code HEAD --"
},
{
"name": "Golint",
"run": "bazel run @org_golang_x_lint//golint -- -set_exit_status $(pwd)/..."
},
{
"name": "linux_amd64: build and test",
"run": "bazel test --test_output=errors --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //..."
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_amd64 //..."
},
{
"name": "linux_amd64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "linux_amd64: upload bb_remote_asset",
Expand All @@ -69,11 +69,11 @@
},
{
"name": "linux_386: build and test",
"run": "bazel test --test_output=errors --platforms=@io_bazel_rules_go//go/toolchain:linux_386 //..."
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_386 //..."
},
{
"name": "linux_386: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:linux_386 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_386 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "linux_386: upload bb_remote_asset",
Expand All @@ -85,11 +85,11 @@
},
{
"name": "linux_arm: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm //..."
},
{
"name": "linux_arm: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "linux_arm: upload bb_remote_asset",
Expand All @@ -101,11 +101,11 @@
},
{
"name": "linux_arm64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm64 //..."
},
{
"name": "linux_arm64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:linux_arm64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "linux_arm64: upload bb_remote_asset",
Expand All @@ -117,11 +117,11 @@
},
{
"name": "darwin_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
},
{
"name": "darwin_amd64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "darwin_amd64: upload bb_remote_asset",
Expand All @@ -133,11 +133,11 @@
},
{
"name": "darwin_arm64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
},
{
"name": "darwin_arm64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:darwin_arm64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "darwin_arm64: upload bb_remote_asset",
Expand All @@ -149,11 +149,11 @@
},
{
"name": "freebsd_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset"
"run": "bazel build --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset"
},
{
"name": "freebsd_amd64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
"run": "rm -f bb_remote_asset && bazel run --run_under cp --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset"
},
{
"name": "freebsd_amd64: upload bb_remote_asset",
Expand All @@ -165,11 +165,11 @@
},
{
"name": "windows_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:windows_amd64 //..."
},
{
"name": "windows_amd64: copy bb_remote_asset",
"run": "rm -f bb_remote_asset.exe && bazel run --run_under cp --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset.exe"
"run": "rm -f bb_remote_asset.exe && bazel run --run_under cp --platforms=@rules_go//go/toolchain:windows_amd64 //cmd/bb_remote_asset $(pwd)/bb_remote_asset.exe"
},
{
"name": "windows_amd64: upload bb_remote_asset",
Expand Down
44 changes: 22 additions & 22 deletions .github/workflows/pull-requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,25 @@
"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": "Restore Bazel cache",
"uses": "actions/cache@v1",
"with": {
"key": "bazel",
"path": "~/.cache/bazel"
}
"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": "Bazel mod tidy",
"run": "bazel mod tidy"
},
{
"name": "Gazelle",
"run": "bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro go_dependencies.bzl%go_dependencies -prune && bazel run //:gazelle"
"run": "rm -f $(find . -name '*.pb.go' | sed -e 's/[^/]*$/BUILD.bazel/') && bazel run //:gazelle"
},
{
"name": "Buildifier",
"run": "sed '/^$/d' go_dependencies.bzl > go_dependencies.bzl.new && mv go_dependencies.bzl.new go_dependencies.bzl && bazel run @com_github_bazelbuild_buildtools//:buildifier"
"run": "bazel run @com_github_bazelbuild_buildtools//:buildifier"
},
{
"name": "Gofmt",
Expand All @@ -41,47 +37,51 @@
},
{
"name": "Protobuf generation",
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
"run": "find . bazel-bin/pkg/proto -name '*.pb.go' -delete || true\nbazel build $(bazel query --output=label 'kind(\"go_proto_library\", //...)')\nfind bazel-bin/pkg/proto -name '*.pb.go' | while read f; do\n cat $f > $(echo $f | sed -e 's|.*/pkg/proto/|pkg/proto/|')\ndone\n"
},
{
"name": "Embedded asset generation",
"run": "bazel build $(git grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |//\\1:|' | sort -u)\ngit grep '^[[:space:]]*//go:embed ' | sed -e 's|\\(.*\\)/.*//go:embed |\\1/|' | while read o; do\n if [ -e \"bazel-bin/$o\" ]; then\n rm -rf \"$o\"\n cp -r \"bazel-bin/$o\" \"$o\"\n find \"$o\" -type f -exec chmod -x {} +\n fi\ndone\n"
},
{
"name": "Test style conformance",
"run": "git diff --exit-code HEAD --"
"run": "git add . && git diff --exit-code HEAD --"
},
{
"name": "Golint",
"run": "bazel run @org_golang_x_lint//golint -- -set_exit_status $(pwd)/..."
},
{
"name": "linux_amd64: build and test",
"run": "bazel test --test_output=errors --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //..."
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_amd64 //..."
},
{
"name": "linux_386: build and test",
"run": "bazel test --test_output=errors --platforms=@io_bazel_rules_go//go/toolchain:linux_386 //..."
"run": "bazel test --test_output=errors --platforms=@rules_go//go/toolchain:linux_386 //..."
},
{
"name": "linux_arm: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm //..."
},
{
"name": "linux_arm64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:linux_arm64 //..."
},
{
"name": "darwin_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_amd64 //..."
},
{
"name": "darwin_arm64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_arm64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:darwin_arm64 //..."
},
{
"name": "freebsd_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset"
"run": "bazel build --platforms=@rules_go//go/toolchain:freebsd_amd64 //cmd/bb_remote_asset"
},
{
"name": "windows_amd64: build and test",
"run": "bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //..."
"run": "bazel build --platforms=@rules_go//go/toolchain:windows_amd64 //..."
}
]
}
Expand Down
31 changes: 14 additions & 17 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@gazelle//:def.bzl", "gazelle")

# gazelle:go_naming_convention_external import
# gazelle:prefix github.com/buildbarn/bb-remote-asset
# gazelle:resolve proto build/bazel/remote/execution/v2/remote_execution.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_proto
# gazelle:resolve proto go build/bazel/remote/execution/v2/remote_execution.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:execution
# gazelle:resolve proto build/bazel/remote/asset/v1/remote_asset.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/asset/v1:remote_asset_proto
# gazelle:resolve proto build/bazel/remote/execution/v2/remote_execution.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_proto
# gazelle:resolve proto go build/bazel/remote/asset/v1/remote_asset.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/asset/v1:asset
# gazelle:resolve proto pkg/proto/configuration/blobstore/blobstore.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore:blobstore_proto
# gazelle:resolve proto go build/bazel/remote/execution/v2/remote_execution.proto @com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:execution
# gazelle:resolve proto go google/bytestream/bytestream.proto @org_golang_google_genproto_googleapis_bytestream//:bytestream
# gazelle:resolve proto go google/rpc/status.proto @org_golang_google_genproto_googleapis_rpc//status
# gazelle:resolve proto go opentelemetry/proto/common/v1/common.proto @io_opentelemetry_go_proto_otlp//common/v1:common
# gazelle:resolve proto go pkg/proto/configuration/blobstore/blobstore.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore
# gazelle:resolve proto pkg/proto/configuration/global/global.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/global:global_proto
# gazelle:resolve proto go pkg/proto/configuration/global/global.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/global
# gazelle:resolve proto pkg/proto/configuration/grpc/grpc.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/grpc:grpc_proto
# gazelle:resolve proto go pkg/proto/configuration/grpc/grpc.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/grpc
# gazelle:resolve proto pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto
# gazelle:resolve proto go pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http
# gazelle:resolve proto opentelemetry/proto/common/v1/common.proto @io_opentelemetry_proto//:common_proto
# gazelle:resolve proto go opentelemetry/proto/common/v1/common.proto @io_opentelemetry_go_proto_otlp//common/v1:common
# gazelle:resolve proto go google/bytestream/bytestream.proto @org_golang_google_genproto_googleapis_bytestream//:bytestream
# gazelle:resolve proto google/bytestream/bytestream.proto @googleapis//google/bytestream:bytestream_proto
# gazelle:resolve proto go google/rpc/status.proto @org_golang_google_genproto_googleapis_rpc//status
# gazelle:resolve proto proto google/rpc/status.proto @googleapis//google/rpc:status_proto
# gazelle:resolve proto google/protobuf/timestamp.proto @protobuf//:timestamp_proto
# gazelle:resolve proto google/rpc/status.proto @googleapis//google/rpc:status_proto
# gazelle:resolve proto opentelemetry/proto/common/v1/common.proto @io_opentelemetry_proto//:common_proto
# gazelle:resolve proto pkg/proto/configuration/blobstore/blobstore.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/blobstore:blobstore_proto
# gazelle:resolve proto pkg/proto/configuration/global/global.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/global:global_proto
# gazelle:resolve proto pkg/proto/configuration/grpc/grpc.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/grpc:grpc_proto
# gazelle:resolve proto pkg/proto/configuration/http/http.proto @com_github_buildbarn_bb_storage//pkg/proto/configuration/http:http_proto
gazelle(
name = "gazelle",
)

buildifier(
name = "buildifier",
)

npm_link_all_packages(
name = "node_modules",
)
Loading

0 comments on commit d3fcdae

Please sign in to comment.