Publishers
Publishers are destinations where bz writes synced modules. They’re specified using registry.* functions when used as a workflow destination.
File Publisher
Write modules to a local filesystem:
# Create a local registry mirrormirror = registry.file("/var/bazel-registry")
sync.workflow( name = "local-sync", origin = bcr, destination = mirror, # Uses file publisher modules = ["rules_go"],)Directory Structure
The file publisher creates the standard BCR structure:
/var/bazel-registry/├── modules/│ └── rules_go/│ ├── metadata.json│ ├── 0.50.0/│ │ ├── MODULE.bazel│ │ └── source.json│ └── 0.50.1/│ ├── MODULE.bazel│ └── source.json└── bazel_registry.jsonHTTP PUT Publisher
Publish modules to an HTTP server that supports PUT requests:
# Basic HTTP PUTserver = registry.http_put( url = "https://registry.example.com",)
# With authenticationserver = registry.http_put( url = "https://registry.example.com", auth = auth.bearer(token = env("UPLOAD_TOKEN")),)
# With basic authserver = registry.http_put( url = "https://registry.example.com", auth = auth.basic( username = env("REGISTRY_USER"), password = env("REGISTRY_PASS"), ),)Request Format
For each file, bz sends:
PUT /modules/rules_go/0.50.1/MODULE.bazel HTTP/1.1Host: registry.example.comContent-Type: application/octet-streamAuthorization: Bearer <token>
<file content>Git Publisher
Push modules to a git repository:
# GitHub repositoryrepo = registry.git( url = "https://github.com/myorg/bazel-registry.git", branch = "main",)
sync.workflow( name = "git-sync", origin = bcr, destination = repo, # Uses git publisher modules = ["rules_go"],)Git Workflow
The git publisher:
- Clones the repository (or pulls if already cloned)
- Writes module files to the working directory
- Commits changes with a descriptive message
- Pushes to the remote branch
Authentication
# Using token (GitHub, GitLab)repo = registry.git( url = "https://github.com/myorg/registry.git", auth = auth.bearer(token = env("GITHUB_TOKEN")),)
# Using SSH (requires SSH key setup)repo = registry.git( url = "git@github.com:myorg/registry.git",)Publisher Selection
The publisher is automatically selected based on the registry type and context:
| Registry Type | As Origin | As Destination |
|---|---|---|
registry.http() | HTTP GET | Not supported |
registry.http_put() | HTTP GET | HTTP PUT |
registry.file() | File read | File write |
registry.git() | Git clone | Git commit/push |
Examples
Mirror to Multiple Destinations
bcr = registry.http("https://bcr.bazel.build")
# Local developmentlocal = registry.file("./registry")
# Team stagingstaging = registry.git( url = "https://github.com/myorg/staging-registry.git", branch = "main",)
# Production serverproduction = registry.http_put( url = "https://registry.prod.example.com", auth = auth.bearer(token = env("PROD_TOKEN")),)
# Sync to local for developmentsync.workflow( name = "dev", origin = bcr, destination = local, modules = ["rules_go"],)
# Sync to staging for testingsync.workflow( name = "staging", origin = bcr, destination = staging, modules = ["rules_go"],)
# Sync to productionsync.workflow( name = "prod", origin = bcr, destination = production, modules = ["rules_go"],)Dry Run
Test publishing without writing:
bz mod sync --workflow prod --dry-runThis shows what would be published without actually writing files.