Yesterday I posted about how to deploy your Django application into fly.io and make use of their free tier. Today I’m going to explain about how we can setup the continuous integration so that whenever developer push their code it will deploy automatically instead of the manual flyctl deploy
steps.
I’m going to use Github Actions for this. Github actions is really easy for CI/CD. I only going to use deploy steps now.
Prerequisite
- Create a fly.io personal access token. This access token is the window to your account. Later in our program you can pass
--token
inflyctl
to deploy into production. - Go to GitHub Settings and add your personal access token that you generated in the first steps to action secrets.
- FLY_API_TOKEN
- OTHER_SECRET_KEY_THAT_ARE_IMPORTANT
Setup Github Actions
To setup Github actions you have to create the .github/workflows
folder in your project root folder. After you created the folder, create main.yml
file.
Inside the file you can place this below content.
name: Fly Deploy
on: [push]
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only --app gaclient
You can see that we can access the personal access token by calling ${{ secrets.FLY_ACCESS_TOKEN }}
and this setup will run on each main branch pushes.
Check your logs in the fly.io if somethings is broken.