Skip to main content

Building with Bazel

PatchBase uses Bazel as its build system. All build, test, and run commands go through Bazel.

Prerequisites

Install bazelisk (recommended) or Bazel 7+ directly:

# Using Go
go install github.com/bazelbuild/bazelisk@latest

# Or download the binary
# See https://github.com/bazelbuild/bazelisk/releases

Bazelisk reads the Bazel version from .bazeliskrc and automatically downloads the right version.

Build commands

# Build everything (server, agent, dashboard)
bazel build //...

# Build just the server
bazel build //cmd/patchbase-server

# Build just the agent
bazel build //agent/cmd/patchbase-agent

# Build the documentation site
bazel build //docs:build_docs

Test commands

# Run all tests
bazel test //...

# Run tests for a specific package
bazel test //internal/services/...
bazel test //agent/internal/collector/...

Run commands

# Run the server
bazel run //cmd/patchbase-server -- serve

# Run migrations
bazel run //cmd/patchbase-server -- migrate

# Run the agent
bazel run //agent/cmd/patchbase-agent -- sync

Gazelle

Gazelle generates BUILD.bazel files from Go source. After changing imports or adding files:

bazel run //:gazelle

If Gazelle adds a new go_test target, annotate it with size = "small" since Gazelle doesn't set that by default:

go_test(
name = "foo_test",
size = "small",
...
)

Linting

golangci-lint run