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)
→ I wrote 17 books to help you become a better developer, download them all at $0 cost by joining my newsletter
→ JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025