Skip to content

Instantly share code, notes, and snippets.

@BlackMac
Last active December 22, 2025 09:53
Show Gist options
  • Select an option

  • Save BlackMac/3e0f889b1578a81f62bd08cbf0ba3c43 to your computer and use it in GitHub Desktop.

Select an option

Save BlackMac/3e0f889b1578a81f62bd08cbf0ba3c43 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Edge Functions Setup Script
# Run this in any project directory to add edge function deployment
# add this to your .bashrc or .zshrc:
# alias setup-edge-functions='bash <(curl -fsSL https://gist.githubusercontent.com/BlackMac/3e0f889b1578a81f62bd08cbf0ba3c43/raw/setup-edge-functions.sh)'
set -e
PROJECT_NAME=${1:-$(basename "$(pwd)")}
echo "πŸš€ Setting up edge functions for: $PROJECT_NAME"
echo ""
# Create directories
mkdir -p .github/workflows
mkdir -p supabase/functions/hello
# Create workflow file
cat > .github/workflows/deploy-functions.yml << 'EOF'
name: Deploy Edge Functions
on:
push:
branches: [main]
paths:
- 'supabase/functions/**'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy functions to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
source: "supabase/functions/*"
target: "${{ secrets.DEPLOY_PATH }}/${{ secrets.PROJECT_NAME }}/"
strip_components: 2
overwrite: true
- name: Done
run: echo "βœ… Deployed to ${{ secrets.PROJECT_NAME }}"
EOF
# Create sample function
cat > supabase/functions/hello/index.ts << 'EOF'
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"
serve(async (req: Request) => {
const body = await req.json().catch(() => ({}))
const name = body.name || 'World'
return new Response(
JSON.stringify({ message: `Hello, ${name}!` }),
{ headers: { 'Content-Type': 'application/json' } }
)
})
EOF
echo "βœ… Created files:"
echo " .github/workflows/deploy-functions.yml"
echo " supabase/functions/hello/index.ts"
echo ""
echo "πŸ“‹ Now add these GitHub secrets to your repo:"
echo " https://github.com/YOUR_USERNAME/$(basename "$(pwd)")/settings/secrets/actions"
echo ""
echo " β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”"
echo " β”‚ DEPLOY_HOST β”‚ your-server-ip β”‚"
echo " β”‚ DEPLOY_USER β”‚ root β”‚"
echo " β”‚ DEPLOY_KEY β”‚ (contents of ~/.ssh/edge_functions_deploy) β”‚"
echo " β”‚ DEPLOY_PATH β”‚ (your functions volume path from Coolify) β”‚"
echo " β”‚ PROJECT_NAME β”‚ $PROJECT_NAME β”‚"
echo " β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜"
echo ""
echo "πŸ”‘ To copy your deploy key:"
echo " cat ~/.ssh/edge_functions_deploy | pbcopy"
echo ""
echo "πŸš€ Then commit and push:"
echo " git add ."
echo " git commit -m 'Add edge functions'"
echo " git push"
echo ""
echo "πŸ“ Your function will be available at:"
echo " https://your-supabase-url/functions/v1/$PROJECT_NAME/hello"
# Create manual deploy script
cat > deploy-functions.sh << EOF
#!/bin/bash
# Staging deploy - deploys to PROJECT_NAME-staging
# Production is only deployed via git push
PROJECT_NAME="$PROJECT_NAME"
STAGING_NAME="\${PROJECT_NAME}-staging"
DEPLOY_HOST="\${DEPLOY_HOST:-your-server-ip}"
DEPLOY_USER="\${DEPLOY_USER:-root}"
DEPLOY_KEY="\${DEPLOY_KEY:-\$HOME/.ssh/edge_functions_deploy}"
DEPLOY_PATH="\${DEPLOY_PATH}"
if [[ -z "\$DEPLOY_PATH" ]]; then
echo "❌ Set DEPLOY_PATH first:"
echo " export DEPLOY_PATH=/data/coolify/services/.../volumes/functions"
exit 1
fi
echo "πŸ§ͺ Deploying to STAGING: \$STAGING_NAME"
echo " (production '\$PROJECT_NAME' is unchanged)"
echo ""
rsync -avz --delete \\
-e "ssh -i \$DEPLOY_KEY" \\
supabase/functions/ \\
"\$DEPLOY_USER@\$DEPLOY_HOST:\$DEPLOY_PATH/\$STAGING_NAME/"
echo ""
echo "βœ… Staging deployed!"
echo ""
echo "πŸ“ Test your functions at:"
echo " https://your-supabase-url/functions/v1/\$STAGING_NAME/FUNCTION_NAME"
echo ""
echo "πŸš€ When ready for production:"
echo " git add . && git commit -m 'Update functions' && git push"
EOF
chmod +x deploy-functions.sh
echo ""
echo "⚑ Workflow:"
echo " ./deploy-functions.sh β†’ deploys to ${PROJECT_NAME}-staging (safe to test)"
echo " git push β†’ deploys to ${PROJECT_NAME} (production)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment