Deployment and operations
How a server runs eDGR, the release pipeline from backup to health check, schema changes, rollback, and publishing these docs.
A deployment is one Linux server with Docker, a checkout of this repository, and Caddy in front. Docker Compose runs the prod profile from the checkout: the backend and web app images, built on the server itself, plus Postgres, Redis and Restate. No image goes to a registry; the images exist only in the server’s Docker. A release builds new images beside the running ones, changes the database and swaps the containers, and a rollback points the containers back at the previous images.
The server's checkout is fast-forwarded to the commit being released. Nobody edits tracked files on the server, because a local change blocks the next fast-forward.
Server configuration
The two env files on the server differ from the examples in these ways.
| File | What changes |
|---|---|
.env | The prod profile as the default. The two app ports Caddy forwards to. The web app’s API address set to /api. Strong database credentials, set before the first start, because Postgres applies them only to an empty data folder. |
backend/.env | The public address of the web app, and the public address of the API ending in /api, which webhooks and tracking links use. A new value for every placeholder secret. A dedicated key for encrypting saved credentials. Real Unipile values and a webhook secret if LinkedIn is used. The file storage choice, with the S3 settings if files go to S3. |
Compose forces production mode and the in-network database, Redis and Restate addresses for the backend container, whatever backend/.env says. The web app calls the API on its own origin, so the allowed-origins setting needs no entry for it, but it must still hold one valid origin to pass the boot check.
Caddy’s configuration lives on the server, outside the repository. It terminates TLS and routes by path:
app.example.com {
handle_path /api/* {
reverse_proxy 127.0.0.1:3111 # backend port
}
handle {
reverse_proxy 127.0.0.1:7002 # web app port
}
}handle_path removes the /api prefix, which the backend has no route for.
The images
| Image | What is in it |
|---|---|
| Backend | Built with Node, run with Node. It carries the schema and the database command-line tool, so the schema push runs from it. It has no bun and none of the scripts, so seeds and agent evals cannot run in the prod container. |
| Web app | A static build served by nginx. The API address is fixed at build time, and an empty one fails the build. Hashed assets are cached forever and the HTML page is never cached. |
Compose tags both as latest on every build. The release tags the running pair first so there is something to roll back to. On a small disk, remove old tags and prune images once a release has proved itself.
Release commands
-
Update the checkout
Fast-forward the server’s checkout to the commit you are releasing.
-
Back up
On the serverstamp=$(date +%Y-%m-%d-%H%M) mkdir -p ~/backups/edgr-$stamp docker exec edgr-postgres pg_dumpall -U edgr | gzip > ~/backups/edgr-$stamp/db.sql.gz cp .env backend/.env ~/backups/edgr-$stamp/Use the database user from
.envif it is notedgr. When files are stored on disk, copy the uploads folder as well. The dump does not cover Restate’s state, which holds the campaign runs in progress. -
Tag the current images
On the serverdocker tag edgr-backend:latest edgr-backend:pre-$stamp docker tag edgr-frontend:latest edgr-frontend:pre-$stamp -
Build
On the serverdocker compose build -
Run new manual SQL
Run every manual SQL file that is newer than the last release, oldest first:
On the serverdocker exec -i edgr-postgres psql -v ON_ERROR_STOP=1 -U edgr -d edgr \ < backend/prisma/migrations-manual/<file>.sql -
Push the schema with the new image
On the serverdocker compose run --rm --no-deps -T backend node_modules/.bin/prisma db pushIf the push refuses a change that would lose data, stop and read the message. Either the release needs a manual SQL file nobody wrote, or the data loss is real.
-
Start and check
On the serverdocker compose up -d docker compose ps docker compose logs --tail=100 backendWait until the backend is
healthy, then run the checks in Health checking from outside the server.
Schema changes
The database has no migration history and records nowhere which SQL file ran. The schema push compares the database to the schema in the code and applies the difference, which is enough for a new table, column or index. A change the push would make by dropping and re-creating something that holds data needs a hand-written SQL file. That file runs first and leaves the database in the shape the new schema describes, so the push that follows finds nothing destructive to do.
- 1 New schema A change that would drop data
- 2 SQL file Moves the data into the new shape, in one transaction
- 3 Push Finds nothing destructive left
- 4 Record Newest file noted in the release notes
Each file is dated in its name and wraps its work in one transaction, and the command above stops at the first error. A file that already ran either changes nothing or fails and rolls back. Since nothing else records it, note the date of the newest file you ran in the release notes. The files so far split product credentials into a model credential and a list of senders, rescaled the fit criterion weights, created the event bus table, and let embedding columns hold vectors of any size.
Health checking
The API has no health route, so a 404 on /api/health is normal, and the Compose health check on the backend only tests that its port accepts connections.
| Check | Expect |
|---|---|
docker compose ps | The backend healthy, the others running or healthy |
| Backend log | The Restate handler listening, the Restate deployment registered, and Nest application successfully started |
curl -s -o /dev/null -w '%{http_code}' https://<host>/api/auth/me | 401: the request reached the backend and the token check refused it. A 502 means Caddy cannot reach the backend port. |
curl -sI https://<host>/ | 200, with Cache-Control: no-cache on the HTML |
| Sign in and open the inbox | The thread list loads and the stream connects |
When Restate refuses the registration, the backend exits on boot and Compose restarts it in a loop; docker compose logs restate backend shows why.
Browser tabs that were open during the deploy still run the old web app. When such a tab asks for a page chunk the new build no longer has, the app reloads the tab once.
Campaigns in flight
The backend re-registers its campaign handler with Restate on every boot, replacing the old registration at the same address. Runs that are waiting continue on the new code when they wake. Restate resumes a workflow by replaying the steps it has already recorded, so a release that reorders or renames the durable steps of the campaign workflow can break those runs on replay. Stop the affected campaigns, or let them finish, before you deploy such a change.
Rollback
Point latest back at the tagged images and start them without building:
docker tag edgr-backend:pre-<stamp> edgr-backend:latest
docker tag edgr-frontend:pre-<stamp> edgr-frontend:latest
docker compose up -d --no-buildThe images go back and the database stays as it is. A release whose schema push only added things leaves a database the old image can run against. If the release dropped or rewrote data, restore the dump into a fresh volume:
docker compose stop backend frontend
docker compose rm -sf postgres
docker volume rm edgr-postgres-data
docker compose up -d postgres
gunzip -c ~/backups/edgr-<stamp>/db.sql.gz | docker exec -i edgr-postgres psql -U edgr -d postgres
docker compose up -d --no-buildThe restore reports that the role and the database already exist, because the container creates both on an empty volume. The rest of the dump applies after those errors.
Publishing these docs
bash docs/scripts/deploy.sh # public build
DOCS_INTERNAL=true bash docs/scripts/deploy.sh # with this Developers tabThe script runs from the server’s checkout. It builds the site, refuses to publish a build that lacks its home page or its search index, keeps the live copy as the previous version, swaps the new one in, and restarts a small static file server, kept alive by pm2 behind its own Caddy site. When the check after the restart does not get a 200, it prints the commands to roll back.