gcp-cloud-run
Skill4 starsChanged 5 months agoMITView on GitHub
Cloud Run deployment patterns for stateless, scalable Python services. Use when deploying to Cloud Run, configuring health checks, optimizing cold starts, or troubleshooting container issues.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- xfstudio/skillstheir own version, first seen Oct 13, 2026
- Ghosteken/agent-harnesstheir own version, first seen Oct 1, 2026
- kumaran-is/claude-code-onboardingtheir own version, first seen May 25, 2026
- Fandry96/k3-agentic-skillstheir own version, first seen May 12, 2026
- ai4brands-design/claude-skillstheir own version, first seen Mar 22, 2026
- bcastelino/agent-skills-kittheir own version, first seen Feb 28, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- kumaran-is/claude-code-onboarding★ 35same name
- Fandry96/k3-agentic-skills★ 27same name
- xfstudio/skills★ 9same name
- ai4brands-design/claude-skills★ 2same name
- bcastelino/agent-skills-kit★ 2same name
- Ghosteken/agent-harness★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository101 other files it gives its agents.
- ai-video-understandingSkill
- apple-foundation-modelsSkill
- arch-dddSkill
- arch-decision-recordsSkill
- arch-diagramsSkill
- arch-eventsSkill
- arch-mvp-roadmapSkill
- arch-python-modernSkill
- aws-app-runnerSkill
- aws-cicd-patternsSkill
- aws-security-hardeningSkill
- azure-functions-python-v2Skill
- azure-identity-m2m-authSkill
- azure-service-bus-messagingSkill
- azure-workflow-execution-modelsSkill
- caddy-tls-proxySkill
- compliance-frameworksSkill
- design-system-workflowSkill
- dev-debugging-strategiesSkill
- dev-standardsSkill
- docker-python-poetrySkill
- docker-pythonSkill
- fastapi-patternsSkill
- ffmpeg-laravel-videoSkill
- formik-yup-react-nativeSkill
- frontend-accessibilitySkill
- frontend-angular-aiSkill
- frontend-angularSkill
- frontend-angular-toolingSkill
- frontend-design-systemsSkill
- frontend-material-chatSkill
- frontend-material-design-3Skill
- frontend-svelteSkill
- gcp-cicd-patternsSkill
- gcp-cloudsql-infrastructureSkill
- gcp-finopsSkill
- gcp-observabilitySkill
- gcp-security-hardeningSkill
- github-actions-cicdSkill
- healthkit-biofeedbackSkill
- infra-terraformSkill
- ios-app-qualitySkill
- ios-audio-hapticsSkill
- jest-nestjs-testingSkill
- langchain-azure-openai-patternsSkill
- laravel-auth-hardeningSkill
- laravel-ci-mysqlSkill
- laravel-mix-webpackSkill
- laravel-modern-patternsSkill
- laravel-pint-patternsSkill
- laravel-s3-storageSkill
- laravel-sail-dockerSkill
- mobile-app-deploymentSkill
- mobile-e2e-testingSkill
- mobile-offline-syncSkill
- mobile-push-notificationsSkill
- mobile-video-uploadSkill
- mongodb-asyncmongoclient-patternsSkill
- mongodb-atlas-patternsSkill
- nestjs-patternsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 68
Run BEFORE building/pushing Docker images (saves 5-10 min):
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cloud Run Deployment Patterns
Stateless, scalable, cost-effective serverless containers on Google Cloud Run.
Core Constraints
| Constraint | Value | Implication |
| Port | 8080 (or PORT env) | Must bind to this port |
| Stateless | No local file persistence | Use GCS/Redis for state |
| Request timeout | 60s default, 3600s max | Long-running tasks need async patterns |
| Cold starts | 2-30s depending on image | Optimize image size, preload configs |
| Concurrency | 1-1000 requests/instance | Configure based on resource usage |
Quick Reference
Port Binding
import os
import uvicorn
port = int(os.environ.get("PORT", 8080))
uvicorn.run(app, host="0.0.0.0", port=port)Health Checks
| Endpoint | Purpose | Check Dependencies? |
/health/liveness | Process alive | No - restart if fails |
/health/readiness | Can serve traffic | Yes - remove from LB if fails |
Environment Variables
| Variable | Purpose | Example |
PORT | Container port | 8080 |
K_SERVICE | Service name | my-service |
K_REVISION | Revision name | my-service-00001 |
K_CONFIGURATION | Config name | my-service |
Common Anti-Patterns
| Anti-Pattern | Problem | Fix |
| Hardcoded port 8000 | Deployment fails | Use os.environ.get("PORT", 8080) |
| DB check in liveness | Outage restarts all containers | Only check in readiness |
| Large container image | Slow cold starts | Multi-stage builds, slim base |
| Global ThreadPoolExecutor | Resource exhaustion | Request-scoped or asyncio |
| Placeholder env vars with Pydantic | Container crashes at startup | Inject real values before deploy |
Pydantic Settings and Cloud Run Deployment
Pydantic validates env vars at container startup (import time). A placeholder like "PLACEHOLDER_SET_BY_DEPLOY_SCRIPT" in an HttpUrl field crashes the container before any deploy script runs. Solution: deploy dependency services first, capture URLs, inject real values via sed/envsubst, then deploy. For self-referential WS_URL: deploy with placeholder, capture URL, update with gcloud run services update --set-env-vars. See reference.md § Pydantic Settings — Pre-Deployment Injection.
Pre-Deployment Validation Checklist
Run BEFORE building/pushing Docker images (saves 5-10 min):
- Code quality:
just validate-branch(format, lint, type-check, tests) - Dockerfile lint:
hadolint/hadolint-action@v3.1.0 - YAML validation:
python -c "import yaml; yaml.safe_load(open('.cloudrun/staging.yaml'))" - Secrets verification:
gcloud secrets describe <secret-name> --project=PROJECT_ID - Connection pool capacity:
max_instances × (pool_size + pool_overflow) ≤ database_max_connections. Tier limits:db-f1-micro= 25,db-g1-small= 100,db-standard-1= 200+.
Docker Multi-Stage Build Pattern
3-stage Dockerfile with uv + BuildKit caching: fetch uv → install deps in builder → copy .venv + src into a minimal runtime image with a non-root user. Yields 50-70% faster rebuilds and ~200MB runtime image (vs 1GB+ with build tools). See reference.md § Docker Multi-Stage Build (uv) for the full Dockerfile.
Service Account Verification for CI/CD
CI/CD secrets (e.g., GCP_SA_KEY) may contain a different service account than expected, causing silent permission failures. Debug by extracting the SA email from the key JSON (jq -r .client_email key.json), then confirm its IAM bindings on the target resource (gcloud run services get-iam-policy <svc> / gcloud projects get-iam-policy <project>) match what the deploy expects before assuming a code fault.
VPC Egress Configuration
| Egress Setting | Use Case | Cost Impact |
all-traffic | Gateway services needing external APIs | Higher (all traffic through VPC) |
private-ranges-only | Internal services (DB, Redis only) | Lower (only private IPs via VPC) |
Entrypoint Shell Injection Prevention
Interpolating env vars into JSON via heredoc in entrypoint.sh is vulnerable to shell injection. jq provides safe JSON construction:
# BAD — shell injection via env var value
cat <<EOF > /app/config.json
{"apiUrl": "$API_URL"}
EOF
# GOOD — jq escapes values safely
jq -n --arg url "$API_URL" '{"apiUrl": $url}' > /app/config.jsonRuntime config pipeline for Angular SPAs: runtime-config.model.ts → config.service.ts → config.initializer.ts → entrypoint.sh → .cloudrun/staging.yaml
See reference.md for connection pool settings, Redis configuration, and graceful shutdown patterns.
See examples.md for thread-safe caching and complete health check implementations.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

