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

Adding an initial bazel configuration #3141

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=7.4.1
8 changes: 8 additions & 0 deletions .buildkite/steps/bazel-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -Eeufo pipefail

# When it comes time to run Bazel within a pipeline, this script will be ready to do so.

# Run all tests
bazelisk test //...
11 changes: 11 additions & 0 deletions .buildkite/steps/build-bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -Eeufo pipefail

# When it comes time to run Bazel within a pipeline, this script will be ready to do so.

# Run the full build first...
bazelisk build //...

# Artefact the built binary...
buildkite-agent artifact upload "./bazel-bin/buildkite-agent_/buildkite-agent"
24 changes: 24 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:prefix github.com/buildkite/agent/v3
gazelle(name = "gazelle")

go_binary(
name = "buildkite-agent",
embed = [":agent_lib"],
pure = "on",
visibility = ["//visibility:public"],
)

go_library(
name = "agent_lib",
srcs = ["main.go"],
importpath = "github.com/buildkite/agent/v3",
visibility = ["//visibility:private"],
deps = [
"//clicommand",
"//version",
"@com_github_urfave_cli//:cli",
],
)
18 changes: 18 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bazel_dep(name = "gazelle", version = "0.40.0")
bazel_dep(name = "rules_go", version = "0.50.1")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.7")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've cracked it! It's ignoring all the overrides and fixes being attempted in deps.bzl because this is using BzlMod instead!

Here's how I think we can fix it:

  1. Get rid of deps.bzl, WORKSPACE.bazel, and the gazelle rule in BUILD.bazel
  2. Add a gazelle override here:
Suggested change
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
go_deps.gazelle_override(
directives = [
"gazelle:go_generate_proto false",
],
path = "github.com/DataDog/sketches-go",
)

With that I can successfully bazel build //... !

go_deps.gazelle_override(
directives = [
"gazelle:go_generate_proto false",
],
path = "github.com/DataDog/sketches-go",
)

# All *direct* dependencies are required to be listed explicitly
use_repo(go_deps, "com_github_aws_aws_sdk_go", "com_github_aws_aws_sdk_go_v2", "com_github_aws_aws_sdk_go_v2_config", "com_github_aws_aws_sdk_go_v2_feature_ec2_imds", "com_github_aws_aws_sdk_go_v2_service_kms", "com_github_azure_azure_sdk_for_go_sdk_azidentity", "com_github_azure_azure_sdk_for_go_sdk_storage_azblob", "com_github_brunoscheufler_aws_ecs_metadata_go", "com_github_buildkite_bintest_v3", "com_github_buildkite_go_pipeline", "com_github_buildkite_interpolate", "com_github_buildkite_roko", "com_github_buildkite_shellwords", "com_github_creack_pty", "com_github_datadog_datadog_go_v5", "com_github_denisbrodbeck_machineid", "com_github_dustin_go_humanize", "com_github_dustinkirkland_golang_petname", "com_github_gliderlabs_ssh", "com_github_go_chi_chi_v5", "com_github_gofrs_flock", "com_github_google_go_cmp", "com_github_google_go_querystring", "com_github_gowebpki_jcs", "com_github_khan_genqlient", "com_github_lestrrat_go_jwx_v2", "com_github_mattn_go_zglob", "com_github_oleiade_reflections", "com_github_opentracing_opentracing_go", "com_github_pborman_uuid", "com_github_puzpuzpuz_xsync_v2", "com_github_qri_io_jsonschema", "com_github_stretchr_testify", "com_github_urfave_cli", "com_google_cloud_go_compute_metadata", "dev_drjosh_zzglob", "in_gopkg_datadog_dd_trace_go_v1", "in_gopkg_yaml_v3", "io_opentelemetry_go_contrib_propagators_aws", "io_opentelemetry_go_contrib_propagators_b3", "io_opentelemetry_go_contrib_propagators_jaeger", "io_opentelemetry_go_contrib_propagators_ot", "io_opentelemetry_go_otel", "io_opentelemetry_go_otel_exporters_otlp_otlptrace", "io_opentelemetry_go_otel_exporters_otlp_otlptrace_otlptracegrpc", "io_opentelemetry_go_otel_sdk", "io_opentelemetry_go_otel_trace", "org_golang_google_api", "org_golang_x_crypto", "org_golang_x_exp", "org_golang_x_net", "org_golang_x_oauth2", "org_golang_x_sys", "org_golang_x_term", "tools_gotest_v3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this generated? Seems like a thing that ought to be one per line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, very much generated! This was all via gazelle, so happy I didn't have to assemble by hand.

134 changes: 134 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions agent/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "agent",
srcs = [
"agent_configuration.go",
"agent_pool.go",
"agent_worker.go",
"api.go",
"doc.go",
"ec2_meta_data.go",
"ec2_tags.go",
"ecs_meta_data.go",
"gcp_labels.go",
"gcp_meta_data.go",
"header_times_streamer.go",
"job_runner.go",
"k8s_tags.go",
"log_streamer.go",
"pipeline_uploader.go",
"run_job.go",
"tags.go",
"verify_job.go",
],
importpath = "github.com/buildkite/agent/v3/agent",
visibility = ["//visibility:public"],
deps = [
"//api",
"//core",
"//env",
"//internal/agenthttp",
"//internal/awslib",
"//internal/experiments",
"//internal/job/hook",
"//internal/shell",
"//kubernetes",
"//logger",
"//metrics",
"//process",
"//status",
"@com_github_aws_aws_sdk_go//aws",
"@com_github_aws_aws_sdk_go//aws/ec2metadata",
"@com_github_aws_aws_sdk_go//service/ec2",
"@com_github_brunoscheufler_aws_ecs_metadata_go//:aws-ecs-metadata-go",
"@com_github_buildkite_go_pipeline//:go-pipeline",
"@com_github_buildkite_go_pipeline//signature",
"@com_github_buildkite_roko//:roko",
"@com_github_buildkite_shellwords//:shellwords",
"@com_github_denisbrodbeck_machineid//:machineid",
"@com_github_dustin_go_humanize//:go-humanize",
"@com_github_gowebpki_jcs//:jcs",
"@com_google_cloud_go_compute_metadata//:metadata",
"@org_golang_google_api//compute/v1:compute",
"@org_golang_x_oauth2//google",
],
)

go_test(
name = "agent_test",
srcs = [
"agent_worker_test.go",
"ec2_meta_data_test.go",
"gcp_meta_data_test.go",
"job_runner_test.go",
"k8s_tags_test.go",
"log_streamer_test.go",
"pipeline_uploader_test.go",
"tags_test.go",
],
embed = [":agent"],
deps = [
"//api",
"//core",
"//logger",
"@com_github_buildkite_go_pipeline//:go-pipeline",
"@com_github_google_go_cmp//cmp",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],
)
40 changes: 40 additions & 0 deletions agent/integration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "integration",
srcs = ["test_helpers.go"],
importpath = "github.com/buildkite/agent/v3/agent/integration",
visibility = ["//visibility:public"],
deps = [
"//agent",
"//api",
"//logger",
"//metrics",
"@com_github_buildkite_bintest_v3//:bintest",
"@com_github_lestrrat_go_jwx_v2//jwk",
],
)

go_test(
name = "integration_test",
srcs = [
"config_allowlisting_integration_test.go",
"job_environment_integration_test.go",
"job_runner_integration_test.go",
"job_verification_integration_test.go",
"main_test.go",
],
embed = [":integration"],
deps = [
"//agent",
"//api",
"//clicommand",
"//version",
"@com_github_buildkite_bintest_v3//:bintest",
"@com_github_buildkite_go_pipeline//:go-pipeline",
"@com_github_buildkite_go_pipeline//signature",
"@com_github_lestrrat_go_jwx_v2//jwk",
"@com_github_urfave_cli//:cli",
"@tools_gotest_v3//assert",
],
)
Loading