Skip to content

Deploy to Fly via GitHub action

New Course Coming Soon:

Get Really Good at Git

Fly.io is a very cool cloud hosting platform but one thing I miss is automatic deploy when I do a GitHub commit, as the services are not linked to GitHub.

To add CD (Continuous Deployment) to Fly.io we need to create a GitHub action.

I suppose you already have a Fly app running and a fly.toml file in your repo like I describe in https://flaviocopes.com/dockerfile-to-run-astro-node-ssr-on-flyio/)

In your project repo, create .github/workflows/fly.yml

name: Fly Deploy
on:
  push:
    branches:
      - mod12
jobs:
  deploy:
    name: Deploy app
    runs-on: ubuntu-latest
    concurrency: deploy-group
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - uses: superfly/flyctl-actions/setup-flyctl@master
      - run: flyctl deploy --remote-only
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

I took this from https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ but updated the checkout version to v4 and added the setup-node step to setup Node 20, as the repo is an Astro site and I want it to use LTS Node.

Make sure you set the name of the branch you want to deploy (in this example, I deploy a branch named mod12).

In your terminal run

fly tokens create deploy -x 999999h

to generate the Fly token and add it to the actions secrets in GitHub:

Call the secret FLY_API_TOKEN and enter the value you got from fly tokens...

Push to GitHub, you’ll see your action running:

You can see all the details of the action by clicking it:

In the jobs tab you can see what happened in the build:

Go on Fly, you’ll see the action was successful:

and the app is deployed on every commit.

All your deploys also have a “check” now to indicate that the action was successful (or not)

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: