Skip to content

Running on Fly

deploy/fly.toml runs one copy of Lyra on Fly.io, with Postgres on Neon and uploaded files in Tigris, Fly’s S3-compatible storage. There’s no Redis and no server of your own to look after. This is how Lyra cloud runs.

docs.acme.com ──▶ Fly (HTTPS) ──▶ Lyra ──┬──▶ Neon (Postgres)
└──▶ Tigris (uploaded files)
Machine One shared-cpu-1x machine with 512 MB of memory, in Frankfurt (fra)
HTTPS Fly gets the certificate and sends every http request to https
Database changes Run as the release command, before each deploy starts the new version
Sleeping The machine is suspended when nobody has Lyra open, and wakes on the next request
Health check Fly calls /ready every 30 seconds
  1. Create a Postgres database on Neon and copy its connection string.

  2. Create the app, its storage and its secrets:

    Terminal window
    fly apps create <app> --org <org>
    fly storage create -a <app> -n <app>-files # sets the AWS_* secrets Lyra reads
    fly secrets set -a <app> --stage DATABASE_URL=... AUTH_SECRET=... GOOGLE_CLIENT_ID=... GOOGLE_CLIENT_SECRET=...

    AUTH_SECRET is at least 32 random characters. Add the secrets for the sign-in methods you want, and for email (SMTP_URL or SES_REGION, and EMAIL_FROM).

  3. In deploy/fly.toml, change app, APP_URL and S3_BUCKET to yours. Remove or change the other values under [env] that belong to Lyra cloud, such as OLD_APP_HOSTS and the links to its terms and privacy policy.

  4. Add https://<app>.fly.dev/api/auth/google/callback, or the same on your own domain, to the Google client’s redirect URIs.

  5. Deploy from the root of Lyra’s code:

    Terminal window
    fly deploy -c deploy/fly.toml --ha=false --build-arg APP_VERSION=$(git rev-parse --short HEAD) .

Every later update is the same fly deploy command. Settings lists everything else you can set, as secrets or under [env].

What’s different from one server with Docker

Section titled “What’s different from one server with Docker”
  • Background jobs only run while the machine is awake. Work that falls due while it sleeps waits until the next request wakes it.
  • There’s no Redis. Live events and rate limits stay in the one copy’s memory, so it must run as exactly one copy, which --ha=false in the deploy command makes sure of. To run more, see More than one machine.
  • Scripts run as a separate process. A command run with fly ssh console, such as users.ts or orgs.ts from Day to day, can’t tell the server about its changes live without Redis, so people may need to reload to see them.
  • Smaller database pool. fly.toml sets DATABASE_POOL_SIZE to 5.
  • Backups come from Neon and Tigris. Use Neon’s restore to an earlier point in time for the database, and back up the bucket for files, instead of the commands in Backups.