Skip to content

Deploy to Fly

Deploy to Fly #149

Workflow file for this run

name: Deploy to Fly
on:
workflow_call:
workflow_dispatch:
push:
branches:
- main
jobs:
check-fly-secret:
runs-on: ubuntu-latest
outputs:
fly-secret-exists: ${{ steps.fly-secret-check.outputs.defined }}
steps:
- name: Check for Fly secrets availability
id: fly-secret-check
# perform secret check & put boolean result as an output
shell: bash
run: |
if [ "${{ secrets.FLY_API_TOKEN }}" != '' ] && [ "${{ secrets.FLY_APP }}" != '' ]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "defined=false" >> $GITHUB_OUTPUT;
fi
deploy:
name: Deploy app
runs-on: ubuntu-latest
needs: [check-fly-secret]
if: needs.check-fly-secret.outputs.fly-secret-exists == 'true'
steps:
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Install Task
uses: arduino/setup-task@v2
with:
# renovate: datasource=github-releases depName=go-task/task
version: 3.27.1
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rewrite secrets
run: |
#Remove old secrets
flyctl secrets unset GITHUB_TOKEN B2_APPLICATION_KEY B2_APPLICATION_KEY_ID B2_BUCKET ADMIN_TOKEN CF_ACCESS_KEY CF_ACCESS_KEY_SECRET CF_R2_ENDPOINT DATABASE_URL PUSH_INSTALLATION_ID PUSH_INSTALLATION_KEY PASS CF_TOKEN SMTP_USERNAME SMTP_FROM SMTP_PASSWORD DOMAIN --stage
#Set New Secrets
flyctl secrets set DATABASE_URL="${{ secrets.DATABASE }}" --stage
flyctl secrets set PUSH_INSTALLATION_ID="${{ secrets.PUSH_INSTALLATION_ID }}" --stage
flyctl secrets set PUSH_INSTALLATION_KEY="${{ secrets.PUSH_INSTALLATION_KEY }}" --stage
flyctl secrets set PASS="${{ secrets.PASS }}" --stage
flyctl secrets set CF_TOKEN="${{ secrets.CF_TOKEN }}" --stage
flyctl secrets set SMTP_USERNAME="${{ secrets.SMTP_USERNAME }}" --stage
flyctl secrets set SMTP_FROM="${{ secrets.SMTP_USERNAME }}" --stage
flyctl secrets set SMTP_PASSWORD="${{ secrets.SMTP_PASSWORD }}" --stage
flyctl secrets set DOMAIN="${{ secrets.DOMAIN }}" --stage
flyctl secrets set CF_ACCESS_KEY="${{ secrets.CF_ACCESS_KEY }}" --stage
flyctl secrets set CF_ACCESS_KEY_SECRET="${{ secrets.CF_ACCESS_KEY_SECRET }}" --stage
flyctl secrets set CF_R2_ENDPOINT="${{ secrets.CF_R2_ENDPOINT }}" --stage
flyctl secrets set ADMIN_TOKEN="${{ secrets.ADMIN_TOKEN }}" --stage
flyctl secrets set B2_APPLICATION_KEY="${{ secrets.B2_APPLICATION_KEY }}" --stage
flyctl secrets set B2_APPLICATION_KEY_ID="${{ secrets.B2_APPLICATION_KEY_ID }}" --stage
flyctl secrets set B2_BUCKET="${{ secrets.B2_BUCKET }}" --stage
flyctl secrets set GITHUB_TOKEN="${{ secrets.TOKEN }}" --stage
env:
FLY_APP: ${{ secrets.FLY_APP }}
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Checkout Repository
uses: actions/checkout@master
with:
ref: main
- name: Deploy app
run: |
flyctl deploy --now --no-public-ips -a $FLY_APP --no-cache
env:
FLY_APP: ${{ secrets.FLY_APP }}
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}