---
title: "Deploy runbook"
description: "Staging and production on Dokploy at The Keep, rollback and backups."
url: https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/deploy-runbook
markdown: https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/deploy-runbook.md
---

# Deploy runbook

## What runs

Each environment is one Dokploy compose service built from `docker-compose.deploy.yml`: its own `postgres` (own volume), `api`, `worker` (pg-boss), `web`, `dashboard` and `docs`. Traefik terminates tls with Let's Encrypt. Dokploy projects: `lehoetel-staging`, `lehoetel-production` and `lehoetel-previews`.

| | staging | production |
| --- | --- | --- |
| trigger | every merge to `main` | published release (tag) |
| hosts | `staging-lehoetel`, `app-staging-lehoetel`, `api-staging-lehoetel`, `docs-staging-lehoetel` | `lehoetel`, `app-lehoetel`, `api-lehoetel`, `docs-lehoetel` |
| `SEED` | `demo` | `none` |
| `MESSAGING_LIVE` | `false` | `true` (a channel still needs its provider keys) |
| `ALLOW_PREVIEW_ORIGINS` | `true` | `false` |
| `S3_PREFIX` | `staging/` | empty |

All hosts are under `findmalek.engineer`. Health: the api answers `/health`, every image ships a docker `HEALTHCHECK`, the deploy job waits for the api `/health`.

## Set up from scratch

1. an api key for a Dokploy user (Dokploy UI, profile, api keys) as repo secret `DOKPLOY_TOKEN`, plus repo variables `DOKPLOY_URL`, `PREVIEW_DOMAIN`, `DOKPLOY_ENVIRONMENT_ID` (previews environment), `STAGING_API_URL`, `PRODUCTION_API_URL`
2. `DOKPLOY_URL=... DOKPLOY_TOKEN=... TARGET=staging ENVIRONMENT_ID=<env id> node .github/scripts/dokploy-bootstrap.mjs`, then again with `TARGET=production`. It creates the compose service, a random env (secrets, admin password) and the domains, and prints the compose id. Set it as variable `DOKPLOY_STAGING_COMPOSE_ID` or `DOKPLOY_PRODUCTION_COMPOSE_ID`. Re-running keeps the env of an existing service
3. add the provider keys (Resend, Kapso, S3, GlitchTip, OpenObserve) in the compose Environment tab, the keys are listed in `docker-compose.deploy.yml`
4. DNS: a CNAME per host to the server, plus `*.preview-lehoetel`

## Rollback

Run the `release` workflow by hand with an older tag. It points the production compose service at that tag and rebuilds it. Migrations only go forward: if a migration must be undone, restore the database from a backup first.

## Backups

The `backup` workflow dumps a database to an S3 bucket every night when `BACKUP_DATABASE_URL` and the bucket secrets are set. Dokploy can also back up each database to an S3 destination (Settings, S3 destinations, then the database Backups tab). No off-site S3 destination is configured yet, the only local copy lives on The Keep's disks, see [the keep](https://pr-179-docs.preview-lehoetel.findmalek.engineer/docs/infrastructure/the-keep.md). Before the pilot: add a destination (Backblaze B2, R2 or any S3), schedule the staging and production databases to it, and do one restore drill into a scratch database.
