Skip to content

Deploy to Fly via GitHub action

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)


download all my books for free

  • javascript handbook
  • typescript handbook
  • css handbook
  • node.js handbook
  • astro handbook
  • html handbook
  • next.js pages router handbook
  • alpine.js handbook
  • htmx handbook
  • react handbook
  • sql handbook
  • git cheat sheet
  • laravel handbook
  • express handbook
  • swift handbook
  • go handbook
  • php handbook
  • python handbook
  • cli handbook
  • c handbook

subscribe to my newsletter to get them

Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.

Related posts about services: