I’d like to deploy a new fleet of fly applications for each PR I have open on GitHub. These will be set up and torn down via GitHub actions.
I’d like to have a per-PR parent domain like pr-15.bazbar.dev and hang everything off it. So if I have www and api apps, I’d expect them to be available at www.pr-15.bazbar.dev and api.pr-15.bazbar.dev, respectively.
I know how to do this using Terraform and Route 53, but that combo is way too 2020 for this project. If possible I’d like to do this completely within fly.
A few questions:
Can I have fly manage the entire DNS zone?
If so, what nameservers should I set with my registrar?
How do I set up and tear down the PR-specific “subdomain” using flyctl (or the GraphQL API)?
How do I bind the www application to www.pr-15.bazbar.dev (again using flyctl or the GraphQL API)?
The fly domains and fly dns-records commands are probably what you want. These are very beta, but they might have what you need. The big limitation is DNS records – our CLI won’t do individual DNS records, it just imports entire zone files. So you’d have to somehow manage a zone file to make this work with DNS.
If I were you, I’d do this with a proxy and some wildcard domains. You could create PR apps with a naming convention:bazbar-www-pr15.fly.dev and bazbar-api-pr15.fly.dev
Then a proxy app that knows how to map a subdomain to a fly app name:
pr15.www-pr.bazbar → bazbar-www-pr15.fly.dev
pr15.api-pr.bazbar → bazbar-api-pr15.fly.dev
Then you can add wildcard certificates to the proxy app (*.www-pr.bazbar.com and *.api-pr.bazbar.com). This could be simpler than DNS shenanigans.