Staging vs production environnement with the same code base

Say, you create two Fly apps (with flyctl launch or flyctl apps create), devdw-app-test and devdw-app-prod and add corresponding entries for it in fly.toml.

If staging and prod use same fly.toml but different dockerfiles, you’d do:

# for staging
flyctl deploy -c fly.toml -a devdw-app-test --dockerfile /path/to/dockerfile-test
# for prod
flyctl deploy -c fly.toml -a devdw-app-prod --dockerfile /path/to/dockerfile-prod

If staging and prod use the same dockerfile but different fly.toml (with app name predefined in the toml itself), you’d do:

# for staging
flyctl deploy  --dockerfile /path/to/dockerfile -c fly.staging.toml
# for prod
flyctl deploy  --dockerfile /path/to/dockerfile -c fly.prod.toml

and so on…

Fly is working to make multi-environment deploys easy still: Feedback/requests from a Rails perspective: apps grouped with a shared deployment story, one-off apps/machines, and pipelines - #2 by Brad

See also: Managing multiple environments - #14 by indirect

Ref docs: Monorepo and Multi-Environment Deployments · Fly Docs

Here’s a codebase that I deploy to four different Fly apps, for reference (check out the .tomls, .dockerfiles, and .github/workflows): GitHub - serverless-dns/serverless-dns: The RethinkDNS resolver that deploys to Cloudflare Workers, Deno Deploy, Fastly, and Fly.io

2 Likes