Skip to content

Deployment

Self-Hosting

Self-hosting Rebase means running two things: a Postgres database, and the official rebasepro/server image with your project’s bundle mounted into it.

There is no application image to build. Your project travels as a bundle, the runtime is published, and upgrading Rebase is a tag change rather than a rebuild. See Runtime and bundles for why it is split that way.

If your project came from rebase init, use its own docker-compose.yml. It is in your repository, init filled in its secrets, its first admin account and its pinned runtime version, and it is the file Deployment describes:

rebase build
docker compose up -d

The rest of this page is the same deployment without a scaffold behind it — somebody else’s project, a bundle built in CI, or the two things the generated file deliberately leaves out: a connection pooler and the split-process shapes. That one lives in the repository, at infra/docker/docker-compose.selfhost.yml. Use it rather than copying a snippet out of this page: both files are booted by the project’s own acceptance gate on every push, so neither can drift from what actually works.

The two agree on every environment variable except the database password, and that is because each is written for its own writer: this one reads POSTGRES_PASSWORD, which quickstart.sh generates; the generated one reads DATABASE_PASSWORD, which rebase init also embeds in the DATABASE_URL it writes into your .env.

rebase build # produces ./dist-bundle
./infra/docker/quickstart.sh # writes infra/docker/.env if absent, then brings it up

quickstart.sh is one command doing two obvious things and printing both. The long form, if you would rather own each step:

docker compose -f infra/docker/docker-compose.selfhost.yml \
--env-file infra/docker/.env up

You do not need to start the database separately — api waits on its healthcheck.

quickstart.sh generates these for you. To write the .env yourself:

cat > infra/docker/.env <<EOF
POSTGRES_PASSWORD=$(openssl rand -hex 32)
JWT_SECRET=$(openssl rand -hex 32)
REBASE_SERVICE_KEY=$(openssl rand -hex 32)
CORS_ORIGINS=https://app.example.com
REBASE_ADMIN_EMAIL=you@example.com
REBASE_ADMIN_PASSWORD=$(openssl rand -hex 16)
EOF

Three secrets, one fact, and the account you sign in with:

  • POSTGRES_PASSWORD — the database password. Changing it later means changing it in the volume too, so pick it once.
  • JWT_SECRET — signs every session. Rotating it signs everybody out.
  • REBASE_SERVICE_KEY — the credential that bypasses row-level security for server-to-server calls. Treat it like a root password: anything holding it can read every row.
  • CORS_ORIGINS — the origins your frontend is served from, comma-separated. Not a secret, and not optional: the runtime refuses to start in production without it rather than guessing, because an API that guesses its allowed origins eventually allows the wrong one.
  • REBASE_ADMIN_EMAIL / REBASE_ADMIN_PASSWORD — the first administrator. A fresh database has no users, and outside production the registration policy admits the first sign-up and promotes it to admin — otherwise an empty database is a dead end, because bootstrapping an admin needs a caller who is already signed in. The moment this stack answers on a hostname that convenience is a race the operator can lose, so in production the window is shut and the account is named here instead. The runtime creates it once, while the user table is empty, and does nothing on every boot after that.

JWT_SECRET and REBASE_SERVICE_KEY must each be at least 32 characters, and the admin password at least 12. Use an address with a dot in its domain: POST /auth/login parses its body with z.string().email(), so the runtime refuses to seed admin@localhost — an account nobody could sign in to — and logs why instead. The compose file declares all six with ${VAR:?…}, so a missing one stops the stack with a message naming it rather than starting something half-configured — and self-registration ships off (DISABLE_SELF_REGISTRATION, default true), so nothing is left to be claimed.

Sign in with those credentials and change the password: they are sitting in a file on the host.

rebase build installs your project’s dependencies into the bundle by default, so dist-bundle arrives with a node_modules and a package-lock.json beside its package.json. A vendored bundle starts in about five seconds.

Because they are already there, you can mount the bundle read-only — worth doing, since a compromised hook then cannot rewrite the code that runs after the next restart:

volumes:
- ./dist-bundle:/bundle:ro

rebase build --no-vendor opts out and produces a bundle that installs its dependencies on first start instead, which takes 40–60 seconds per start and needs the mount to be writable.

For a real deployment, prefer baking both into an image, which also pins exactly what runs:

FROM rebasepro/server:0.38.1
COPY dist-bundle /bundle

The runtime creates missing tables at boot, including the ones backend/schema declares. REBASE_MIGRATE_ON_BOOT defaults to ensure, which is additive across the whole schema: it creates missing tables, columns and enum types, and applies their row-level security. A first start against an empty database comes up serving your tables, with no separate step.

What ensure deliberately never does is change anything that already exists. It does not alter a column type, does not drop a table or a column, and does not edit an existing enum’s labels — because a container restart must not be able to reshape a schema as a side effect of a deploy.

So rebase db push is still worth running, for what boot leaves alone — any change that is not purely additive: a renamed column, a narrowed type, a removed field.

rebase db push

Run it from a checkout or a CI job, pointed at the deployment’s database. It dry-runs the change first, refuses destructive ones without explicit confirmation, and can take a backup before applying. The database publishes a port in the compose file so this can reach it from the host; remove that mapping once the schema is in place if the database should not be reachable from outside.

REBASE_MIGRATE_ON_BOOT accepts ensure and none, and nothing else — the image refuses to boot on push, for the reason above.

When only your change process may change the database

Section titled “When only your change process may change the database”

REBASE_MIGRATE_ON_BOOT=none leaves your tables alone. It does not leave the database alone: the framework’s own tables (auth, API keys, jobs, cron) are still created and kept current at every boot. When the database may only change through a reviewed change process, set REBASE_PROVISION=false on every process that serves:

Setting Declared tables and policies Framework tables
default (REBASE_MIGRATE_ON_BOOT=ensure) created and kept current at boot created and kept current
REBASE_MIGRATE_ON_BOOT=none left alone created and kept current
REBASE_PROVISION=false left alone left alone; whatever is missing is named in the log

With provisioning off the runtime creates and alters nothing: no table, column, index, function, trigger, policy, role or grant. That holds at boot and later, including the tables a serving process otherwise makes on first use (idempotency keys, cron claims, the shared rate-limit counters). It reads what is there instead:

  • Auth tables, or a column auth reads, missing: the boot refuses and lists each one.
  • The request role can reach a framework table such as rebase.refresh_tokens or rebase.api_keys: the boot refuses and prints the REVOKE to run. A provisioning boot takes those privileges away on its own. With provisioning off, nothing does.
  • An optional table missing (API keys, idempotency keys, cron claims, rate-limit counters, presence, metrics history): that feature is off, and the log says which table it needs.
  • A declared table the database does not protect — row-level security disabled, none of the policies it declares present, or a restrictive policy it declares missing: that table is not served (a missing permissive policy is served, with a boot warning naming it). A request for it answers 503 TABLE_WITHHELD, and the boot log names the SQL that protects it (or rebase db push). The other tables are served, and the boot goes on. A many-to-many junction is checked the same way: one the database does not protect withholds the tables whose relations use it, and TABLE_WITHHELD names the junction. A table whose via relation passes through a withheld table is withheld too, and the message names the relation. This holds with REBASE_MIGRATE_ON_BOOT=none too, and on a live schema refresh. A table whose access the app enforces itself says rlsRequired: false to be served anyway (how).

Rows still change, as they would on any database: sign-ins, sessions, API key usage, idempotency keys, cron claims. The first admin account (REBASE_ADMIN_EMAIL) is seeded by the provisioning run, not by the serving processes. Live schema editing can still commit a change as source, but refuses to apply it to the database.

The schema comes from a run your change process controls. Use the same image and bundle as the server, with REBASE_PROVISION_ONLY=true, connected as a role that may create in the database. REBASE_PROVISION_SQL_OUT keeps every schema change the run made, as a SQL script:

docker run --rm \
-e DATABASE_URL="postgres://admin:…@scratch-db:5432/app" \
-e JWT_SECRET="…" \
-e CORS_ORIGINS="https://app.example.com" \
-e REBASE_PROVISION_ONLY=true \
-e REBASE_PROVISION_SQL_OUT=/out/rebase.sql \
-v "$PWD/out:/out" \
-v "$PWD/dist-bundle:/bundle" \
"rebasepro/server:$REBASE_VERSION"

The image runs with NODE_ENV=production, so this run is held to the same environment checks as the server, CORS_ORIGINS or FRONTEND_URL included, even though it serves nothing.

The script is a record, not a plan: every statement in it ran, in order, and succeeded. Recorded against an empty database, it is the whole schema the release needs. Recorded against a restored copy of production, it is exactly the upgrade. Rows the run wrote are not in it. Review it, then apply it to the real database:

psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f out/rebase.sql

Do it again for every Rebase upgrade, before the serving processes roll. A release can add a table or a column, and a process that may not create one reports it missing rather than making it.

A server you build yourself follows the same rule: initializeRebaseBackend reads REBASE_PROVISION, and createRebaseBackend takes provision: false.

Storage is off unless a bucket is configured, and that is deliberate: the alternative default is the container filesystem, which silently loses every uploaded file on the next restart. Uploads are refused with 501 STORAGE_NOT_CONFIGURED until you set one up.

For a bucket, set STORAGE_TYPE=s3 (or gcs) plus its bucket and credentials — the compose file lists the variables, commented out. gcs loads @google-cloud/storage, which the official image does not ship, so on that image reach Google Cloud Storage through its S3-compatible endpoint instead (STORAGE_TYPE=s3, S3_ENDPOINT=https://storage.googleapis.com, HMAC keys).

For local disk, which is only appropriate when the path is a real volume that outlives the container:

STORAGE_TYPE: local
# Each declared bucket gets a directory beside this one, bucket("media")
# /storage/uploads__media, so the volume goes on their parent.
STORAGE_PATH: /storage/uploads
FORCE_LOCAL_STORAGE: "true"
volumes:
- storage:/storage

FORCE_LOCAL_STORAGE is not optional there: in production a local backend is dropped rather than registered, because the alternative is uploads that succeed into a filesystem about to be destroyed. The variable is how you say the mount is durable.

Mount the volume above STORAGE_PATH, not at it. STORAGE_PATH is the default bucket’s directory, and every bucket declared in backend/resources.ts gets its own beside it, <STORAGE_PATH>__<key>. A volume at STORAGE_PATH itself holds the default bucket only. Every other bucket writes to the container’s filesystem and loses its files when the container is recreated. STORAGE_PATH__MEDIA can move one bucket elsewhere on the volume. It cannot move it inside another bucket’s directory, such as /storage/uploads/media, because the default bucket would then list, serve and delete its files.

The image creates /storage for the unprivileged node user it runs as, which is why the volume goes there. A volume mounted where the image has no directory belongs to root, and every upload fails with EACCES. The compose file rebase init writes mounts it this way.

Once a bucket is configured, the runtime refuses to boot in production until the deployment states how objects are protected. Storage is not under row-level security and its keys share one flat namespace, so with no rule the only thing separating two users’ files is key unguessability — which GET /storage/list?prefix= defeats. Any one of these satisfies it:

  • a storageAuthorize hook (or storagePolicies) in your project’s config, which is what the scaffold ships in backend/storage.ts;
  • STORAGE_POLICIES, the same rules as JSON — “owner” for a folder per user, roles for admins (see Storage authorization);
  • STORAGE_PUBLIC_READ=true, for a bucket that genuinely is a public read-only CDN;
  • STORAGE_ALLOW_ANY_AUTHENTICATED=true, for a single-tenant app where every signed-in account is trusted with every file.

Outside production the same condition is a loud warning rather than a refusal, so this is a boot failure you meet on the deploy rather than on the laptop. It is deliberate: the failure it replaces is silent.

Set MFA_ENCRYPTION_KEY too if you use TOTP. Left unset, stored authenticator secrets are encrypted with JWT_SECRET — so rotating that signs everybody out and makes every enrolled device undecryptable.

The runtime is an ordinary container listening on $PORT, so anything that runs containers works. Two things to get right everywhere:

  1. The bundle must be present at /bundle (or wherever REBASE_BUNDLE points), with its dependencies installed beside it — see Dependencies.
  2. Set CORS_ORIGINS, JWT_SECRET and DATABASE_URL. The runtime refuses to start in production without them rather than guessing.
[build]
dockerfile = "Dockerfile" # FROM rebasepro/server:0.38.1 + COPY dist-bundle /bundle
[http_service]
internal_port = 8080
[[http_service.checks]]
path = "/livez"

Use the derived-image form above so the bundle ships with the app, then fly deploy.

Point the service at the derived image, set the environment variables, and set the health check path to /livez.

npm install -g @rebasepro/server @rebasepro/server-postgres
rebase-server /srv/myapp/dist-bundle

rebase-server --help lists the variables it reads. Under systemd:

[Service]
ExecStart=/usr/bin/rebase-server /srv/myapp/dist-bundle
Restart=always
Environment=NODE_ENV=production
Environment=DATABASE_URL=postgresql://rebase:...@127.0.0.1:5432/rebase
Environment=ALLOW_LOCALHOST_IN_PRODUCTION=true
Environment=JWT_SECRET=...
Environment=REBASE_SERVICE_KEY=...
Environment=CORS_ORIGINS=https://app.example.com
Environment=DISABLE_SELF_REGISTRATION=true
Environment=REBASE_ADMIN_EMAIL=you@example.com
Environment=REBASE_ADMIN_PASSWORD=...

NODE_ENV=production is not decoration. Left unset the process runs in development mode: it reflects localhost origins, serves the OpenAPI spec, and leaves the first-admin window open — so the first stranger to find the sign-up form becomes the administrator. The two REBASE_ADMIN_* lines are what replace that window; see Your first admin.

ALLOW_LOCALHOST_IN_PRODUCTION=true is there because the database is on the same machine. In production the runtime refuses any variable that points at localhost — in a container, loopback is the container itself, so that address is always a mistake — and this line tells it the address is meant. Drop it when the database runs elsewhere.

Prefer EnvironmentFile=/etc/rebase.env with the file at mode 0600 over Environment= lines for the secrets: a unit file is world-readable, and systemctl show prints every Environment= value.

The runtime holds its own small pool and needs no pooler. For everything else that talks to the same database and cannot hold a connection — serverless functions, scheduled scripts, a worker that scales out — the compose file ships a pgbouncer service behind the pooler profile. See Connection pooling.

Path Use for
/livez Liveness. Answers “is this process alive” without touching the database.
/health Readiness. Performs a database round-trip and reports latency.

Point liveness probes at /livez. A liveness probe on /health restarts a perfectly healthy process during a brief database hiccup, which is the opposite of what it is for.

REBASE_METRICS=true
REBASE_METRICS_TOKEN=<random string>

Exposes Prometheus metrics at /metrics: request counts and latency histograms broken down by API surface (data, auth, storage, functions) and table, plus process gauges. Without a token the endpoint is readable by anyone who can reach the port, so set one unless it is on a private network.

rebase_db_pool_wait_ms is a histogram of how long each query waited for a connection from the database pool, opening one included, labelled by data source key (source="(default)" in a project that declares no data sources). A healthy pool keeps it near zero. A tail that grows with traffic means requests are queueing for connections — most often held by write hooks that await something slow; see A hook holds a connection.

The database itself, per data source:

Metric What it says
rebase_db_pool_connections, rebase_db_pool_idle, rebase_db_pool_waiting Each pool’s connections, labelled pool="primary", "read" (the replica) or "session" (the SQL console’s direct pool behind a pooler). waiting above zero for long is a pool too small for its load.
rebase_db_connection_errors_total Requests answered 503 for want of a connection, by code: 53300 / 53400 (the server is out of connections), pool_exhausted, connect_timeout, unreachable.
rebase_db_connections Client connections on the server, by state, against rebase_db_max_connections.
rebase_db_size_bytes The database’s size.
rebase_db_replica_lag_seconds How far DATABASE_READ_URL is behind the primary.

The last four are sampled every 30 seconds on the instance’s own connection, so a scrape never becomes a query.

rebase_realtime_* reports each instance’s open sockets, channels and the frames it sent to the channel bus or held back: see Seeing what the bus does.

Every response carries X-Frame-Options: SAMEORIGIN, X-Content-Type-Options: nosniff, Referrer-Policy: strict-origin-when-cross-origin and Strict-Transport-Security: max-age=15552000 (180 days). The HSTS header leaves out includeSubDomains: that would tell browsers to refuse plain HTTP on every subdomain of your domain, including ones this server has nothing to do with, and a browser keeps it for as long as the header says. Set REBASE_HSTS_INCLUDE_SUBDOMAINS=true when every subdomain is HTTPS-only.

strict-origin-when-cross-origin is the browsers’ own default: a request to another site carries your origin and never the page’s path or query. It is not no-referrer because origin checks need the origin — the Google sign-in button compares it with the OAuth client’s authorized JavaScript origins, and under no-referrer it answered “The given origin is not allowed for the given client ID” on every app, whatever the client allowed. A response that sets its own policy keeps it (the MCP consent page sends no-referrer); a page that wants a stricter one can say so with <meta name="referrer" content="no-referrer">. X-Frame-Options works the same way: SAMEORIGIN unless the response sets its own, as the MCP consent page does with DENY.

The static apps — the CMS admin and any frontend the bundle serves — also carry Content-Security-Policy: frame-ancestors 'self'; object-src 'none'; base-uri 'self'. It decides who may frame the app, rules out plugins and pins <base> to your origin, and restricts nothing else, so inline scripts, workers and third-party sign-in keep working. A response that sets its own policy keeps it. For anything stricter, put the policy on the reverse proxy in front.

frame-ancestors 'self' means only a page on the app’s own origin can put it in an iframe. A CMS on admin.example.com that previews the site on www.example.com needs the site to allow it, with frameAncestors on the site’s app in rebase.json:

"site": {
"type": "static", "root": "site", "output": "site/dist", "path": "https://www.example.com",
"frameAncestors": ["https://admin.example.com"]
}

The site is then served with frame-ancestors 'self' https://admin.example.com, and so is any route of the site whose function sends no policy of its own. The other apps keep 'self'. X-Frame-Options: SAMEORIGIN is still sent beside it; a browser that reads frame-ancestors ignores X-Frame-Options, as the CSP specification requires.

Each entry is one origin, written exactly: https:// with a hostname and an optional port, or http:// for localhost, 127.0.0.1 and [::1] while you develop. There is no wildcard, no path and no keyword — 'self' is always on the list, and anything else is refused by the CLI and again by the runtime before it reaches the header. Nothing is allowed unless you name it.

One container is the default and needs nothing more. Before a second replica takes traffic — or a rolling deploy runs two side by side — go through Running more than one instance: rate limits, broadcast channels, local files, resumable uploads and the image cache are per process until a setting shares them.

One command adds this server to the Rebase connector, the single MCP connector that reaches all your projects from Claude:

rebase cloud connect https://your-app.com

Set the two variables it prints on this server and restart it. The server must run Rebase 0.28.1 or later and answer over https at a public address. Nothing else changes: it holds no secret, and it grants the connector what Studio would.

Everything above is one container serving the whole project, which is the right shape for almost every deployment. When a custom function should stop competing with the data API for the event loop — or should scale, restart and fail on its own — the same image and the same bundle can be booted as several cooperating processes. See Split processes.

image: rebasepro/server:0.38.1

Restart. Your bundle is unchanged. Within a runtime contract major, a bundle that validated keeps working — see Compatibility.