Skip to content

GCP Cloud Run

Deploy your services to Google Cloud Run with automatic scaling and pay-per-use billing.

Prerequisites

  1. Google Cloud SDK installed and configured
  2. Docker installed
  3. A GCP project with Cloud Run API enabled
Terminal window
# Install gcloud
brew install google-cloud-sdk
# Authenticate
gcloud auth login
gcloud auth configure-docker
# Set project
gcloud config set project YOUR_PROJECT_ID

Service Configuration

name: my-api
provider: gcp
project: my-gcp-project
region: 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: true

Required Fields

FieldDescription
nameService name
projectGCP project ID
regionGCP region (e.g., us-central1)

Optional Fields

Cloud Run Configuration

FieldTypeDefaultDescription
min_instancesint0Minimum instances (set > 0 to avoid cold starts)
max_instancesint100Maximum instances
memorystring256MiMemory allocation (256Mi, 512Mi, 1Gi, 2Gi)
cpustring1CPU allocation (1, 2, 4)
concurrencyint80Max concurrent requests per instance
timeout_secondsint300Request timeout
cpu_throttlingbooltrueThrottle 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-repo

Or use Container Registry (legacy):

registry_name: gcr.io/my-project

Secrets

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:latest

Pilum 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-api
provider: gcp
project: my-project
regions:
- us-central1
- europe-west1
- asia-northeast1

Pilum creates three deployments, one per region.

Deployment Steps

The GCP Cloud Run recipe executes:

  1. build binary — Compile the application
  2. build docker image — Create container image
  3. push to registry — Push to Artifact Registry
  4. deploy to cloud run — Deploy with gcloud run deploy

Example Commands

Terminal window
# Deploy all GCP services
pilum deploy --tag=v1.0.0
# Deploy specific service
pilum 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 commands
pilum dry-run --tag=v1.0.0

Generated Deploy Command

Pilum generates:

Terminal window
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:latest

Troubleshooting

Authentication Errors

ERROR: (gcloud.run.deploy) PERMISSION_DENIED

Re-authenticate:

Terminal window
gcloud auth login
gcloud auth configure-docker us-central1-docker.pkg.dev

Image Push Fails

Ensure Docker is authenticated:

Terminal window
gcloud auth configure-docker us-central1-docker.pkg.dev

Service Doesn’t Start

Check logs:

Terminal window
gcloud run services logs read my-api --region us-central1

Next Steps