We already have a guide: Continuous Deployment with Fly.io and GitHub Actions that you can read and follow. But we can make it simpler. And with flyctl version 0.2.80, we have done so.
The change we have made is that at fly launch
time:
- If your
.git/config
indicates that your project is hosted on GitHub or you have an existing.github/workflows
directory, we will add a Fly Deploy action. All you need to do isadd
andpush
it to get your project to automatically deploy on everypush
- If your
.git/config
indicates that your project is hosted on GitHub and you have the github CLI installed, we will also add the necessary flyctl deploy token as a GitHub secret to make this work.
This is perhaps easiest to understand with an example.
Step 1: install gh command line
Skip this step if you already have the GitHub CLI installed and configured.
brew install gh
… or go to https://cli.github.com/
And run:
gh auth login
Step 2: create an application, push to github, launch
This demo is Rails, but use whatever you are comfortable with:
rails new demo --css tailwind --main
cd demo
gh repo create --public --source=.
fly launch --no-deploy
Optional, but recommended; required if you are running Ruby 3.3.3:
bin/rails generate dockerfile --force
If you chose not to replace the Dockerfile, feel free to omit --no-deploy
and skip the next step.
Step 3: push to deploy
git add .
git commit -m 'initial commit'
git push --set-upstream origin main
Step 4: make a change and push to deploy
echo 'Rails.application.routes.draw { root "rails/welcome#index" }' \
>> config/routes.rb
git commit -a -m "add rails welcome"
git push