Skip to content

Base Infrastructure Setup with Fly.io Foundation (#18) #1

Base Infrastructure Setup with Fly.io Foundation (#18)

Base Infrastructure Setup with Fly.io Foundation (#18) #1

Workflow file for this run

# ABOUTME: GitHub Actions workflow for automated Fly.io deployment
# ABOUTME: Follows Fly.io best practices with simple flyctl deploy commands
name: Deploy to Fly.io
on:
push:
branches: [main]
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.38'
- name: Install Test Dependencies
run: cpanm --quiet --notest Test2::V0
- name: Run Infrastructure Tests
run: prove -v t/
setup-infrastructure:
name: Setup Infrastructure
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Setup Perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.38'
- name: Create PostgreSQL Database
run: |
# Check if magnet-postgres already exists
if ! flyctl apps list | grep -q "magnet-postgres"; then
echo "Creating PostgreSQL database..."
flyctl postgres create --name magnet-postgres --region ord --initial-cluster-size 1
else
echo "PostgreSQL database already exists"
fi
- name: Create Volumes
run: perl scripts/create-volumes.pl --production
- name: Setup Deploy Tokens
run: perl scripts/setup-deploy-tokens.pl
deploy:
name: Deploy Applications
runs-on: ubuntu-latest
needs: setup-infrastructure
strategy:
matrix:
include:
- app: magnet-9rl
config: servers/magnet-9rl/fly.toml
region: ord
- app: magnet-1eu
config: servers/magnet-1eu/fly.toml
region: ams
- app: magnet-atheme
config: servers/magnet-atheme/fly.toml
region: ord
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Attach PostgreSQL to magnet-atheme
if: matrix.app == 'magnet-atheme'
run: |
# Check if already attached
if ! flyctl postgres attach --app magnet-atheme magnet-postgres --dry-run 2>/dev/null; then
echo "Attaching PostgreSQL to magnet-atheme..."
flyctl postgres attach --app magnet-atheme magnet-postgres
else
echo "PostgreSQL already attached to magnet-atheme"
fi
- name: Deploy ${{ matrix.app }}
run: flyctl deploy --config ${{ matrix.config }} --app ${{ matrix.app }} --remote-only