Module 32: Deployment to Cloud Run
Theoryโ
Figure: Promoting support-ops-agent from a local agents-cli prototype to a production-grade serverless microservice on Google Cloud Run with built-in A2A and ADK SSE endpoints.
From Validated Prototype to Serverless Productionโ
In Part 6 (Modules 30.1โ30.4) and Module 31, you built support-ops-agent, verified its quality with agents-cli eval run, added deployment gates, and mapped out target selection and Workload Identity. Now you are ready to roll out a live, authenticated HTTPS container to Google Cloud Run (agents-cli scaffold enhance + agents-cli deploy).
Google Cloud Run is a fully managed serverless container runtime that pairs naturally with ADK agents:
- Zero Server Administration: Provide a
Dockerfile(already generated byagents-cli), and Cloud Run manages TLS certificates, load balancing, health checks, and revision rollouts. - Dual-Protocol Serving Out of the Box: The scaffolded
uvicorn app.fast_api_app:appcontainer simultaneously serves ADK's native streaming routes (/run_sse,/apps/app/...) and the Agent-to-Agent (A2A) surface (/a2a/app/.well-known/agent-card.json+ JSON-RPC) on port8080. - Pay-Per-Request & Revision Traffic Control: Dev services scale to zero when idle (
--min-instances 0), while production services pin warm instances and support instant traffic shifting across immutable revisions.
Upgrading a Prototype In Place with agents-cli scaffold enhanceโ
Figure: Automated Cloud Run promotion pipeline โ in-place IaC enhancement, Cloud Build image compilation, Artifact Registry storage, and Cloud Run revision rollout.
Because you started with --prototype in Module 31, adding Cloud Run infrastructure requires zero code rewrites. Running scaffold enhance from inside support-ops-agent/ merges production assets in place while preserving app/agent.py, .env, GEMINI.md, and tests/eval/ untouched:
agents-cli scaffold enhance . \
--deployment-target cloud_run \
--cicd-runner github_actions \
--region us-central1
What scaffold enhance Adds to Your Projectโ
- Updated
agents-cli-manifest.yaml: Recordsdeployment_target: cloud_run,cicd_runner: github_actions, andregion: us-central1soagents-cli deployknows how to package and target the service. - Modular Terraform IaC (
deployment/terraform/):deployment/terraform/single-project/(service.tf,iam.tf,storage.tf) โ Single-project Cloud Run v2 service, Artifact Registry, least-privilegeapp_saruntime service account, and telemetry bindings (usable viaagents-cli infra single-project --apply).deployment/terraform/cicd/&deployment/terraform/shared/โ Multi-environment staging-to-production promotion withcicd_runner_sa, Workload Identity Federation (WIF), and optional persistent Cloud SQL for PostgreSQL 15 session storage when--session-type cloud_sqlis selected.
- CI/CD Pipelines (
.github/workflows/or.cloudbuild/): Automated lint, evaluation gate, staging deploy, load test, and human-approved production rollout workflows. - Load Testing Suite (
tests/load_test/load_test.py): Pre-configured Locust harness for stress-testing concurrency and memory ceilings before production launch.
Sizing, Security & Secrets Flags on agents-cli deployโ
For rapid dev and staging deployments, agents-cli deploy works standalone (no prior terraform apply required) and exposes fine-grained sizing and security flags:
| Flag | Default (agents-cli deploy) | Production Guidance & Coupling Rules |
|---|---|---|
--cpu | 1 | Container runs a single async Uvicorn process; scale out via concurrency and instances first, raising --cpu only when profiling shows real CPU saturation rather than LLM wait time. |
--memory | 4Gi | Memory bounds concurrency. Each concurrent request holds its prompt history, tool payloads, and stream buffer in RAM (peak โ base + concurrency ร per-request RAM). Never raise --concurrency without checking --memory. |
--concurrency | 8 | Conservative default protecting RAG/multimodal agents from OOM. Lightweight tool-calling agents can tune to 16โ32 using tests/load_test/load_test.py. |
--min-instances | 0 (1 in service.tf) | 0 avoids idle dev cost; pass --min-instances 1 (default in generated service.tf) to eliminate cold starts for latency-sensitive or Live API agents. |
--max-instances | 10 | Horizontal scaling cap protecting downstream APIs and model quotas. |
--timeout | 300 (seconds, max 3600) | Increase to --timeout 3600 for long-running research workflows or bidirectional Live / voice WebSocket sessions. |
--iap | Off | Enables Identity-Aware Proxy on Cloud Run so only authorized Google Workspace identities can reach the service without custom auth code. |
--secrets | โ | Mounts GCP Secret Manager secrets as env vars (e.g., --secrets "WEBHOOK_TOKEN=prod-webhook:latest"); never commit production API secrets into .env. |
Separating Infrastructure Region (DEPLOY_REGION) from Model Location (GOOGLE_CLOUD_LOCATION=global)โ
One of the most important operational distinctions on Google Cloud is separating where your container runs from where your Gemini model endpoint is served:
DEPLOY_REGION(--region us-central1): Cloud Run services, Cloud Build workers, and Artifact Registry repositories are regional resources and require a concrete region such asus-central1oreurope-west1.GOOGLE_CLOUD_LOCATION=global: On Gemini Enterprise / Vertex AI (GOOGLE_GENAI_USE_ENTERPRISE=1),gemini-3.8-flashis served on theglobalendpoint. Passing--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global"ensures the running Cloud Run container routes model inference toglobalrather than defaulting tous-central1(which would cause runtime404 NOT_FOUNDmodel errors):
export GOOGLE_CLOUD_PROJECT="your-project-id"
export DEPLOY_REGION="us-central1"
agents-cli deploy \
--project "$GOOGLE_CLOUD_PROJECT" \
--region "$DEPLOY_REGION" \
--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" \
--no-confirm-project
Testing & Evaluating Live Cloud Run Endpointsโ
By default, Cloud Run services deployed by agents-cli enforce IAM authentication (--no-allow-unauthenticated). Rather than manually crafting curl headers and minting short-lived identity tokens, agents-cli natively authenticates, manages sessions, and speaks both protocols against your --url:
- Test the Built-In A2A Endpoint (
--mode a2a): Discovers/a2a/app/.well-known/agent-card.jsonand streams JSON-RPC tasks over HTTPS:agents-cli run "Investigate ticket TCK-1042 and check SLA." \
--url "$SERVICE_URL" \
--mode a2a - Test the Native ADK Streaming Endpoint (
--mode adk): Creates an ADK session and streams Server-Sent Events (/run_sse) against--app-name app:agents-cli run "Check ticket TCK-2088." \
--url "$SERVICE_URL" \
--mode adk \
--app-name app - Run Remote Cloud Evaluation (
eval generate --url+eval grade): Validates the live Cloud Run container end-to-end againsttests/eval/datasets/basic-dataset.json:agents-cli eval generate --url "$SERVICE_URL" --app-name app && agents-cli eval grade
When deploying 'support-ops-agent' ('gemini-3.8-flash') to Cloud Run in 'us-central1' using 'agents-cli deploy', why do you pass '--region us-central1' together with '--env-vars GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global'?
Key Takeawaysโ
- In-Place Promotion (
scaffold enhance):agents-cli scaffold enhance . --deployment-target cloud_runupgrades a validated prototype with Terraform IaC (deployment/terraform/), CI/CD pipelines, and Locust load tests without touchingapp/agent.pyor.env. - Coupled Sizing: Memory (
--memory, default4Gi) bounds--concurrency(default8); scale--concurrency,--memory, and--max-instancestogether usingtests/load_test/, and set--min-instances 1(plus--timeout 3600for Live voice agents) when cold starts are unacceptable. - Region Separation: Always pair regional Cloud Run infrastructure (
--region us-central1) with--env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global"forgemini-3.8-flash. - Live Dual-Protocol Verification: Use
agents-cli run --url "$SERVICE_URL" --mode [a2a|adk]andagents-cli eval generate --url "$SERVICE_URL" --app-name app && agents-cli eval gradeto verify authenticated Cloud Run deployments end-to-end.