Google Cloud Run Deployment Setup
This guide walks you through setting up automatic deployment to Google Cloud Run using GitHub integration and Buildpacks.Prerequisites
- Google Cloud Project with billing enabled
- Cloud Run API enabled
- Repository pushed to GitHub
- Google Cloud Console access
Step 1: Enable Required APIs
In Google Cloud Console, enable these APIs:- Cloud Run Admin API
- Cloud Build API
- Artifact Registry API (if using custom images)
Step 2: Set Up Cloud Run Service
- Go to Google Cloud Console → Cloud Run
- Click “Create Service”
- Select “Continuously deploy from a repository”
- Click “Set up with Cloud Build”
Step 3: Connect GitHub Repository
- Select “GitHub” as the source
- Authenticate with GitHub if needed
- Select your repository:
conductor/activation-api
- Choose branch:
main
Step 4: Configure Build Settings
- Build Type: Select “Buildpack” (recommended)
- Build Context: Leave as root directory
- Entry Point: Will be auto-detected from package.json
Step 5: Configure Service Settings
Basic Settings
- Service Name:
scope3-campaign-api
(or your preferred name) - Region: Choose your preferred region (e.g.,
us-central1
)
Environment Variables (Optional)
Add these optional environment variables:SCOPE3_GRAPHQL_URL
: https://api.scope3.com/api/graphql (if different)NODE_ENV
: production
Scaling Settings (Recommended)
- Minimum instances: 0 (scales to zero when no traffic)
- Maximum instances: 10 (adjust based on expected load)
- CPU allocation: CPU is only allocated during request processing
- Memory: 512 MB (increase if needed)
Security Settings
- Allow unauthenticated invocations: Enable (for public API access)
- Or configure authentication based on your needs
Health Check Settings
Cloud Run will automatically detect the built-in health check at/health
:
- Health check path:
/health
(automatically configured) - Health check timeout: 4 seconds (default)
- Health check interval: 10 seconds (default)
- No authentication required for health checks
Step 6: Deploy
- Click “Create” to set up the service
- Cloud Run will automatically trigger a build from your main branch
- Monitor the build in Cloud Build logs
Step 7: Verify Deployment
Once deployed, your service will be available at:Test the MCP Server
Ongoing Deployment
After initial setup:- Push changes to the
main
branch - Cloud Run automatically detects changes
- Builds new container using Buildpacks
- Deploys new version with zero-downtime rollout
- Automatically rolls back if health checks fail
Monitoring and Logs
View Logs
Monitoring Metrics
- Request count and latency
- Error rates
- Memory and CPU usage
- Instance scaling events
Troubleshooting
Build Failures
- Check Cloud Build logs in Google Cloud Console
- Verify all dependencies in package.json
- Ensure start script is defined
Runtime Issues
- Check Cloud Run logs
- Verify environment variables are set
- Check that PORT environment variable is handled correctly
Authentication Issues
- Verify API key is sent in request headers (x-scope3-api-key or Authorization: Bearer)
- Check API key permissions in Scope3 dashboard
- API keys are never stored on the server - they must come from client requests
Cost Optimization
- Service scales to zero when not in use
- You’re only charged for request processing time
- Consider setting appropriate CPU and memory limits
- Use minimum instances only if you need sub-second response times
Security Best Practices
- API keys are only passed through HTTP headers, never stored server-side
- Enable Cloud Run security features if needed
- Regularly rotate API keys
- Consider rate limiting for production use
Rollback
If you need to rollback a deployment:- Go to Cloud Console → Cloud Run → Your Service
- Click “Manage Traffic”
- Allocate 100% traffic to a previous revision
- Or use gcloud CLI: