Skip to content

About

rustbgpd in a container

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

container-rustbgpd

A minimal container image for rustbgpd, published to ghcr.io/routedbits/rustbgpd.

~48 MB, versus ~134 MB for the Debian-based image the upstream project publishes. The daemon and the rbgp CLI sit on a FROM scratch rootfs holding nothing but the glibc objects the two binaries actually link against.

$ docker pull ghcr.io/routedbits/rustbgpd:latest
$ docker run --rm ghcr.io/routedbits/rustbgpd rustbgpd --version
rustbgpd 0.65.0

What this repo is

Packaging only — there is no Rust here, and nothing is compiled.

The Dockerfile downloads the official release tarball from the upstream GitHub release, verifies it against the published checksums-linux-<arch>.txt, and assembles a scratch rootfs from it. The binaries in the image are therefore byte-identical to the ones operators install from a tarball today: the full release profile with fat LTO, codegen-units=1, and jemalloc — the same build every number in the upstream benchmarks describes.

That choice is what makes this cheap. A CI run takes about a minute instead of the twenty to forty a fat-LTO workspace build needs, and linux/arm64 costs almost nothing, because the only work QEMU has to emulate is ldd and cp.

Running it

# Generate a starting config (the image has no ENTRYPOINT, by design)
$ mkdir -p ./conf
$ docker run --rm ghcr.io/routedbits/rustbgpd \
    rustbgpd --init-config edge > ./conf/config.toml
$ sudo chown -R 999:999 ./conf

$ docker run -d --name rustbgpd \
    -v "$PWD/conf:/etc/rustbgpd" \
    --network host \
    --ulimit nofile=65536:524288 \
    --stop-timeout=1920 \
    ghcr.io/routedbits/rustbgpd:latest

Networking: --network host or published ports

BGP identifies peers by source address, so the only thing that matters is whether a peer's address reaches the daemon intact. Published ports preserve it for traffic that genuinely arrives from off-box, and rewrite it for two local paths:

how the peer reaches the daemon source address
another router, off-box preserved
this host, via its own LAN address preserved
this host, via 127.0.0.1 rewritten to 172.17.0.1
another container on this host rewritten to 172.17.0.1

The last two are Docker's userland proxy and the bridge hairpin masquerade. A peer that hits either is dropped, and the log says exactly that:

WARN "inbound connection from unknown peer, dropping"  peer_ip=172.17.0.1

So published ports are fine for ordinary peerings with real routers:

$ docker run -d --name rustbgpd \
    -v "$PWD/conf:/etc/rustbgpd" \
    -p 179:179 -p 9179:9179 \
    --ulimit nofile=65536:524288 \
    --stop-timeout=1920 \
    ghcr.io/routedbits/rustbgpd:latest

Reach for --network host when peers live on this same host — labs with peers in other containers or namespaces, or anything peering over 127.0.0.1 — and when you want the daemon's outbound sessions to source from the host's address rather than a masqueraded bridge address. A macvlan/ipvlan network gives the container its own L2 presence and preserves addresses in both directions, if you want isolation too.

Either way, port 179 works as uid 999, because the daemon binary carries cap_net_bind_service=+ep. You do not need --cap-add (Docker's default bounding set already contains it) and you do not need to run as root. The Dockerfile explains why the file capability is required rather than merely convenient — the short version is that a container with its own network namespace gets ip_unprivileged_port_start=0 for free, and the host's namespace does not.

Add --cap-add=NET_ADMIN if you use the Linux FIB or EVPN VTEP dataplane.

The config directory must be mounted read-write and owned by uid 999. Config persistence rewrites the file with a temp-file-plus-rename, so a :ro bind-mounted file makes every mutating RPC fail. For the same reason, mount the directory rather than the config file itself.

The CLI is in the image, so it works without a shell:

$ docker exec rustbgpd rbgp health
Status:  healthy
Uptime:  00:00:06
Peers:   0
Routes:  0

Differences from the upstream image

upstream this image
size ~134 MB ~48 MB
base debian:bookworm-slim scratch
shell yes no
uid 999 via useradd --system pinned explicitly in /etc/passwd
HEALTHCHECK rbgp health | grep healthy rbgp health (liveness only)
port 179 as non-root container netns sysctl file capability, works with --network host
extra binaries birdwatcher-adapter none

Two consequences worth knowing:

  • docker exec ... sh does not work. docker exec ... rbgp ..., docker cp, and docker logs all still do.
  • The healthcheck is a liveness probe. rbgp health exits 0 whenever the daemon answers the Health RPC, even if the daemon self-reports unhealthy. Asserting on the reported status needs a shell for the pipeline, which this image deliberately does not have. The clean fix is an exit-non-zero-on-unhealthy flag on rbgp health upstream.

birdwatcher-adapter and rs-config-render ship in the release tarball but are not in this image. Both are separate processes rather than daemon dependencies; the adapter belongs in a sidecar.

The Dockerfile documents, in comments, why each remaining piece is load-bearing and why each omission is safe — ca-certificates, tzdata, terminfo, the NSS modules, the 0700 state directory, the sticky /tmp. Read it before removing anything from it.

How publishing works

One workflow, .github/workflows/release.yml, with two triggers that both converge on a single resolved version:

trigger version packaged
Run workflow with no version current upstream release
Run workflow with a version that version
weekly cron (Mon 06:00 UTC) current upstream release

There is deliberately no git tag trigger. Nothing here carries state a tag could usefully record, and this repo's code changes independently of upstream's version numbers — tagging it vX.Y.Z after upstream would conflate the two. It would also block the common case: republishing an unchanged upstream version after a packaging fix, where that tag already exists. A force dispatch covers that instead.

New upstream releases are therefore published automatically, within a week and with nobody in the loop. Two gates keep that safe rather than merely automatic:

  1. The registry is the source of truth. Before building anything, the run asks docker manifest inspect whether that version is already published and exits cleanly if it is. There is no state file to drift. A manual dispatch racing the cron, or a re-run of either, cannot double-publish. The force input overrides this for a deliberate rebuild.
  2. Nothing is pushed before it is verified. Both linux/amd64 and linux/arm64 are built into the local image store first, and scripts/verify-image.sh asserts against the real exported filesystem — the binaries run and report the expected version, the state directory is 0700 and owned by 999, both licenses are present, no shell leaked in, and the image is still small. Only then does the multi-arch push happen.

latest moves only when the version being published is upstream's current release, so a forced rebuild of an old version cannot drag the floating tag backward.

When the cron goes dormant

GitHub disables scheduled workflows in public repositories after 60 days with no repository activity. In practice that only happens during a stretch where upstream released nothing, so nothing was missed — but the next upstream release will not publish on its own.

The recovery is Actions → Release container → Run workflow, with both inputs left blank. That resolves upstream latest and publishes it, taking exactly the path the cron would have taken.

Local development

$ ./scripts/smoke.sh           # build and verify the current upstream release
$ ./scripts/smoke.sh 0.65.0    # build and verify an exact version

smoke.sh runs the same verify-image.sh that CI runs against the same build, so a green smoke run means a green CI build.

Repository setup

The published package is public, and pulls need no authentication:

$ docker pull ghcr.io/routedbits/rustbgpd:latest

The package is linked back to this repo by the org.opencontainers.image.source label rather than by the repo name — the image is routedbits/rustbgpd, the repo is routedbits/container-rustbgpd.

Licensing

The packaging in this repository is MIT (see LICENSE).

rustbgpd itself is dual-licensed MIT OR Apache-2.0 by its authors, and both license texts are shipped inside the image at /LICENSE-MIT and /LICENSE-APACHE, extracted from the upstream release tarball.

About

rustbgpd in a container

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages