Fly.io
Deploy the production image to Fly.io with fly.toml, with migrations as the release command.
fly.toml deploys the production image to Fly.io.
A project with a frontend and its API can't use this option yet: it deploys on any container host or Railway. Nor can a project without a website, whose API deploys on any container host or Railway: the CLI refuses this option for it.
pnpm clubedge deploy does these steps for you, databases included.
What fly.toml sets
- Build: the root
Dockerfile. With Next.js, setNEXT_PUBLIC_APP_URLunder[build.args], since Next.js compiles it into the build. - Release command:
node /app/migrate.mjsruns in a temporary machine with the new image, before it replaces the running one. A failed migration stops the deploy. - HTTP service: port 3000 with HTTPS forced, machines that stop when idle and start on the next request, and a check on
/api/healthevery 30 seconds. - VM: 512 MB of memory.
- Client address:
CLIENT_IP_HEADER = "fly-client-ip"under[env], since Fly's proxy puts each client's address inFly-Client-IP(Starter v0.27.0 or newer).
Deploy by hand
Install Fly's CLI and sign in with fly auth login, then:
fly launch --no-deploy # creates the app; keep the existing fly.toml
fly secrets set DATABASE_URL="postgresql://..."
fly deployfly launch adds the app's name and region to fly.toml; commit it. Set the other production variables with fly secrets set. For a database on Fly, create Postgres and attach it with fly postgres attach, which sets DATABASE_URL; with cache redis, fly redis create gives you Upstash Redis.
Background jobs
Fly runs the app as a long-lived server, so the jobs worker runs with it. Machines that stop when idle stop the worker too: set min_machines_running = 1 in fly.toml when jobs must run on time.
The deploy workflow
The Deploy job runs flyctl deploy --remote-only: Fly's builders build the image, and the release command runs the migrations before the switch. It needs the secret FLY_API_TOKEN, from fly tokens create deploy.
How is this guide?