- Zig 98.7%
- Shell 1.2%
- Dockerfile 0.1%
| .forgejo/workflows | ||
| deploy | ||
| docker | ||
| docs | ||
| src | ||
| .gitignore | ||
| .mise.toml | ||
| AGENTS.md | ||
| build.zig | ||
| build.zig.zon | ||
| LICENSE | ||
| README.md | ||
beacon
beacon keeps nginx and Cloudflare DNS in step with the routes aerodrome
publishes, the way docker-gen does for containers. A person approves a public host for a
flight, and https://<host> starts working with no hand edits. Revoke it,
and nginx stops routing it at once.
It follows hangar's routes feed (GET /routes?since=<generation>&wait=60
on hangar's admin socket) and, on every new generation:
- renders one nginx file,
conf.d/beacon.conf, from a per-host fragment; writes it to a temp file and renames it into place; runsnginx -tin the nginx container; reloads (HUP) if the test passes, and puts the old file back if it doesn't; - keeps a CNAME per approved host in Cloudflare, each marked with a
managed by beacon <commit>; flight=<flight>comment. It never touches a record without that mark. When a host leaves the feed, its record is only markedabsent since <time>;beacon prunedeletes such records, asking for each one.beacon adopttakes over a hand-made CNAME at a host in the feed, also asking for each one.
When hangar can't be reached (aerodrome restarting or upgrading), beacon keeps what it last applied and retries. A restarted hangar's new generation with the same routes renders the same bytes, so nothing changes.
Design, decisions, and the reasons for them: docs/design.md.
Usage
beacon run [--config PATH] [--dry-run] [--once]
beacon prune [--config PATH]
beacon adopt [--config PATH]
beacon version
run: the service. Logs onekey=valueline per event on stderr.--dry-run: reads hangar, the nginx file, and Cloudflare for real; prints the file beacon would write, its diff against the one on disk, and the DNS changes; changes nothing.--once: one round, then exit (non-zero if anything failed).prune: lists beacon's DNS records whose hosts left the feed, oldest first, and deletes each only on ay. It needs a terminal (docker exec -it), and keeps a record whose host is back in the feed.adopt: lists hand-made (unmarked) CNAMEs at the names of hosts in the feed and, on ayfor each, makes it beacon's: its comment, and the config's target, proxied, and TTL (the prompt shows what that changes). Any other record type there is skipped with a warning. It also needs a terminal, and leaves a record alone if its host has left the feed.
The config path defaults to /etc/beacon/beacon.zon.
Configuration
One ZON file; deploy/beacon.zon as an example, with every field. In short:
| Field | Default | |
|---|---|---|
hangar_socket |
/run/aerodrome-hangar/hangar.sock |
Mount its directory, not the socket |
nginx.conf_dir |
/etc/nginx/conf.d |
|
nginx.file_name |
beacon.conf |
Its sort order in conf.d matters (design.md, "File") |
nginx.fragment |
/etc/beacon/fragment.conf |
|
nginx.certs_dir |
/etc/nginx/certs |
Certificates chosen as docker-gen does |
docker.socket |
/var/run/docker.sock |
|
docker.container |
nginx |
Where nginx -t runs and HUP goes |
dns |
none | Without it, beacon keeps no DNS |
dns.token_file |
/run/secrets/cloudflare-token |
API token, DNS edit on the zones only |
dns.target |
(required) | What every CNAME points at |
dns.proxied, dns.ttl |
false, 1 (auto) |
|
dns.zones |
(required) | .{ .name, .id }; a host goes to longest matching zone |
The fragment (deploy/fragment.conf) is nginx config
with three placeholders, {{host}}, {{flight}}, and {{cert}} (the
certificate's base name, such as lerch.org). Anything else in {{...}}
is an error at start. beacon writes it once per host, hosts sorted, and
leaves out (and logs) a host with no usable certificate.
Deployment
The image is git.lerch.org/lobo/beacon:<shortsha>, built and pushed by
.forgejo/workflows/build.yaml: a static
binary (x86_64-linux-none: no libc) and a CA bundle, FROM scratch,
running as uid 1000. deploy/docker-run.sh is an
example docker run; set its paths for your host. It mounts:
/run/aerodrome-hangar(the directory; the container joins theaerodrome-admingroup);- nginx's
conf.d(read-write) andcerts(read-only); - a directory with
beacon.zonandfragment.confas/etc/beacon; - the Cloudflare API token file (DNS edit on your zone only) as
/run/secrets/cloudflare-token; - the Docker socket (the container joins the
dockergroup), fornginx -tand the reload.
Two of those are worth knowing about: hangar's socket is its whole admin
API (beacon only ever calls GET /routes), and Docker socket access is
root-equivalent on the host, as it already is for docker-gen.
Prune or adopt from the host:
docker exec -it beacon /beacon prune --config /etc/beacon/beacon.zon
docker exec -it beacon /beacon adopt --config /etc/beacon/beacon.zon
Building
Zig 0.17.1, std only, pinned in .mise.toml.
zig build # zig-out/bin/beacon
zig build test --summary all # unit and Unix-socket tests
zig build fmt # zig fmt --check
zig build -Dtarget=x86_64-linux-none --release=safe -Dcommit="$(git rev-parse --short HEAD)"
-Dcommit stamps the build; beacon writes it into the DNS comments
(unknown without it).
License
MIT; see LICENSE.