GC-301e · Module 2

Cloud Run & Cloud Functions

4 min read

Cloud Run deployment through Gemini CLI collapses a multi-step process into conversational commands. The traditional workflow: write a Dockerfile, build the image, push to Artifact Registry, create a Cloud Run service, configure environment variables, set scaling parameters, route traffic. With Gemini CLI and the Cloud Run extension, the workflow becomes: "Deploy this directory to Cloud Run with these environment variables and 512MB memory, splitting 10% traffic to the new revision." Gemini handles the Dockerfile generation, build, push, and deployment configuration.

Cloud Functions follow a similar pattern but with event-driven triggers. Gemini CLI can scaffold a function, configure its trigger (HTTP, Pub/Sub, Firestore, Cloud Storage), set runtime options, and deploy — all through natural language. The key advantage: Gemini understands the relationship between your source code and the function configuration. Ask "deploy this handler as a Cloud Function triggered by Firestore writes to the orders collection" and Gemini generates the appropriate configuration, handles the deployment, and verifies the trigger is working.

# Cloud Run deployment via Gemini CLI
# "Deploy to Cloud Run with these settings:"
gcloud run deploy my-api \
  --source . \
  --region us-central1 \
  --memory 512Mi \
  --min-instances 1 \
  --max-instances 10 \
  --set-env-vars "DATABASE_URL=${DATABASE_URL},API_KEY=${API_KEY}" \
  --allow-unauthenticated

# Traffic splitting for canary deploys
gcloud run services update-traffic my-api \
  --to-revisions LATEST=10 \
  --region us-central1

# Cloud Functions deployment
gcloud functions deploy processOrder \
  --gen2 \
  --runtime nodejs20 \
  --trigger-event-filters="type=google.cloud.firestore.document.v1.written" \
  --trigger-event-filters="database=(default)" \
  --trigger-event-filters-path-pattern="document=orders/{orderId}" \
  --source . \
  --entry-point processOrder

# Gemini natural language equivalent:
# "Deploy processOrder to Cloud Functions, triggered by
#  Firestore writes to orders/{orderId}, Node.js 20 runtime"