· Alexander Stolpe · Dev Diary
Setting up Nightly Deploys for a Static Supabase-backed Site
A small note on keeping a static Supabase-backed site alive with a nightly GitHub Actions workflow that triggers a Cloudflare Pages deploy hook once per day.
Setting up Nightly Deploys for a Static Supabase-backed Site
Seeing that this site mostly does its reads during the build step, unless I am logged in to the admin pages and doing something myself, the page will not trigger many reads from my Supabase database. This caused my Supabase project to be targeted for pausing as “inactive” after one week without traffic.
Since this is a natural consequence of how the site works, I decided to create a small nightly deploy strategy to keep things active.
The choice
Given my stack I stumbled across 2 viable options for doing this. Both options use a Cloudflare deploy hook that gets called on schedule. Then I either create a Cloudflare worker cron and trigger it from there or add an Github workflow. I went with the Github workflow since it feels more natural to keep as much of my workflow there as possible. This also lets me tweak it in my code seeing that the workflow lives in a YAML file, which just feels like the cleanest and most reusable option here.
The implementation
- Create a deploy hook in Cloudflare pages
- Create the file in the project under .github/workflows/daily-cloudflare-deploy.yml
name: Daily Cloudflare Deploy
on:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Trigger Cloudflare Deploy
env:
CLOUDFLARE_DEPLOY_HOOK: ${{ secrets.CLOUDFLARE_DEPLOY_HOOK }}
run: |
curl -X POST "$CLOUDFLARE_DEPLOY_HOOK"- Add the deploy hook as a repository secret in my github repo.
- Success!
This also gives me the option of triggering it manually from Github. Which is really nice.
Cover photo by Alex Knight on Unsplash.