Skip to main content

Module 32: Deployment to Cloud Run

Theoryโ€‹

Serverless Agent Deployment to Cloud Run (Light) Serverless Agent Deployment to Cloud Run (Dark) 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 by agents-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:app container 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 port 8080.
  • 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โ€‹

Automated Cloud Run Deployment Pipeline (Light) Automated Cloud Run Deployment Pipeline (Dark) 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: Records deployment_target: cloud_run, cicd_runner: github_actions, and region: us-central1 so agents-cli deploy knows 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-privilege app_sa runtime service account, and telemetry bindings (usable via agents-cli infra single-project --apply).
    • deployment/terraform/cicd/ & deployment/terraform/shared/ โ€” Multi-environment staging-to-production promotion with cicd_runner_sa, Workload Identity Federation (WIF), and optional persistent Cloud SQL for PostgreSQL 15 session storage when --session-type cloud_sql is 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:

FlagDefault (agents-cli deploy)Production Guidance & Coupling Rules
--cpu1Container 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.
--memory4GiMemory 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.
--concurrency8Conservative default protecting RAG/multimodal agents from OOM. Lightweight tool-calling agents can tune to 16โ€“32 using tests/load_test/load_test.py.
--min-instances0 (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-instances10Horizontal scaling cap protecting downstream APIs and model quotas.
--timeout300 (seconds, max 3600)Increase to --timeout 3600 for long-running research workflows or bidirectional Live / voice WebSocket sessions.
--iapOffEnables 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 as us-central1 or europe-west1.
  • GOOGLE_CLOUD_LOCATION=global: On Gemini Enterprise / Vertex AI (GOOGLE_GENAI_USE_ENTERPRISE=1), gemini-3.8-flash is served on the global endpoint. Passing --env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" ensures the running Cloud Run container routes model inference to global rather than defaulting to us-central1 (which would cause runtime 404 NOT_FOUND model 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:

  1. Test the Built-In A2A Endpoint (--mode a2a): Discovers /a2a/app/.well-known/agent-card.json and streams JSON-RPC tasks over HTTPS:
    agents-cli run "Investigate ticket TCK-1042 and check SLA." \
    --url "$SERVICE_URL" \
    --mode a2a
  2. 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
  3. Run Remote Cloud Evaluation (eval generate --url + eval grade): Validates the live Cloud Run container end-to-end against tests/eval/datasets/basic-dataset.json:
    agents-cli eval generate --url "$SERVICE_URL" --app-name app && agents-cli eval grade
๐ŸŽฏ Knowledge CheckSelect Best Answer

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_run upgrades a validated prototype with Terraform IaC (deployment/terraform/), CI/CD pipelines, and Locust load tests without touching app/agent.py or .env.
  • Coupled Sizing: Memory (--memory, default 4Gi) bounds --concurrency (default 8); scale --concurrency, --memory, and --max-instances together using tests/load_test/, and set --min-instances 1 (plus --timeout 3600 for 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" for gemini-3.8-flash.
  • Live Dual-Protocol Verification: Use agents-cli run --url "$SERVICE_URL" --mode [a2a|adk] and agents-cli eval generate --url "$SERVICE_URL" --app-name app && agents-cli eval grade to verify authenticated Cloud Run deployments end-to-end.
๐Ÿ“–

32: Deploying to Cloud Run(Theory & Overview)

Part 7: Cloud Runtimes & Enterprise โ€ข Module 32

Overall Course Progress:
0%(0/98)
Next Step: Challenge Lab ๐Ÿงช โ†’