Initialization
In this section, you’ll create a new Laravel application, configure and deploy it as a Fly App, and finally add it to a GitHub repository.-
Start with a clean slate: create a new Laravel project and configure it as a deployable Fly app by using the
flyctllaunch command: -
Create a new github repository for your current Laravel Fly App. You can create one either through:
- GitHub Console - Visiting your create a new repository page in your console
- GitHub CLI - run the create repo command:
-
Finally, initialize your Laravel Fly App’s directory as part of a git repository, and point its remote to the recently created repository above
GitHub CI Action: Auto Deploy to Fly.io
Once you have your Laravel application set up with a github repository, you can configure some GitHub Actions to auto deploy your changes. In this guide, you’ll be usingFly.io’s very own GitHub action template here to help deploy your application.
-
Generate a
Fly tokenwithfly tokens deploy -
Then save your newly generated
FLY_API_TOKENin your github repository either through the GitHub Console or GitHub CLI:-
GitHub Console - Open your repository’s Settings tab, then add a secret named
FLY_API_TOKENunder the Secrets section. - GitHub CLI - run the command below
-
GitHub Console - Open your repository’s Settings tab, then add a secret named
-
Once you have your
FLY_API_TOKENsafely stored as a secret in your github repository, proceed with creating a GitHub workflow yml file in.github/workflows/main.yml:Let’s go through each line above, shall we?- name: Fly Deploy => This is the Workflow name
- on: [push] => Any push action to the repository triggers the current workflow
- env: `FLY_API_TOKEN` => Environment variable set for the GitHub Actions container
- jobs: => This is the list of jobs to run for the workflow
- name: Deploy app => Each job would have a name
- runs-on: ubuntu-latest => Each job would have an container environment we want to run its virtual machine on
- steps: => Each job would have a list of steps, see below:
- uses: actions/checkout@v2 => This is a pre-made GitHub Action. It allows checking out of your repository into the virtual machine spun up for the job
- uses: superfly/flyctl-actions/setup-flyctl@master => This is one of Fly.io’s pre-made GitHub action. It sets up `flyctl` in the virtual machine spun up for the job
- run: flyctl deploy => Need I say more?
-
Save and push your changes with:
- Visit the Actions tab of your repository and see how your deployment fares!