Deployment with Fly.io¶
Follow these steps to deploy your application using Fly.io:
Attention
Either
- copy the
deploy/fly.tomlfile to your project root directory - or append
-c deploy/fly.tomlto everyflycommand.
-
Change your
appname in thefly.tomlfile to something unique, e.g.your-unique-appto avoid conflicts with other people using the same name. -
Initialize your Fly.io app:
This creates a new app on Fly.io without deploying it yet. The
--ha=falseflag disables high availability mode, otherwise two machines are started. When going through the setup process, answernoto all question by pressingEnter. -
Import your environment variables. It is best to define a production
.env.prodfile, where all production related variables are set, includingDEBUG=FALSE. This way you you have a clean separation between local development and production deployment.This command imports all variables from your
.env.prodfile as secrets in Fly.io. -
Verify your secrets:
This lists all the secrets set for your Fly.io app.
-
If you want to access your site using the fly.io domain, make sure to add the domain to
ALLOWED_HOSTS(or simply change theDOMAINvariable to the fly.io domain). If not, follow the instructions in the Custom domain section. -
Deploy your application:
This command builds and deploys your application to Fly.io based on the
fly.tomlfile.
After completing these steps, your application should be live on Fly.io. You can access it using the URL provided by Fly.io in the terminal after deployment, or you can run fly open to open the app in your browser.
Note
If you want to deploy to a different region, change the primary_region in the fly.toml file, e.g. to dfw for Dallas, Texas (US).
Custom domain¶
To use a custom domain, you need to have a domain name and point it to the Fly.io domain.
-
Create a CNAME record in your DNS settings of your domain name:
Type Name Content CNAME @ your-unique-app.fly.dev -
Create a certificate for your domain name:
-
The cli will tell you to create a CNAME record that looks something like this:
Type Name Content CNAME _acme-challenge.yourdomain.com yourdomain.com.y1yzi5.flydns.net. Info
If you are using clouflare, do not proxy the
_acme-challengerecord, otherwise the certificate will not be issued. -
Wait for the certificate to be issued. You can check the status with:
Look for the
Issuedrow. It should saytrue. -
Done.
Continuous Deployment¶
DjipFast comes with a GitHub Actions worfklow to automate the deployment of your app.
The workflow is defined in .github/workflows/fly-deploy.yml. It expects a FLY_API_TOKEN to be set in the GitHub Actions environment.
-
Push your code to a private GitHub repository, if not already done.
-
To create your
FLY_API_TOKEN, run the following command in the terminal: -
Copy the output, including the
FlyV1and space at the beginning. -
Go to your newly-created repository on GitHub and select Settings.
-
Under Secrets and variables, select Actions, and then create a new repository secret called
FLY_API_TOKENwith the value of the token from step 2. -
Done.
This workflow is triggered on every push to the main branch. It can also be triggered manually by going to Actions, clicking Fly Deploy, and then Run workflow.
It builds the CSS, installs the dependencies and deploys the app to Fly.io.