Manual application deployment using GitHub Actions
Did you know that you can configure your workflows to run only when manually triggered through the Actions tab on GitHub, GitHub CLI, or the REST API?
Did you know that you can configure your workflows to run only when manually triggered through the Actions tab on GitHub, GitHub CLI, or the REST API?
An everyday use case for this feature is when you have multiple environments running your application and wants to release a branch to a specific environment.
Here is a basic recipe for that purpose, making use of workflow_dispatch
and event inputs.
name: Deploy
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy'
required: true
default: 'staging'
jobs:
deploy:
name: Deploy to ${{ github.event.inputs.environment }}
runs-on: ubuntu-latest
env:
FLY_APP_CONFIG: ${{ github.workspace }}/${{ fromJSON('{"staging":"fly.staging.toml","production":"fly.production.toml"}')[github.event.inputs.environment] }}
FLY_APP_NAME: ${{ fromJSON('{"staging":"myapp-staging","production":"myapp-production"}')[github.event.inputs.environment] }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Fly.io CLI
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Run Fly Doctor
run: flyctl doctor
- name: Deploy the application to Fly.io
run: |
echo "Deploying to $FLY_APP_NAME with config $FLY_APP_CONFIG"
flyctl deploy --remote-only
Here I'm giving you an illustration of what could be a very basic workflow to deploy an app to Fly.io.
Also, as food for thought, I'm showing how you could grab different configuration files or values (env
section) using the environment input. Then, you can elaborate on the deploy command, applying these values to build the command line and ship your software to the right environment using the correct configuration.
Since it is possible to trigger workflows like this using REST API, you can go above and beyond, connecting with your existing tools and processes.