~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A container image for the server, and how to deploy it

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:deploy/container
.dockerignorenew+7−0
@@ -0,0 +1,7 @@
target
**/node_modules
web/dist
harness
bench
compat
.git
Dockerfilenew+40−0
@@ -0,0 +1,40 @@
# The server as a container image: `pds serve`, listening on every address
# of the container's network, its data on the volume /data, run as a user
# of its own. The rest of its environment is the operator's (README,
# "Deploying").
#
# docker build -t spec-pds .
# docker run -p 2583:2583 -v pds-data:/data --env-file pds.env spec-pds
#
# The image is the `pds` binary alone: `pds <group> <command>` in it is the
# CLI, as anywhere.
# The authorization pages, which pds-server embeds as it compiles.
FROM node:24.22.1-trixie-slim AS web
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY web/ ./
RUN npm run build
# The toolchain the gates build with (.knotless/workflows/gates.yml).
FROM rust:1.98-trixie AS build
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
COPY .cargo .cargo
COPY crates crates
COPY spec spec
COPY --from=web /src/web/dist web/dist
RUN cargo build --release --locked -p pds
FROM debian:trixie-slim
RUN useradd --system --uid 10001 --home-dir /data pds && mkdir /data && chown pds:pds /data
COPY --from=build /src/target/release/pds /usr/local/bin/pds
USER pds
# `::` takes IPv4 too on Linux, and is the address a network of IPv6 alone
# (as Railway's private one) reaches; `0.0.0.0` where the kernel has no IPv6.
ENV PDS_PORT=2583 PDS_BIND_ADDRESS=:: PDS_DATA_DIR=/data
VOLUME /data
EXPOSE 2583
ENTRYPOINT ["pds"]
CMD ["serve"]
README.md+41−6
@@ -22,6 +22,7 @@ and the server's whole repository verified with the reference's own library.
| `crates/pds-server` | the PDS: XRPC, the firehose and the MCP endpoint, over `pds-repo`, `pds-store` and `pds-lexicon`; `lib.rs` routes and dispatches each call to its area's module (`server.rs`, `sessions.rs`, `email.rs`, `lifecycle.rs`, `repo.rs`, `sync.rs`, `federation.rs`, `identity.rs`, `blobs.rs`, `invites.rs`), beside the firehose (`events.rs`), the MCP endpoint (`mcp.rs`), the OAuth authorization server (`oauth.rs`), whose pages (`oauth/page.rs`) are the build of `web/` that `build.rs` embeds at compile time and `oauth/assets.rs` serves, the PLC directory (`plc.rs`), the limits every call meets (`limits.rs`), the logs it starts again from (`log.rs`), their generations, compaction and the backfill window (`store.rs`), an account's checkpoint (`checkpoint.rs`) and the service log's (`compact.rs`) |
| `crates/pds-cli` | the CLI: each method as a command, a client of a running server |
| `crates/pds` | the one binary: `pds serve` runs the server, `pds <group> <command>` the CLI; its allocator is jemalloc, built by `.cargo/config.toml` to give freed memory back at once, so that resident memory follows what is in use (`spec/STORE.md`, "Scale") |
| `Dockerfile` | the server as a container image ("Deploying", below) |
The Rust is one workspace, laid out flat: every crate one level down in
`crates/`, in a directory named as the crate, under a root `Cargo.toml` that
@@ -165,12 +166,6 @@ server's starts. The `nightly` workflow runs them on `main`'s tip every
night at 10:00 UTC, and when the owner asks for it
(`knotless run rerun --ref main --workflow nightly`).
The server listens on `127.0.0.1` unless `PDS_BIND_ADDRESS` names another
address (`0.0.0.0` or `::` for a container's network; `spec/PDS.md`).
Behind a reverse proxy, set `PDS_TRUSTED_PROXIES` to the proxy's addresses:
the server reads `X-Forwarded-For` only from those peers, so without it
every client shares the proxy's rate limits (`LIMITS.md`).
To compare the server with the reference by hand:
```sh
@@ -214,6 +209,46 @@ pds.js.
just compat # cd harness && node bench.mjs --setup && node compat.mjs --steps 200 --json ../compat/results.json
```
## Deploying
`Dockerfile` builds the server as an image: the pages, then `pds` with the
gates' toolchain, on Debian slim, run as a user of its own, with
`PDS_PORT=2583`, `PDS_BIND_ADDRESS=::` and `PDS_DATA_DIR=/data`, a volume.
`docker stop` sends SIGTERM, which shuts the server down within Docker's
10 seconds (`spec/OPERATIONS.md`).
```sh
docker build -t spec-pds .
docker run -d -p 2583:2583 -v pds-data:/data --env-file pds.env spec-pds
```
Outside a container, the server listens on `127.0.0.1` unless
`PDS_BIND_ADDRESS` names another address (`spec/PDS.md`). Either way it
speaks plain HTTP: TLS is the reverse proxy's. Behind one, set
`PDS_TRUSTED_PROXIES` to the proxy's addresses: the server reads
`X-Forwarded-For` only from those peers, so without it every client shares
the proxy's rate limits (`LIMITS.md`). `/metrics` is on `127.0.0.1` alone,
so in a container only what runs in it can scrape it.
What a server on the network is given, besides those (each variable's page
says the rest):
| Variable | Is |
| --- | --- |
| `PDS_HOSTNAME`, `PDS_PUBLIC_URL` | its host name, and its `https://` URL |
| `PDS_HANDLE_DOMAINS` | the domains its accounts' handles end in, as `.example.com`; each handle's own host must reach the server for `/.well-known/atproto-did`, so a wildcard DNS record and certificate |
| `PDS_PLC_URL` | `https://plc.directory` |
| `PDS_PLC_ROTATION_KEY_HEX` | a new secp256k1 key (`openssl rand -hex 32`), in a secret store: whoever holds it controls every account's DID |
| `PDS_RECOVERY_DID_KEY` | a `did:key` whose private key is kept offline, so the DIDs outlive a lost or stolen rotation key |
| `PDS_EMAIL_SMTP_URL`, `PDS_EMAIL_FROM` | the mail server, and the address mail is from |
| `PDS_ADMIN_PASSWORD`, `PDS_INVITE_REQUIRED` | the admin's password; `true` unless anyone may sign up |
| `PDS_CRAWLERS` | the relays told of it, as `https://bsky.network` |
| `PDS_BSKY_APP_VIEW_URL`, `PDS_BSKY_APP_VIEW_DID`, `PDS_BSKY_APP_VIEW_CDN_URL_PATTERN` | `https://api.bsky.app`, `did:web:api.bsky.app` and `https://cdn.bsky.app/img/%s/plain/%s/%s@jpeg`, for the Bluesky app |
`PDS_DEV_MAIL_DIR`, `PDS_OAUTH_CLIENT_FETCH` and
`PDS_DISABLE_SSRF_PROTECTION` are for development, never for a server on
the network.
## Checks
Besides the harness and the tests, the source itself is held to these, the