cloud-run-basics
它能做什么
这个技能讲解并指导使用 Google Cloud Run,这是一个无需你管理服务器即可运行代码的平台。适合在 Google Cloud 上构建或托管应用的人员。
适用场景
- ✓你想把网页应用或 API 部署到 Google Cloud Run 上线的时候。
- ✓你需要任务按计划运行或按需运行一次的时候。
- ✓你有一个需要从队列读取数据、且必须始终运行的后台工作进程的时候。
技能链接
https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/cloud-run-basics/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我把我的网页应用部署到 Google Cloud Run,使其能在互联网上访问。”
每周 5 个新技能,1 分钟读完。
工作原理
这个技能指导你完成启用所需的 Google Cloud 服务、设置访问角色,并创建三种资源类型之一:服务、作业或工作进程池。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Cloud Run Basics
Cloud Run is a fully managed application platform for running your code, function, or container on top of Google's highly scalable infrastructure. It abstracts away infrastructure management, providing three primary resource types:
- Services: Responds to HTTP requests sent to a unique and stable endpoint, using stateless instances that autoscale based on a variety of key metrics, also responds to events and functions.
- Jobs: Executes parallelizable tasks that are executed manually, or on a schedule, and run to completion.
- Worker pools: Handles always-on background workloads such as pull-based workloads, for example, Kafka consumers, Pub/Sub pull queues, or RabbitMQ consumers.
Prerequisites
Enable the Cloud Run Admin API and Cloud Build APIs:
gcloud services enable run.googleapis.com cloudbuild.googleapis.com --quietIf you are under a domain restriction organization policy restricting unauthenticated invocations for your project, you will need to access your deployed service as described under Testing private services.
Required roles
You need the following roles to deploy your Cloud Run resource:
- Cloud Run Admin (
roles/run.admin) on the project - Cloud Run Source Developer (
roles/run.sourceDeveloper) on the project - Service Account User (
roles/iam.serviceAccountUser) on the service identity - Logs Viewer (
roles/logging.viewer) on the project
Cloud Build automatically uses the Compute Engine default service account as the default Cloud Build service account to build your source code and Cloud Run resource, unless you override this behavior.
For Cloud Build to build your sources, grant the Cloud Build service account the
Cloud Run Builder (roles/run.builder) role on your project:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member=serviceAccount:SERVICE_ACCOUNT_EMAIL_ADDRESS \
--role=roles/run.builder \
--quiet
Replace PROJECT_ID with your Google Cloud project ID and
SERVICE_ACCOUNT_EMAIL_ADDRESS with the email address of the Cloud Build
service account.
Deploy a Cloud Run service
You can deploy your service to Cloud Run by using a container image or deploy directly from source code using a single Google Cloud CLI command.
CRITICAL RULE: Any deployed code MUST listen on 0.0.0.0 (not 127.0.0.1) and use the injected $PORT environment variable (defaults to 8080), or it will crash on boot.
Deploy a container image to Cloud Run
Cloud Run imports your container image during deployment. Cloud Run keeps this copy of the container image as long as it is used by a serving revision. Container images are not pulled from their container repository when a new Cloud Run instance is started.
Supported container images
You can directly use container images stored in the Artifact Registry, or Docker Hub. Google recommends the use of Artifact Registry since Docker Hub images are cached for up to one hour.
You can use container images from other public or private registries (like JFrog Artifactory, Nexus, or GitHub Container Registry), by setting up an Artifact Registry remote repository.
You should only consider Docker Hub for deploying popular container images such as Docker Official Images or Docker Sponsored OSS images. For higher availability, Google recommends deploying these Docker Hub images using an Artifact Registry remote repository.
To deploy a container image, run the following command:
gcloud run deploy SERVICE_NAME \
--image IMAGE_URL \
--region us-central1 \
--allow-unauthenticated \
--quiet
Replace the following:
- SERVICE_NAME: the name of the service you want to deploy to. Service names must be 49 characters or less and must be unique pe
常见问题
服务和作业有什么区别?
服务以固定地址响应网页请求。作业则运行一项任务直到完成,可以按需运行,也可以按计划运行。
工作进程池用来做什么?
它用于持续运行的后台任务,例如拉取消息的队列消费者。
部署前我需要启用什么吗?
需要。你的项目中必须启用 Cloud Run Admin API 和 Cloud Build API。
详情
作者的原始描述
Manages Cloud Run services, jobs, and worker pools. Use when you need to deploy applications responding to HTTP requests (services), run event-triggered or scheduled tasks (jobs), or handle always-on pull-based background processing (worker pools).
热度
- GitHub 星标
- 33k
- 排名
- #8738
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
owasp-security
33k教你的智能体掌握面向网页应用、API、移动端、容器和 AI 智能体的 OWASP 安全指南,以便发现常见弱点并提出修复建议。
agent-management
33k让你的智能体使用 AI Maestro 命令行工具创建、列出、休眠、唤醒、重命名和删除 AI 智能体,管理每个智能体的生命周期。
agent-messaging
33k让你的智能体使用智能体消息协议,在 AI 智能体之间发送、接收和回复带签名的消息,大部分在你自己的电脑上完成。
docs-search
33k让你的智能体搜索自动生成的代码文档,查找函数签名、类定义和注释,从而在修改代码之前核对真实的 API。