Minimal example repository demonstrating Google Cloud Run PR preview deployments with custom domains and OAuth support.
- Fork this repository
- Set up Google Cloud (see setup guide)
- Configure DNS (see DNS guide)
- Add GitHub secrets (see below)
- Open a PR - preview will deploy automatically!
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
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).
├── .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
- Open PR → GitHub Actions triggered
- Build Docker image → Push to Artifact Registry
- Deploy to Cloud Run → Service named
my-app-pr-123 - Map custom domain →
pr-123.example.com - SSL certificate → Auto-provisioned by Google
- Comment on PR → Bot posts preview URL
- Close PR → Automatic cleanup
- ✅ 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
Typical cost: $1-5/month for moderate usage
- Cloud Run: ~$0.01/month per active PR preview
- Artifact Registry: ~$0.10/GB/month storage
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"]Update workflow --port flag:
flags: '--allow-unauthenticated --port=8080 --memory=1Gi'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 }}/callbackMIT
Based on: ChipFlow Configurator PR Preview Implementation