Skip to content

Update carbon-aware-deploy.yml #28

Update carbon-aware-deploy.yml

Update carbon-aware-deploy.yml #28

name: Carbon-Aware Deploy to Fly.io
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Install Dependencies
run: npm install
- name: Build Astro Site
run: npm run build # Generates static files in 'dist/'
- name: Install Flyctl
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Get Low-Carbon Fly.io Region
id: carbonaware
env:
CARBON_API_TOKEN_ID: ${{ secrets.CARBON_API_TOKEN_ID }}
CARBON_API_TOKEN_SECRET: ${{ secrets.CARBON_API_TOKEN_SECRET }}
run: |
RESPONSE=$(curl -s -u "$CARBON_API_TOKEN_ID:$CARBON_API_TOKEN_SECRET" \
"https://api.carbonaware.cloud/v1/by-provider/fly")
CLEAN_REGION=$(echo "$RESPONSE" | jq -r '.regions | sort_by(.intensity) | .[0].id')
echo "CLEAN_REGION=$CLEAN_REGION" >> $GITHUB_ENV
- name: Scale Machines in Clean Region
run: |
echo "Scaling down machines in all regions..."
flyctl scale count 0
echo "Scaling up machines in region: $CLEAN_REGION"
flyctl scale count 1 --region $CLEAN_REGION --yes
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Deploy to Fly.io in Low-Carbon Region
run: |
echo "Deploying to region: $CLEAN_REGION"
flyctl deploy --remote-only --regions $CLEAN_REGION -a dani-astro-portfolio-blog-dawn-sun-2034
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}