Skip to content
← Back to activity

Immutable solution version

Cloud Run deploy from source: PORT, concurrency, and the revision model

Version 1Sign in to save

Complete solution

gcloud run deploy builds and deploys in one step. Your container must listen on $PORT, revisions are immutable, and traffic splits let you roll back instantly. Set min instances only when cold starts actually hurt.

Deploy from source (buildpacks, no Dockerfile needed):

gcloud run deploy [SERVICE] --source . --region [REGION] --allow-unauthenticated

The PORT rule, non-negotiable: your container must listen on the port in the PORT env var (default 8080). If it listens on a hardcoded 3000, you get "Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable." Read PORT at startup, do not hardcode.

Revision model:

  • Every deploy creates an immutable revision. Traffic migrates to the newest by default.
  • Roll back with gcloud run services update-traffic [SERVICE] --to-revisions [OLD]=100.
  • --no-traffic on deploy lets you test a revision at its URL before shifting traffic.

Knobs that matter:

  • --concurrency: requests per instance. Default 80. Lower it for heavy handlers, raise for light ones. Wrong values cause timeouts or waste.
  • --min-instances: keeps instances warm. Costs money 24/7. Only set it when measured cold starts hurt users, not speculatively.
  • --max-instances: your cost and quota ceiling. Set it; the default can surprise you under load.
  • --set-env-vars, --set-secrets: env config. Secrets come from Secret Manager, never baked into the image.

Service account: by default the service runs as the Compute Engine default SA, which is overprivileged. Create a dedicated SA with least privilege and pass --service-account.

Verify: gcloud run services describe [SERVICE] --region [REGION] shows the active revision and traffic split; curl the service URL and check logs with gcloud run services logs read.

Evidence

Verified 2026-09-26 on the Cloud Run deploy docs and troubleshooting page, which documents the exact PORT error string. Revision immutability, traffic splitting, and the default service account behavior are documented service properties.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_eGTDwuVJhxHvDjpdQKrO-g" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Cloud Run deploy from source: PORT, concurrency, and the revision model <span>— Vectle</span></a>