Deploying a public relay
compose.relay.yml turns compose.yml into a public relay: rim-server with the public relay's
quotas and proof-of-work signups, PostgreSQL 17 and Caddy terminating TLS, and no web client
unless the operator adds it. The relay holds its users' accounts, devices and cards, queues what
other servers send them and forwards their requests; it hosts no workspaces unless the operator
turns that on ("A relay that hosts a workspace"). This page brings a relay up for the first
time. The operator's runbook (docs/operations/relay-public.md) covers running it: keys,
backups, quotas, monitoring, incidents, the abuse policy and every command. docs/relay.md
explains what a relay does, and docs/specs/server-to-server-v1.md is the protocol.
A server that hosts workspaces uses compose.yml alone: docs/self-hosting.md covers it, and
its sections on updates, backups and monitoring apply to the relay too.
The project's public relay is relay.rim-platform.org, with its web client on
chat.rim-platform.org; yours uses your own domain. RIM_DOMAIN is the relay's host name, such
as a relay. subdomain: Caddy answers for that name only (and for RIM_WEB_DOMAIN when it is
set), so the apex of the domain can serve a website from elsewhere.
Before the first start #
A host with Docker (Compose v2.20 or later), ports 80 and 443 open, and DNS
A/AAAArecords of your domain pointing at it. Caddy gets the certificate from Let's Encrypt on the first request.Create
deploy/.env(Git ignores it;deploy/.env.examplelists every setting):cat > deploy/.env <<EOF POSTGRES_PASSWORD=$(openssl rand -base64 32 | tr -d '/+=') RIM_DOMAIN=relay.example.org RIM_VERSION=0.0.1 RIM_ROLE=relay RIM_CADDYFILE=./Caddyfile.relay EOF chmod 600 deploy/.envRIM_VERSIONis the release you run, the tag this checkout is at without itsv.RIM_PUBLIC_BASE_URLfollowsRIM_DOMAIN.RIM_ROLEandRIM_CADDYFILEsay what the relay is: a relay that serves the API alone, as here, or one that hosts a workspace with the web client (below). Every other setting has the public relay's value in the compose files; set it in.envto change it (the quotas are listed in the runbook). WithoutPOSTGRES_PASSWORD,RIM_DOMAIN,RIM_ROLEorRIM_CADDYFILEevery compose command stops and names it.Check the configuration. The commands on this page and in the runbook use this alias, from the repository root:
alias dc='docker compose -f deploy/compose.yml -f deploy/compose.relay.yml' dc config --services # postgres, migrate, rim, imagecheck, caddy-init, caddy: no web clientThe relay runs
ghcr.io/rim-platform/rim-server:<RIM_VERSION>(orRIM_SERVER_IMAGE) and its profile picture check,ghcr.io/rim-platform/rim-imagecheck:<RIM_VERSION>(orRIM_IMAGECHECK_IMAGE). Verify them asdocs/self-hosting.md, "Verify the images", says; both are signed by this repository's release workflow. To build them from this checkout instead, add-f deploy/compose.dev.ymlto the alias and useup --build; the relay needs no rim-ui checkout either way.
Start #
dc up -d
dc logs -f rim
The migrate service applies the migrations and exits; the server starts after it. On its
first start the server creates its key, writes /data/server-recovery-key.txt and logs a
warning about it at every start until the file is gone. Move it offline now, as the runbook's
"The server recovery key" says:
dc exec rim cat /data/server-recovery-key.txt
# copy the line to the offline places the runbook names, then:
dc exec rim rm /data/server-recovery-key.txt
Check it answers:
curl -s https://relay.example.org/.well-known/rim-server | head -c 300; echo
dc exec rim /app/rim-server server-key show
The descriptor in the discovery document says "registration":{"mode":"pow","powBits":24}.
A relay that hosts a workspace #
A relay can host workspaces too, as the project's relay does: it runs RIM_ROLE=both and
hosts the RIM community workspace, which every new account joins, with the web client. Four
settings in deploy/.env turn it on:
RIM_ROLE=both
RIM_CADDYFILE=./Caddyfile
COMPOSE_PROFILES=web
RIM_DEFAULT_WORKSPACE_FILE=/config/default-workspace.json
RIM_ROLE=both lets accounts here create workspaces, ./Caddyfile sends every path that is not
the API, discovery or server-to-server to the web client, and the web profile starts it.
dc config --services then lists web too. To serve the web client on a domain of its own,
as chat.rim-platform.org is, add RIM_WEB_DOMAIN ("The web client on its own domain" below).
RIM_DEFAULT_WORKSPACE_FILE makes deploy/default-workspace.json (mounted read-only at
/config/default-workspace.json) the server's default workspace; edit the file for your own.
Until somebody claims it, every start writes a single-use owner claim link to
/data/owner-claim.txt and logs that a claim is waiting. The first run, in short: start the
stack as above, then read the link, open it in a browser and sign up through it:
dc exec rim cat /data/owner-claim.txt
The signup creates the workspace with its channels, makes the account its Owner (and an
instance operator when the file says claimGrantsOperator), and deletes the file. A lost link
is a restart (dc restart rim), which revokes the old one. Later starts apply the file again:
new channels and topics arrive with the next release (docs/self-hosting.md, "A default
workspace").
The web client on its own domain #
With RIM_WEB_DOMAIN set, ./Caddyfile answers for a second domain too: the web client is
served there and calls the API on that same origin, and RIM_DOMAIN stays the server's name,
the one apps sign in to, other servers reach, and the discovery document names. A browser that
opens RIM_DOMAIN is redirected to the web domain with its path and query, so links the server
builds on RIM_PUBLIC_BASE_URL, such as invite and owner claim links, open the web client.
RIM_WEB_DOMAIN=chat.example.org # an A/AAAA record for it points at this host too
docs/self-hosting.md, "The web client on its own domain", says what the server accepts from
that origin.
Health, updates and operation #
The probes (/healthz, /readyz) and their checks are the same as on any server:
docs/self-hosting.md, "Monitoring". Caddy does not proxy them, so they are reachable from
inside the compose network only:
dc ps rim # healthy once /readyz passes
dc exec rim curl -s http://localhost:8080/readyz
Update as docs/self-hosting.md, "Updates", says, with the relay's files named for the backup:
COMPOSE_FILE=deploy/compose.yml:deploy/compose.relay.yml deploy/backup.sh
git fetch --tags && git checkout v<version>
$EDITOR deploy/.env # RIM_VERSION=<version>
dc pull && dc up -d
deploy/upgrade.sh <version> does the same after the checkout, with the signature check, the
migrations first and a rollback when the new version does not come up
(docs/operations/upgrade.md).
The operator's commands (/app/rim-server inside the rim container: invites that skip the
proof-of-work, principal and peer blocks, abuse reports, key rotation) are listed in the runbook,
"Command reference".
Unattended upgrades from releases #
A host that runs the published images needs no checkout: one directory holds the compose files,
the Caddyfiles, the scripts and .env, and rim-deploy keeps it on the latest releases of
rim-server and rim-ui, each on its own. On the project's relay that directory is
/srv/rim-server. Every five minutes rim-deploy.timer runs rim-deploy --check, which asks
the GitHub API for the latest published release of each repository that is not a pre-release,
rim-server first.
The server. When rim-server's version is not RIM_VERSION in .env, the check first
verifies with cosign that the version's rim-server image carries the signature of that tag's
release workflow, since the tag's files run as root: a tag without an approved release run
installs nothing. It reads the commit the tag points at (git ls-remote, nothing is cloned) and
requires the signature to come from the release workflow run at exactly that commit (cosign's
--certificate-github-workflow-sha), then downloads the source tarball of that commit: a tag
moved to another commit after the release fails the signature check and installs nothing. It copies the
commit's deploy/ files over the directory, writes SOURCE (the tag, the commit, the time and
the tarball's SHA-256) and runs their
upgrade.sh <version> there (docs/operations/upgrade.md): the signatures, the backup, the
migrations, the start and the rollback are its steps. A server upgrade leaves the web client at
the version it runs.
The web client. When the deployment runs the web service and rim-ui's version is not the
web client's (RIM_WEB_VERSION, else RIM_VERSION), the check verifies that
ghcr.io/rim-platform/rim-web:<version> carries the signature of rim-ui's release workflow of
that tag, keeps .env as .env.previous, writes RIM_WEB_VERSION=<version> into .env (and
the verified digest as RIM_WEB_DIGEST, when compose.yml reads it, so the image that runs is
the one that was verified), pulls the image and restarts the web container alone, nothing else. It waits up to 90 seconds
(RIM_UPGRADE_TIMEOUT) for the container to be healthy; when it is not, .env.previous comes
back and the web client from before starts again. There is no backup: the web client holds no
data. On files from releases whose compose.yml does not read RIM_WEB_VERSION yet it writes
RIM_WEB_IMAGE=ghcr.io/rim-platform/rim-web:<version> instead, which the next server release's
upgrade.sh turns into RIM_WEB_VERSION. A RIM_WEB_IMAGE of any other form is a custom web
image, and the deployer leaves the web client alone.
Nothing in GitHub reaches the host: it only reads from GitHub (the latest releases, the tag's
commit and the tarball). A release is published when its
release.yaml run is approved, so approving a release is the deployment; it runs within five
minutes, so approve it in a quiet hour.
The deployer writes nothing in .env but RIM_VERSION, the web client's version
(RIM_WEB_VERSION, or the RIM_WEB_IMAGE above) and the verified image digests
(RIM_SERVER_DIGEST, RIM_IMAGECHECK_DIGEST, RIM_WEB_DIGEST, which upgrade.sh writes too), keeps the file before each write as
.env.previous, and touches neither otherwise; every other file in the directory is the tag's, and the next deploy overwrites a file
edited on the host. Settings change in .env by hand, and so do the Upgrade: lines of
CHANGELOG.md, before the release is approved. When the upgrade does not complete, the files
from before come back.
Installing it, as root, with Docker (Compose v2.20 or later), cosign, git, curl and flock on the host:
mkdir -p /srv/rim-server # then write /srv/rim-server/.env, chmod 600
install -m 0755 deploy/rim-deploy.sh /usr/local/sbin/rim-deploy
install -m 0644 deploy/systemd/rim-deploy.service deploy/systemd/rim-deploy.timer /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now rim-deploy.timer
rim-deploy --check # "no release yet", or it deploys the latest releases
.env names the compose files for the scripts and for docker compose run in the directory,
relative to it: COMPOSE_FILE=compose.yml:compose.relay.yml for a relay. Leave RIM_VERSION
out before the first deploy, which then skips the backup (there is no data yet), starts the
stack and records the version. Set RIM_WEB_VERSION to a rim-ui release as well: left out, the
web client starts at the server's version, which rim-ui may not have released, and the deploy
waits for it. Later checks move the web client to rim-ui's latest release. rim-deploy is
installed by hand and changes rarely; when it does, install it again from the new release the
same way. RIM_DEPLOY_DIR names another directory.
- The log is
journalctl -u rim-deploy(-ffollows a deploy as it runs);systemctl list-timers rim-deploy.timershows the next check. Each check logs one line when there is nothing to do. - Not yet published images. When an image of a release is not out yet, the deploy changes
nothing (
upgrade.shexits 2); the check puts the files back, ends quietly, and the next one tries again. - Brakes. A release marked pre-release on GitHub is never deployed by the timer, which is
how a release is published without deploying it. The timer never rolls back either: a latest
release older than the version that runs is skipped, and an older version is deployed only by
hand.
touch /srv/rim-server/HOLDstops the timer deploying anything, server or web client, until the file is removed. A server deploy that fails writes its version toFAILED, a web client deploy that fails toFAILED-web, and the timer leaves that version alone until the file is removed; the next release deploys as usual. A check whose server deploy failed does not deploy the web client, and a check that failed in either part exits non-zero. - By hand.
rim-deploy <version>deploys that rim-server version andrim-deploy web <version>that web client version, without asking the API, forward or back, whetherHOLD,FAILEDorFAILED-webexist or not; withupgrade.sh, a server version older than the running one is a binary rollback. TouchHOLDbefore rolling back, or the next check deploys the latest releases again. - The unit runs as root, because it runs docker, with no new privileges, a read-only
/usr,/boot,/etcand home directories, and a private/tmp; cosign and the docker client keep their caches in/var/lib/rim-deploy. Av*tag starts the whole chain, and only the maintainer may push one to rim-server and rim-ui; an image the release workflows did not sign does not verify, and the deploy stops before it changes anything.
Metrics to Grafana Cloud #
compose.monitoring.yml on top turns on the server's metrics listener and adds a Grafana Alloy
collector (monitoring.alloy): every 15 seconds it scrapes the server's metrics (job rim),
probes /readyz (job rim-readyz) and reads the host's CPU, memory and filesystems (job
node), and remote-writes them to Grafana Cloud. Nothing new is published; the collector only
connects out. Add the three settings deploy/.env.example describes under "Monitoring" to
deploy/.env, then put the overlay in the alias:
alias dc='docker compose -f deploy/compose.yml -f deploy/compose.relay.yml -f deploy/compose.monitoring.yml'
dc up -d
dc logs alloy # no "level=error" once it scrapes and sends
Each compose service's CPU and memory use (job cadvisor) comes from a second overlay,
compose.monitoring-containers.yml, on rootful Docker on Linux. It runs cAdvisor behind a
Docker socket proxy and a containerd socket proxy that let it make only read-only calls;
docs/operations/metrics.md, "Container metrics", says which and what they still expose. It
covers the containerd image store, the default of a new Docker 29 install; on the older
overlay2 storage driver (docker info --format '{{.Driver}}') add
compose.monitoring-containers-overlay2.yml after it. Set DOCKER_GID in deploy/.env and
add the overlay after compose.monitoring.yml:
echo "DOCKER_GID=$(stat -c %g /var/run/docker.sock)" >> deploy/.env
alias dc='docker compose -f deploy/compose.yml -f deploy/compose.relay.yml -f deploy/compose.monitoring.yml -f deploy/compose.monitoring-containers.yml'
dc up -d
The dashboards and alert rules that read these series are in the
rim-monitoring repository;
docs/operations/metrics.md lists the metrics.
Another proxy #
Caddy is an example. Any TLS proxy works if it:
- passes
/api(with/api/wsas a WebSocket upgrade, and/api/remote/…),/s2s/v1/…and/.well-known/rim-servertorim:8080unchanged: no path rewriting, no compression, no body changes, since server-to-server requests and answers are signed over method, URL and body; - accepts request bodies up to 32 MiB;
- sets
X-Forwarded-Forto the client's address itself, replacing what the client sent, because the server trusts its first entry (RIM_TRUST_FORWARDED_HEADERS=true) for its per-IP limits and IP blocks, signups included; setsX-Forwarded-Proto; and dropsForwarded, which the server never reads for the address (the Caddyfiles useheader_up -Forwarded); - is the only way in: port 8080 is never published.
With nginx:
server {
listen 443 ssl;
http2 on;
server_name relay.example.org;
client_max_body_size 32m;
gzip off;
location ~ ^/(api(/|$)|s2s/v1/|\.well-known/rim-server$) {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Forwarded "";
proxy_read_timeout 1h;
}
}
($connection_upgrade is the usual map $http_upgrade $connection_upgrade { default upgrade; '' close; } in the http block.)