Skip to content

Commit

Permalink
Use Bazel 7 and bzlmod. (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekhabarov authored Jan 23, 2025
1 parent c4974ba commit 6402d5d
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 164 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Limit resources for build
# build --local_ram_resources=HOST_RAM*.5 --local_cpu_resources=8

common --incompatible_enable_proto_toolchain_resolution

# Show us information about failures.
build --verbose_failures
test --test_output=errors
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.5.0
7.4.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bazel-*
MODULE.bazel.lock
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_sluongng_nogo_analyzer//:def.bzl", "nogo_config")
load("@com_github_sluongng_nogo_analyzer//staticcheck:def.bzl", "staticcheck_analyzers")
load("@io_bazel_rules_go//go:def.bzl", "TOOLS_NOGO", "nogo")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
load(":staticheck.bzl", "STATICCHECK_ANALYZERS", "STATICCHECK_OVERRIDE")

# gazelle:prefix github.com/ekhabarov/bazel-k8s-envoy
Expand Down
81 changes: 81 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module(
name = "bazel-k8s-envoy",
version = "0.0.1",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.11.0")
bazel_dep(name = "rules_oci", version = "2.2.0")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "distroless_base",
digest = "sha256:280852156756ea3f39f9e774a30346f2e756244e1f432aea3061c4ac85d90a66", #multi-arch
image = "gcr.io/distroless/base",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)
oci.pull(
name = "envoy_base",
# tag = "distroless-v1.28.0",
digest = "sha256:0bb664e36cef65b884965b22bbb2fbd1acecb8bb174683a321677c4fc7475593",
image = "index.docker.io/envoyproxy/envoy",
platforms = [
"linux/amd64",
"linux/arm64",
],
)

# For each oci.pull call, repeat the "name" here to expose them as dependencies.
use_repo(
oci,
"distroless_base",
"distroless_base_linux_amd64",
"distroless_base_linux_arm64_v8",
"envoy_base",
"envoy_base_linux_amd64",
"envoy_base_linux_arm64",
)

bazel_dep(name = "rules_go", version = "0.52.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.41.0", repo_name = "bazel_gazelle")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"co_honnef_go_tools",
"com_github_burntsushi_toml",
"com_github_envoyproxy_go_control_plane",
"org_golang_google_genproto",
"org_golang_google_grpc",
"org_golang_x_tools",
)

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.23.4")
go_sdk.nogo(nogo = "//:nogo")

bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "toolchains_protoc", version = "0.3.6")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a")

switched_rules = use_extension("@googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(
go = True,
grpc = True,
)
use_repo(switched_rules, "com_google_googleapis_imports")

protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
protoc.toolchain(
# Creates a repository to satisfy well-known-types dependencies such as
# deps=["@com_google_protobuf//:any_proto"]
google_protobuf = "com_google_protobuf",
# Pin to any version of protoc
version = "v27.3",
)
use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")

register_toolchains("@toolchains_protoc_hub//:all")
142 changes: 0 additions & 142 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,10 @@ http_archive(
],
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "f4a9314518ca6acfa16cc4ab43b0b8ce1e4ea64b81c38d8a3772883f153346b8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
],
)

http_archive(
name = "googleapis",
sha256 = "12b19423a8cf8d35848440e818d5c5385848edf59d3da434e6ea49a070482526",
strip_prefix = "googleapis-d6f184876ec67295addccbb70aa4af622e049a7e",
urls = [
"https://github.com/googleapis/googleapis/archive/d6f184876ec67295addccbb70aa4af622e049a7e.zip",
],
)

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

switched_rules_by_language(
name = "com_google_googleapis_imports",
go = True,
)


load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(
nogo = "@//:nogo",
version = "1.22.7",
)

http_archive(
name = "bazel_gazelle",
integrity = "sha256-LHVFzJFKQR5cFcPVWgpe00+/9i3vDh8Ktu0UvaIiw8w=",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.39.0/bazel-gazelle-v0.39.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.39.0/bazel-gazelle-v0.39.0.tar.gz",
],
)

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

# gazelle:repository_macro go_deps.bzl%go_deps
go_deps()

load("@com_github_sluongng_nogo_analyzer//staticcheck:deps.bzl", "staticcheck")

staticcheck()

gazelle_dependencies()

http_archive(
name = "rules_proto",
sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295",
strip_prefix = "rules_proto-6.0.2",
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

rules_proto_dependencies()

load("@rules_proto//proto:setup.bzl", "rules_proto_setup")

rules_proto_setup()

load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")

rules_proto_toolchains()


############## TILT

TILT_VERSION = "0.33.12"
Expand Down Expand Up @@ -118,76 +46,6 @@ _tilt_sha = {
"mac",
]]

http_archive(
name = "aspect_bazel_lib",
sha256 = "87ab4ec479ebeb00d286266aca2068caeef1bb0b1765e8f71c7b6cfee6af4226",
strip_prefix = "bazel-lib-2.7.3",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.3/bazel-lib-v2.7.3.tar.gz",
)

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

# Required bazel-lib dependencies

aspect_bazel_lib_dependencies()

# Register bazel-lib toolchains

aspect_bazel_lib_register_toolchains()

http_archive(
name = "com_google_protobuf",
sha256 = "3cf7d5b17c4ff04fe9f038104e9d0cae6da09b8ce271c13e44f8ac69f51e4e0f",
strip_prefix = "protobuf-25.5",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.5/protobuf-25.5.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

### OCI ###
http_archive(
name = "rules_oci",
sha256 = "56d5499025d67a6b86b2e6ebae5232c72104ae682b5a21287770bd3bf0661abf",
strip_prefix = "rules_oci-1.7.5",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.7.5/rules_oci-v1.7.5.tar.gz",
)

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")

rules_oci_dependencies()

load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oci_register_toolchains")

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

load("@rules_oci//oci:pull.bzl", "oci_pull")

oci_pull(
name = "distroless_base",
digest = "sha256:280852156756ea3f39f9e774a30346f2e756244e1f432aea3061c4ac85d90a66", #multi-arch
image = "gcr.io/distroless/base",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)

oci_pull(
name = "envoy_base",
# tag = "distroless-v1.28.0",
digest = "sha256:0bb664e36cef65b884965b22bbb2fbd1acecb8bb174683a321677c4fc7475593",
image = "index.docker.io/envoyproxy/envoy",
platforms = [
"linux/amd64",
"linux/arm64",
],
)

http_archive(
name = "rules_ytt",
sha256 = "876ab0223567ec7556107374a9b9cb3e3db9ba5bb97e778c35d36f1d1f717879",
Expand Down
4 changes: 2 additions & 2 deletions authz/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push", "oci_load")
load("@rules_ytt//:defs.bzl", "ytt")
load("//:platforms.bzl", "ARCH", "OS")
load("//:stamp.bzl", "stamp")
Expand Down Expand Up @@ -67,7 +67,7 @@ oci_image_index(
],
)

oci_tarball(
oci_load(
name = "tarball",
image = select({
"@platforms//cpu:arm64": ":image_linux_arm64",
Expand Down
2 changes: 1 addition & 1 deletion bazel.Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ arch = "amd64"
# if k8s_context().endswith("@pi"):
# arch = "arm"

# BAZEL_RUN_CMD = "bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_{arch} %s -- --norun".format(arch=arch)
# BAZEL_RUN_CMD = "bazel run --platforms=@rules_go//go/toolchain:linux_{arch} %s -- --norun".format(arch=arch)
BAZEL_RUN_CMD = "bazel run %s".format(arch=arch)

# build dependencies: what dependencies does Bazel need to execute this target?
Expand Down
4 changes: 2 additions & 2 deletions envoy/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_load")
load("@rules_ytt//:defs.bzl", "ytt")
load("//:stamp.bzl", "stamp")
load("//utils:tar.bzl", "mtar")
Expand All @@ -19,7 +19,7 @@ oci_image(
tars = [":tar"],
)

oci_tarball(
oci_load(
name = "tarball",
image = ":image",
repo_tags = ["bazel/envoy:latest"],
Expand Down
19 changes: 15 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
module github.com/ekhabarov/bazel-k8s-envoy

go 1.20
go 1.23

toolchain go1.23.4

require (
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
github.com/envoyproxy/go-control-plane v0.11.0
golang.org/x/tools v0.29.0
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4
google.golang.org/grpc v1.53.0
)

require (
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.10.0 // indirect
)

require (
github.com/cncf/xds/go v0.0.0-20230112175826-46e39c7b9b43 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
honnef.co/go/tools v0.5.1
)
Loading

0 comments on commit 6402d5d

Please sign in to comment.