Skip to content

add action to create PR-specific apps #23

add action to create PR-specific apps

add action to create PR-specific apps #23

Workflow file for this run

name: Fly Deploy Disctictr V2 PR
on:
pull_request:
types: [opened, reopened, synchronize, closed]
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
FLY_REGION: "iad"
FLY_ORG: "mggg"
jobs:
staging_app:
runs-on: ubuntu-latest
concurrency:
group: pr-${{ github.event.number }}
environment:
name: pr-${{ github.event.number }}
url: ${{ steps.deploy-app.outputs.url }}
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
# list fly apps
- name: confirm fly auth
id: print-fly-auth
run: flyctl auth whoami
env:
FLY_API_TOKEN: ${{ secrets.FLY_DB_API_TOKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
# copy the db
- name: Get DB Volume ID
id: get-db-volume-id
run: |
volume_info=$(flyctl volumes list -a districtr-v2-db -j)
volume_id=$(echo "$volume_info" | jq -r '.[0].id')
echo "volume_id=$volume_id" >> $GITHUB_ENV
env:
FLY_API_TOKEN: ${{ secrets.FLY_DB_API_TOKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: Get Latest Snapshot ID
id: get_snapshot_id
run: |
snapshot_info=$(flyctl volumes snapshots list ${{ env.volume_id }} -j)
snapshot_id=$(echo "$snapshot_info" | jq -r '.[0].id')
echo "snapshot_id=$snapshot_id" >> $GITHUB_ENV
env:
FLY_API_TOKEN: ${{ secrets.FLY_DB_API_TOKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: Get Image Version
id: get_image_version
run: |
image_version=$(flyctl image show -a districtr-v2-db -j | jq -r '.[0].Version')
echo "image_version=$image_version" >> $GITHUB_ENV
env:
FLY_API_TOKEN: ${{ secrets.FLY_DB_API_TOKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: Create DB from snapshot
id: create-db-snapshot
run: |
flyctl postgres create \
--name pr-${{ github.event.number }}-db \
--snapshot-id ${{ env.snapshot_id }} \
--initial-cluster-size 1 \
--vm-size shared-cpu-1x \
--org mggg \
--volume-size 1 \
--region iad
env:
FLY_API_TOKEN: ${{ secrets.FLY_ORG_TOTKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
# then create copies of the app and api
- name: Deploy API
id: deploy-api
uses: superfly/[email protected]
with:
name: pr-${{ github.event.number }}-api
postgres: pr-${{ github.event.number }}-db
- name: Deploy App
id: deploy-app
uses: superfly/[email protected]
with: pr-${{ github.event.number }}-app