在专用池中创建和运行 build
本页面介绍如何创建连接到服务提供方网络的 Cloud Build 专用池,并在专用池中运行构建。
服务提供方网络是托管专用池的网络。默认情况下,专用池设置为使用服务提供方网络,该网络提供具有以下功能的构建环境:
- 可配置的机器类型
- 可配置的磁盘大小
- 访问公共互联网中的资源,例如代码库或注册表中的资源
如需遵循有关此任务的分步指导,请直接在 Cloud Shell Editor 中点击 操作演示:
准备工作
- 登录您的 Google Cloud 账号。如果您是 Google Cloud的新用户, 请创建账号,以便在 真实场景中评估我们产品的性能。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
创建专用池
在 Google Cloud 控制台中,打开 Cloud Build 工作器池 标签页:
点击
创建 。在创建专用池面板中,输入以下设置:
在
名称 字段中,输入my-first-privatepool。在
区域 字段中,选择us-central1。在
机器类型 字段中,选择e2-standard-2。在
可用磁盘大小 字段中,输入800。将
网络项目编号 字段留空。将
网络 字段留空。确保选中
分配外部 IP 。
点击
专用池创建会需要一些时间,请稍等片刻。专用池创建后,将在工作器池标签页中列出。
在专用池中运行构建
打开一个终端窗口。
创建名为
quickstart-private-pool的新目录并导航至该目录:mkdir quickstart-private-pool cd quickstart-private-pool创建名为
cloudbuild.yaml且包含以下内容的文件:steps: - name: "bash" script: echo "I am running in a private pool!" options: pool: name: "projects/$PROJECT_ID/locations/us-central1/workerPools/my-first-privatepool"使用构建配置文件启动构建:
gcloud builds submit
构建完成后,您将看到类似于以下内容的输出:
I am running in a private pool!
PUSH
DONE
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
5df45735-6414-40b7-9e10-e6d2023c8cea 2020-08-31T13:16:18+00:00 10S gs://private-pool-test_cloudbuild/source/1598879777.206444- 58901ecbd14e431f8cdacc85d5dd0fc3.tgz - SUCCESS
查看构建详情
在 Google Cloud 控制台中打开构建记录 页面。
在
您将看到您在专用池中运行的构建作业。区域 下拉框中,选择 us-central1。点击构建以查看构建详情,例如构建摘要和工件。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
在 Google Cloud 控制台中打开工作器池 页面:
在专用池所在的行中,点击垃圾桶图标。
在删除专用池?弹出式窗口中,点击删除。
您在此快速入门中创建的专用池现已删除。 您可能需要刷新屏幕才能从工作器池页面中删除专用池。
后续步骤
- 了解如何创建专用 VPC 对等互连连接。
- 详细了解专用池。