DEV Community

ruthmoog
ruthmoog

Posted on

Deploying a project to fly.io with GitHub Actions

I have a citizen science mobile app project, which is hosted on fly.io. Here's how I used GitHub actions on my project repo to automatically deploy my code updates.


Generate your deploy token

Use the command line to generate a deploy token (Keep it secret!), required to push to your application, flyctl tokens create deploy. You can use the fly dashboard Tokens if you prefer GUI.

Deploy tokens are experimental, but unlike auth tokens they will manage a single application and its resources, as opposed to accessing all your apps.

"These kinds of tokens are an entirely new concept! We're still working out the kinks. We'll do our best, but we may have reset these tokens periodically while we get things right." -fly.io

You'll need to set the token as the FLY_API_TOKEN environment variable:



FLY_API_TOKEN=$(flyctl tokens create deploy) flyctl deploy

Enter fullscreen mode Exit fullscreen mode




Add the token to your repo

Your deploy token needs to be added as a Secret in your GitHub repo, so you can use it in your configuration without making the token public.

Go to Settings, Secrets and variables, Actions, and create a repository secret called FLY_API_TOKEN with your token value:

Name: FLY_API_TOKEN
Value: enter the auth token generated at the command line

Configure your workflow

My project has workflow actions set up for running tests and build, so I already have a .github directory in my project, with the workflows sub-directory inside:

.github folder

Replicate that set up in your project and add a new directory for you deployment workflow, I'll call mine deploy.yml. This is a YAML file which is used for our configuration.

The docs have an example template which you can customise for your project, remember to use the correct branch name.

Publish your workflow

When you commit and push your config YAML file to GitHub, it will automatically create the workflow in Actions.

Go to Actions and you should see your new "Fly Deploy" workflow, along with any workflow runs you have.

GitHub Actions screen

Verify this works in Fly, by going to your app dashboard, and checking the latest action is deployed with your last commit.
Every push to your configured branch will now be deployed to your fly application.

Top comments (0)