How to setup continuous deployment on fly.io Django application?

Published 19 May, 2022

Reading time: 2 Mins


Automate flyctl deploy procedure by setting up CI/CD on Github Actions.

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

  1. Create a fly.io personal access token. This access token is the window to your account. Later in our program you can pass --token in flyctl to deploy into production.
  2. 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/[email protected]

        - uses: superfly/flyctl-actions/[email protected]

        - 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.

This article published under development on django tags. If you wish to receive email from me when I post a new blog post then please subscribe to my newsletter.


You might also like