Skip to content

ChipFlow/pr-preview-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PR Preview Example

Minimal example repository demonstrating Google Cloud Run PR preview deployments with custom domains and OAuth support.

Quick Start

  1. Fork this repository
  2. Set up Google Cloud (see setup guide)
  3. Configure DNS (see DNS guide)
  4. Add GitHub secrets (see below)
  5. Open a PR - preview will deploy automatically!

GitHub Secrets Required

WIF_PROVIDER=projects/123456789/locations/global/workloadIdentityPools/github-actions/providers/github-provider
WIF_SERVICE_ACCOUNT=github-actions-deploy@your-project.iam.gserviceaccount.com

Optional (for OAuth):

APP_CLIENT_ID=your-oauth-client-id
APP_CLIENT_SECRET=your-oauth-client-secret

Environment Variables

Update these in .github/workflows/pr-preview-deploy.yml:

env:
  PROJECT_ID: your-project-id          # Your GCP project ID
  SERVICE_BASE: my-app                  # Base name for services
  REGION: us-central1                   # GCP region
  PREVIEW_DOMAIN_BASE: example.com      # Your domain (will use pr-*.example.com)

Repository Structure

.
├── .github/
│   └── workflows/
│       └── pr-preview-deploy.yml      # Main workflow
├── app/
│   ├── page.tsx                        # Main page
│   └── api/
│       └── auth/
│           └── route.ts                # OAuth example (optional)
├── docs/
│   ├── SETUP.md                        # Detailed setup guide
│   ├── DNS.md                          # DNS configuration
│   └── OAUTH.md                        # OAuth cross-domain guide
├── Dockerfile                          # Container definition
├── package.json
└── README.md                           # This file

How It Works

  1. Open PR → GitHub Actions triggered
  2. Build Docker image → Push to Artifact Registry
  3. Deploy to Cloud Run → Service named my-app-pr-123
  4. Map custom domainpr-123.example.com
  5. SSL certificate → Auto-provisioned by Google
  6. Comment on PR → Bot posts preview URL
  7. Close PR → Automatic cleanup

Features

  • ✅ Automatic deployments on PR open/update
  • ✅ Custom domains with SSL (pr-123.yourapp.com)
  • ✅ Automatic cleanup on PR close
  • ✅ OAuth cross-domain support
  • ✅ Zero-cost when idle (Cloud Run scales to 0)
  • ✅ PR comments with preview URLs

Cost

Typical cost: $1-5/month for moderate usage

  • Cloud Run: ~$0.01/month per active PR preview
  • Artifact Registry: ~$0.10/GB/month storage

Customization

Different Framework

Update Dockerfile and build commands:

Python/Flask:

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:3000"]

Go:

FROM golang:1.21 AS builder
WORKDIR /app
COPY . .
RUN go build -o server .

FROM debian:bookworm-slim
COPY --from=builder /app/server .
CMD ["./server"]

Different Port

Update workflow --port flag:

flags: '--allow-unauthenticated --port=8080 --memory=1Gi'

Additional Environment Variables

Add to env_vars in workflow:

env_vars: |
  NODE_ENV=production
  DATABASE_URL=${{ secrets.DATABASE_URL }}
  API_KEY=${{ secrets.API_KEY }}
  OAUTH_REDIRECT_URI=https://${{ steps.service-name.outputs.custom_domain }}/callback

Troubleshooting

See docs/TROUBLESHOOTING.md

Learn More

License

MIT


Based on: ChipFlow Configurator PR Preview Implementation

About

Complete example for Google Cloud Run PR preview deployments with custom domains and OAuth support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published