GCP Cloud Run
Deploy your services to Google Cloud Run with automatic scaling and pay-per-use billing.
Prerequisites
- Google Cloud SDK installed and configured
- Docker installed
- A GCP project with Cloud Run API enabled
# Install gcloudbrew install google-cloud-sdk
# Authenticategcloud auth logingcloud auth configure-docker
# Set projectgcloud config set project YOUR_PROJECT_IDService Configuration
name: my-apiprovider: gcpproject: my-gcp-projectregion: us-central1
build: language: go version: "1.23" env_vars: CGO_ENABLED: "0"
cloud_run: min_instances: 0 max_instances: 10 memory: "512Mi" cpu: "1" concurrency: 80 timeout_seconds: 300 cpu_throttling: trueRequired Fields
| Field | Description |
|---|---|
name | Service name |
project | GCP project ID |
region | GCP region (e.g., us-central1) |
Optional Fields
Cloud Run Configuration
| Field | Type | Default | Description |
|---|---|---|---|
min_instances | int | 0 | Minimum instances (set > 0 to avoid cold starts) |
max_instances | int | 100 | Maximum instances |
memory | string | 256Mi | Memory allocation (256Mi, 512Mi, 1Gi, 2Gi) |
cpu | string | 1 | CPU allocation (1, 2, 4) |
concurrency | int | 80 | Max concurrent requests per instance |
timeout_seconds | int | 300 | Request timeout |
cpu_throttling | bool | true | Throttle CPU when not processing requests |
Registry Configuration
By default, images are pushed to Artifact Registry:
registry_name: us-central1-docker.pkg.dev/my-project/my-repoOr use Container Registry (legacy):
registry_name: gcr.io/my-projectSecrets
Reference secrets from Secret Manager:
secrets: - name: DATABASE_URL value: projects/123456789/secrets/database-url:latest - name: API_KEY value: projects/123456789/secrets/api-key:latestPilum automatically adds --set-secrets to the deploy command.
Environment Variables
env_vars: LOG_LEVEL: info ENVIRONMENT: production API_TIMEOUT: "30"Multi-Region Deployment
Deploy to multiple regions:
name: my-apiprovider: gcpproject: my-projectregions: - us-central1 - europe-west1 - asia-northeast1Pilum creates three deployments, one per region.
Deployment Steps
The GCP Cloud Run recipe executes:
- build binary — Compile the application
- build docker image — Create container image
- push to registry — Push to Artifact Registry
- deploy to cloud run — Deploy with
gcloud run deploy
Example Commands
# Deploy all GCP servicespilum deploy --tag=v1.0.0
# Deploy specific servicepilum deploy my-api --tag=v1.0.0
# Build and push only (no deploy)pilum publish --tag=v1.0.0
# Deploy only (image must exist)pilum deploy --only-tags=deploy --tag=v1.0.0
# Preview commandspilum dry-run --tag=v1.0.0Generated Deploy Command
Pilum generates:
gcloud run deploy my-api \ --image us-central1-docker.pkg.dev/my-project/my-repo/my-api:v1.0.0 \ --region us-central1 \ --project my-project \ --platform managed \ --allow-unauthenticated \ --min-instances=0 \ --max-instances=10 \ --memory 512Mi \ --cpu 1 \ --concurrency=80 \ --timeout=300 \ --set-secrets=DATABASE_URL=projects/123456789/secrets/database-url:latestTroubleshooting
Authentication Errors
ERROR: (gcloud.run.deploy) PERMISSION_DENIEDRe-authenticate:
gcloud auth logingcloud auth configure-docker us-central1-docker.pkg.devImage Push Fails
Ensure Docker is authenticated:
gcloud auth configure-docker us-central1-docker.pkg.devService Doesn’t Start
Check logs:
gcloud run services logs read my-api --region us-central1Next Steps
- Service Configuration — Full reference
- CLI Commands — All commands
- Troubleshooting — Common issues