# Install OpenSequence in production (https://docs.opensequence.dev/docs/self-hosting/install)

How to install for production: build the one image, point it at your Postgres, run the api and worker roles with real secrets, create the first project.

This page takes you from a clone to a production install: one Docker image, a Postgres you own, an `api` role and a `worker` role. To try it on a laptop with mock providers, run `docker compose up` from a clone, as in the [Quickstart](/docs/get-started/quickstart).

```mermaid
flowchart LR
  APP["Your application"] -->|HTTPS, project key| API["api role, public"]
  EXT["Allo, mail clients"] -->|webhooks, opt-out links| API
  API --> PG[("Postgres")]
  W["worker role, private"] --> PG
  W -->|send, poll| P["Mail servers, Allo, Attio"]
  W -->|signed webhooks| APP
```

<Steps>
<Step title="Get the image">

```bash
docker pull ghcr.io/lguerberg/open-sequence:main
```

Every push to `main` publishes `ghcr.io/lguerberg/open-sequence:main` and `:sha-<commit>` (amd64). A release tag `v*` publishes `:<version>`, `:<major>.<minor>` and `:latest` for amd64 and arm64. Pin a `sha-` or version tag in production so a redeploy never changes the code under you. To build it yourself instead: `docker build -f apps/server/Dockerfile -t opensequence/server .` from a clone.

The image runs Node 22 on Alpine as the non-root user `oseq` (uid 100, gid 101). It starts `node dist/main.js`, listens on port 8080 and has a Docker `HEALTHCHECK` on `/healthz`. `NODE_ENV=production` is baked in. The operator CLI ships inside as `dist/cli.js`.

</Step>
<Step title="Provision Postgres">

Give OpenSequence its own database on Postgres 14 or newer. It needs no extensions. It creates and owns two schemas, `seq` and `seq_auth`, so it can share a database such as Supabase's. A transaction pooler is fine. See [Database](/docs/self-hosting/database).

</Step>
<Step title="Generate the secrets">

```bash
docker run --rm ghcr.io/lguerberg/open-sequence:main node dist/cli.js secrets new-key
# kmvb1mvo3:Y2ItLFqx5NZ9+b+jHrY01i2ZrnGE+pnxdoeMna58BzM=   -> SEQ_ENCRYPTION_KEYS
openssl rand -base64 32                                   # -> SEQ_ADMIN_TOKEN
```

`SEQ_ENCRYPTION_KEYS` encrypts every stored secret: each sender's SMTP and IMAP passwords, the Allo and Attio keys and the webhook signing secrets. `SEQ_ADMIN_TOKEN` is the operator token that creates projects.

<Warning>Back up `SEQ_ENCRYPTION_KEYS` with the database. A database restored without the key that encrypted it has unreadable credentials, and every one must be entered again.</Warning>

</Step>
<Step title="Run the api role">

```bash
docker run -d --name oseq-api -p 8080:8080 \
  -e SEQ_ROLES=api \
  -e SEQ_DB_DSN=postgres://oseq:secret@db.internal:5432/opensequence \
  -e SEQ_ENCRYPTION_KEYS='kmvb1mvo3:…' \
  -e SEQ_ADMIN_TOKEN='…' \
  -e SEQ_PUBLIC_URL=https://sequences.example.com \
  -e SEQ_RUN_MIGRATIONS=1 \
  ghcr.io/lguerberg/open-sequence:main
```

With `SEQ_RUN_MIGRATIONS=1` the process applies the `seq` and `seq_auth` migrations before it opens its port. Each migration runs in its own transaction behind a row lock, so replicas that start together do not race. If a migration fails, the process exits with code 1. To migrate from a pipeline instead, see [Upgrades](/docs/self-hosting/upgrades).

`SEQ_PUBLIC_URL` is the HTTPS origin the outside world reaches. Allo posts webhooks to it, and every email's unsubscribe link points at it. It defaults to `http://localhost:8080`, so always set it in production. The service speaks plain HTTP: put a TLS terminator in front.

</Step>
<Step title="Run the worker role">

```bash
docker run -d --name oseq-worker \
  -e SEQ_ROLES=worker \
  -e SEQ_DB_DSN=postgres://oseq:secret@db.internal:5432/opensequence \
  -e SEQ_ENCRYPTION_KEYS='kmvb1mvo3:…' \
  -e SEQ_PUBLIC_URL=https://sequences.example.com \
  ghcr.io/lguerberg/open-sequence:main
```

The worker runs the scheduler and the queue consumers. It needs no `SEQ_ADMIN_TOKEN`. It still listens on `SEQ_PORT` for `/healthz` and `/readyz`, but the API routes answer on that port too, so never expose it. It needs the same `SEQ_PUBLIC_URL` because it writes the unsubscribe links into emails.

For a small install, one container with `SEQ_ROLES=all` does both jobs. You can split it later without a migration.

</Step>
<Step title="Create the first project">

```bash
docker exec oseq-api node dist/cli.js projects create acme --name "Acme CRM"
# or over HTTP with the operator token
curl -X POST https://sequences.example.com/v1/admin/projects \
  -H "Authorization: Bearer $SEQ_ADMIN_TOKEN" -H "Content-Type: application/json" \
  -d '{"slug":"acme","name":"Acme CRM"}'
```

Both return the project and its first `admin` API key, shown once. Keep that key for configuration. Give your application a narrower key:

```bash
curl -X POST https://sequences.example.com/v1/api-keys \
  -H "Authorization: Bearer $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"app","scopes":["enroll"]}'
```

</Step>
<Step title="Register the providers">

With mock providers off, nothing is sent until the project has credentials. Each one is stored encrypted and is write-only.

| What you want | What to register |
|---|---|
| Email | each sender's SMTP and IMAP settings, Gmail included: [Email](/docs/modules/email) |
| SMS and call tasks | one Allo API key per project, then a number and user per sender: [Allo](/docs/modules/sms/allo) |
| `crm.*` conditions | one Attio API key per project: [Attio](/docs/modules/crm/attio) |

`GET /v1/project` shows the inbound webhook URL (`webhook_urls.allo`), built from `SEQ_PUBLIC_URL`.

</Step>
</Steps>

## Check it is healthy [#check-it-is-healthy]

| Path | Answers |
|---|---|
| `GET /healthz` | `{ "ok": true }` while the process runs. Use it for liveness |
| `GET /readyz` | `503` when the database does not answer. On `worker` and `all`, also `503` until the scheduler has run a job, and whenever it has not run one in the last 2 minutes |
| `GET /v1/admin/engine/health` | queue depths and the last run of every scheduler job, with the operator token |
| `GET /v1/engine/health` | the same plus the project's flags, with an `admin` key |

Logs are Pino JSON on stdout. See [Observability](/docs/self-hosting/observability).

## Next [#next]

<Cards>
<Card title="Configuration" href="/docs/self-hosting/configuration">Every SEQ_ variable, its default and when it is required.</Card>
<Card title="Security hardening" href="/docs/security/security-hardening">What to lock down before you expose the API.</Card>
<Card title="Deploy on Qovery" href="/docs/self-hosting/deploy-qovery">Two services from one Dockerfile and a managed Postgres.</Card>
<Card title="Deploy on Fly.io" href="/docs/self-hosting/deploy-fly">One fly.toml with api and worker process groups.</Card>
<Card title="Deploy on Kubernetes" href="/docs/self-hosting/deploy-kubernetes">Manifests for both roles, probes and a migration Job.</Card>
</Cards>
