这些说明适用于希望将 GitHub Enterprise 源代码库与 Google 搭配使用的应用开发者、平台管理员和安全管理员。 具体而言,您可以将 GitHub Enterprise 代码库与 Gemini Code Assist搭配使用。
如需详细了解 Developer Connect,请参阅 Developer Connect 概览。
准备工作
-
登录您的 Google 账号。
如果您还没有 Google 账号,请 注册新账号。
-
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 Developer Connect 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.-
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 Developer Connect 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.-
确保您有权访问 GitHub Enterprise 上的账号。
为了确保团队工作的安全性,我们建议您使用机器人账号或团队共享的账号(而非个人账号)完成本指南中的任务。
- 确保您拥有 GitHub Enterprise 代码库,或者对共享代码库拥有管理员级权限。
在 GitHub Enterprise 组织中使用代码库时,请确保您拥有 GitHub 应用管理员权限。
- 可选:创建客户管理的 加密密钥 (CMEK),用于加密 Developer Connect 创建的身份验证密钥。
- 可选:如需使用本指南中的命令行说明,请完成以下步骤:
- 安装 Google Cloud CLI。如果您之前安装过 gcloud CLI,请运行
gcloud components update以确保您拥有最新版本。 - 通过运行以下命令创建 Developer Connect 服务账号
,其中 PROJECT_ID 是您的 Google Cloud 项目 ID:
gcloud beta services identity create \ --service=developerconnect.googleapis.com \ --project=PROJECT_ID
- 安装 Google Cloud CLI。如果您之前安装过 gcloud CLI,请运行
启用 Developer Connect 也会启用 Secret Manager API。
授予所需的 IAM 权限
如需获得创建连接和链接所需的权限,请让您的管理员为您授予以下 IAM 角色:
-
如果您不是项目所有者:
Developer Connect Admin (
roles/developerconnect.admin) 角色。 -
如果您计划使用 CMEK 加密 Developer Connect 创建的密钥:Cloud KMS CryptoKey Encrypter/Decrypter (
roles/cloudkms.cryptoKeyEncrypterDecrypter) 角色位于 Secret Manager 服务账号上。 -
如果您计划使用 gcloud CLI 完成本指南中的步骤:Secret Manager Admin 角色 (
roles/secretmanager.admin) on the Developer Connect Service Account. -
如果您计划使用 Google Cloud 控制台完成本指南中的步骤:用户账号的Project IAM Admin (
roles/resourcemanager.projectIamAdmin) 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
您也可以通过自定义 角色或其他预定义 角色来获取所需的权限。
创建连接
本部分介绍了如何在 Developer Connect 和 GitHub Enterprise 之间创建连接。如果您使用的是 Google Cloud 控制台,则还可以在完成连接设置后开始 添加与代码库的链接。
如需创建新的 GitHub Enterprise 连接,请选择以下选项之一:
控制台
如需启动连接,请完成以下步骤:
在 Google Cloud 控制台中,打开 Developer Connect。
Developer Connect 会显示 Git 代码库 页面。
- 如果您看到源代码管理提供方列表 :选择一个源代码管理提供方,开始配置您的第一个连接。点击 GitHub Enterprise 卡片上的连接 。
如果您看到列出现有连接的表格:依次点击创建连接 > GitHub Enterprise ,设置源代码管理提供商。
创建连接 页面随即打开。
对于区域,请为连接资源选择一个区域 。
- 对于名称,请输入新连接的名称。
选中启用符合数据驻留规定的连接复选框 ,使此连接符合 数据驻留要求。
如果您在创建连接时选中此复选框,则使用 Google Cloud 控制台创建的 GitHub 连接 符合数据驻留要求 。执行此操作后,Developer Connect 会创建一个 GitHub 应用
如果您使用 Google Cloud CLI 创建 GitHub 连接,则这些连接不符合数据驻留要求。所有其他连接类型都符合数据驻留要求。
- 对于主机网址,请输入要连接到的主机的网址。
点击显示更多 以查看可选配置设置。
可选:默认情况下,Developer Connect 可以充当代理,以便向 GitHub Enterprise 发出 Git 调用。 如需停用此选项,请取消选中启用 Developer Connect 代理 复选框。
对于网络类型,请选择公共互联网。
如果您想使用专用网络,请参阅 连接到专用网络中托管的 GitHub Enterprise 代码库。
可选:在加密 部分中,选择一个 CMEK 密钥来 加密 Developer Connect 创建的 Secret Manager 密钥。
点击继续 。
系统会显示一个 GitHub 对话框,邀请您创建 GitHub 应用。
按照 GitHub 中的提示,完成以下任务:
输入应用的名称。
选择要安装应用的组织。
选择要授予访问权限的代码库。
对话框随即关闭。
Developer Connect 会从 GitHub 获取您的私钥,并将其作为 Secret Manager 密钥存储在您的 Google Cloud 项目中。如需查看密钥, 请在 Secret Manager 中列出密钥。
创建连接后,系统会显示关联代码库 页面。
如需将代码库与连接相关联,请完成以下步骤:
在可用代码库列表中,选择要使用的代码库。
点击确定 。
点击关联 。
您的连接会添加到控制台的连接页面,而您的代码库 链接会添加到代码库页面。 Google Cloud 您可以随时向现有连接添加更多链接。
如果您要设置 Gemini Code Assist,请按照 配置和使用 Gemini Code Assist 代码自定义 中的步骤继续该过程。
gcloud
以下任务需要在网络浏览器中执行一些操作。
如需启动连接,请完成以下步骤:
运行
gcloud developer-connect connections create命令,以创建与 GitHub Enterprise 的连接:gcloud developer-connect connections create CONNECTION_NAME \ --location=REGION \ --github-enterprise-config-host-uri=HOST_URI --git-proxy-config-enabled替换以下内容:
您必须创建一个 GitHub 应用,才能管理与 GitHub 的连接。运行以下命令以获取应用设置的 URI:
gcloud developer-connect connections describe CONNECTION_NAME \ --location=REGION替换以下内容:
- CONNECTION_NAME:连接的名称。
- REGION:连接的 区域。
Developer Connect 会返回一个链接,以便您在浏览器窗口中完成后续步骤。复制此链接。
在网络浏览器中打开该链接。
如果系统提示您登录 GitHub 账号,请登录。
按照 GitHub 中的提示,完成以下任务:
输入应用的名称。
选择要安装应用的组织。
选择要授予访问权限的代码库。
对话框随即关闭。
Developer Connect 会从 GitHub 获取您的私钥,并将其作为 Secret Manager 密钥存储在您的 Google Cloud 项目中。如需查看密钥, 请在 Secret Manager 中列出密钥。
验证连接
运行以下命令,验证 GitHub 连接的创建情况:
gcloud developer-connect connections describe CONNECTION_NAME \
--location=REGION
其中:
- CONNECTION_NAME:连接的名称。
- REGION:连接的区域。
Developer Connect 会在 installationState 字段中返回状态。如果此字段的值为 COMPLETE,则表示应用安装已完成。
否则,Developer Connect 会返回一个 URI,以便您返回到浏览器中的配置。
连接完成后,请按照关联到代码库中的说明选择要关联的代码库。
向现有连接添加代码库链接
与 GitHub Enterprise 建立连接后,您可以关联到代码库。您可以稍后重复执行这些步骤,以便根据需要关联其他代码库。
如需在现有 GitHub Enterprise 连接上创建代码库链接,请选择以下选项之一:
控制台
在 Google Cloud 控制台中打开代码库 页面。
点击关联代码库 。
关联 Git 代码库 窗格随即打开。
在连接列表中,选择一个连接。
点击继续 。
在代码库列表中,选择要关联到的代码库。
点击创建 。
Developer Connect 会创建代码库链接,并在 控制台 Google Cloud 中显示这些链接。
gcloud
运行以下命令:
gcloud developer-connect connections git-repository-links create REPO_NAME \
--clone-uri=REPO_URI \
--connection=CONNECTION_NAME \
--location=REGION
替换以下内容:
- REPO_NAME:代码库链接的名称。
- REPO_URI:代码库的链接。
例如
https://github.com/cloud-build/test-repo.git。 - CONNECTION_NAME:连接的名称。
- REGION:连接的 区域。
Developer Connect 会创建代码库链接。
如需列出关联的代码库,请运行
developer-connect connections git-repository-links list 命令。
如果您要设置 Gemini Code Assist,请按照 配置和使用 Gemini Code Assist 代码自定义 中的步骤继续该过程。
数据共享
与此连接关联的 Google Cloud 资源的内容可能会 转移到 GitHub。此声明适用于目前和未来使用此连接的所有资源。如需停止与 GitHub 共享信息, 请在 控制台或 gcloud CLI 中删除 Developer Connect 连接,并在 GitHub 中撤消访问权限。 Google Cloud
后续步骤
- 完成 Gemini Code Assist 代码自定义的设置。
- 了解 Gemini Code Assist 如何帮助您加快软件开发速度。
- 探索可通过 Developer Connect 实现的其他集成。