你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure VMware 解决方案上配置 GitHub Enterprise Server

本文介绍如何在Azure VMware 解决方案私有云上设置 gitHub Enterprise Server(GitHub.com 的“本地”版本)。 该方案包含一个 GitHub Enterprise Server 实例,该实例可以为 3,000 名开发人员提供服务,这些开发人员在 GitHub Actions 上每分钟执行多达 25 个作业。 这包括(在撰写本文时)预览功能(例如 GitHub Actions)的设置。 要根据你的特定需求自定义设置,请查看在 VMware 上安装 GitHub Enterprise Server 中列出的要求。

开始之前

GitHub Enterprise Server 需要有效的许可证密钥。 可以注册 试用许可证。 如果要通过集成扩展 GitHub Enterprise Server 的功能,检查如果你有资格获得免费的五个席位的开发人员许可证。 通过 GitHub 的合作伙伴计划申请此许可证。

在 VMware 上安装 GitHub Enterprise Server

  1. 下载适用于 VMware ESXi/vSphere (OVA) 的最新版本的 GitHub Enterprise Server部署 OVA 模板(之前已下载)。

    Screenshot showing the GitHub Enterprise Server on VMware installation options.

    Screenshot showing the Deploy the OVA Template menu option.

  2. 为新虚拟机提供可识别的名称,例如 GitHubEnterpriseServer。 不需要在 VM 名称中包含发布详细信息,因为这些详细信息在升级实例时会变得陈旧。

  3. 选择所有默认值(稍后将编辑详细信息),并等待导入 OVA。

  4. 导入后,根据需要调整硬件配置。 在我们的示例方案中,我们需要以下配置。

    资源 标准设置 标准设置 +“Beta 功能”(操作)
    vCPU 4 8
    内存 32 GB 61 GB
    附加存储 250 GB 300 GB
    根存储 200 GB 200 GB

    你的需求可能会有所不同。 请参阅在 VMware 上安装 GitHub Enterprise Server 中关于硬件注意事项的指南。 另请参阅为 VMware 添加 CPU 或内存资源,以根据你的情况自定义硬件配置。

配置 GitHub Enterprise Server 实例

Screenshot of the Install GitHub Enterprise window.

打开新预配的虚拟机(VM)后, 请通过浏览器对其进行配置。 需要上传许可证文件并设置管理控制台密码。 请确保在安全的地方记下此密码。

Screenshot of the GitHub Enterprise SSH access screen to add a new SSH key.

建议至少执行以下步骤:

  1. 将公共 SSH 密钥上传到管理控制台,以便通过 SSH 访问管理 shell

  2. 在实例上配置 TLS,以便可以使用由受信任的证书颁发机构签名的证书。 应用设置。

    Screenshot showing the settings being applied to your instance.

  3. 在实例重启时,为 GitHub Actions 配置 Blob 存储。

    要在 GitHub Enterprise Server 上启用 GitHub Actions(当前可作为“beta 版本”功能),必须具备外部 blob 存储。 Actions 使用此外部 blob 存储来存储工件和日志。 GitHub Enterprise Server 上的 Actions 支持将 Azure Blob 存储作为存储提供程序(以及其他存储提供程序)。 需要使用 Blob 的存储帐户类型创建新的 Azure 存储帐户存储。

    Screenshot showing the instance details to enter for provisioning an Azure Blob Storage account.

  4. 新 Blob存储资源部署完成后,保存连接字符串(在访问密钥下可用)供以后使用。

  5. 实例重启后,在实例上创建新的管理员账户。 请务必也要记下该用户的密码。

    Screenshot showing the Create admin account for GitHub Enterprise.

其他配置步骤

要强化实例以用于生产用途,建议执行以下可选设置步骤:

  1. 配置高可用性以防止出现以下情况:

    • 软件崩溃(操作系统或应用程序级别)
    • 硬件故障(存储、CPU、RAM 等)
    • 虚拟化主机系统故障
    • 网络在逻辑或物理上切断
  2. 配置备份实用程序,提供用于灾难恢复的版本快照,并托管在与主实例分离的可用性中。

  3. 使用有效的 TLS 证书设置子域隔离,以缓解跨站点脚本和其他相关漏洞。

设置 GitHub Actions 运行器

此时,你应该有了一个正在运行的 GitHub Enterprise Server 实例,并创建了一个管理员帐户。 你还应该具有 GitHub Actions 用于持久性的外部 blob 存储。

创建用于使用 Azure VMware 解决方案 运行的 GitHub Actions 的某个位置。

  1. 在群集上配置新的 VM,并使其基于最新版本的 Ubuntu 服务器

    Screenshot showing the virtual machine name and location to provision a new VM.

  2. 继续完成设置,选择计算资源、存储和兼容性。

  3. 选择要在 VM 上安装的来宾 OS。

    Screenshot showing the Guest OS Family and Guest OS version to install on the VM.

  4. 创建 VM 后,接通其电源并通过 SSH 连接到该 VM。

  5. 接下来,安装 Actions 运行器应用程序,该应用程序从 GitHub Actions 工作流运行作业。 通过发布页面或运行以下快速脚本,确定并下载 Actions 运行器的最新 Linux x64 版本。 该脚本需要你的 VM 上同时存在 curl 和 jq

    LATEST\_RELEASE\_ASSET\_URL=$( curl https://api.github.com/repos/actions/runner/releases/latest | \
    
    jq -r '.assets | .[] | select(.name | match("actions-runner-linux-arm64")) | .url' )
    
    DOWNLOAD\_URL=$( curl $LATEST\_RELEASE\_ASSET\_URL | \
    
    jq -r '.browser\_download\_url' )
    
    curl -OL $DOWNLOAD\_URL
    

    你现在应该在 VM 上有一个本地文件,即 actions-runner-linux-arm64-*.tar.gz。 在本地提取这个 tarball:

    tar xzf actions-runner-linux-arm64-\*.tar.gz
    

    提取后将在本地解压缩一些文件,其中包括 config.shrun.sh 脚本。

启用 GitHub Actions

在 GitHub Enterprise Server 实例上配置和启用 GitHub Actions。

  1. 通过 SSH 访问 GitHub Enterprise Server 实例的管理 shell,然后运行以下命令:

  2. 设置包含 Blob 存储连接字符串的环境变量。

    export CONNECTION\_STRING="<your connection string from the blob storage step>"
    
  3. 配置操作存储。

    ghe-config secrets.actions.storage.blob-provider azure
    
    ghe-config secrets.actions.storage.azure.connection-string "$CONNECTION\_STRING`      
    
  4. 应用设置。

    ghe-config-apply
    
  5. 执行 pre检查,在 GitHub Enterprise Server 上安装 Actions 所需的更多软件。

    ghe-actions-precheck -p azure -cs "$CONNECTION\_STRING"
    
  6. 启用操作并重新应用配置。

    ghe-config app.actions.enabled true
    
    ghe-config-apply      
    
  7. 检查 Blob 存储的运行状况。

    ghe-actions-check -s blob
    

    应会看到以下输出:“Blob 存储正常”

  8. 现在已配置 GitHub Actions,请为用户启用。 以管理员身份登录到 GitHub Enterprise Server 实例,然后选择任意页面右上角的

  9. 在左侧边栏中,依次选择“企业概述”、“策略”、“操作”,然后选择用于为所有组织启用 Actions 的选项。

  10. 从“自托管运行器”选项卡中配置运行器。选择“新增”,然后从下拉菜单中选择“新建运行器”。 你会看到一组要运行的命令。

  11. 复制命令以配置运行器,例如

    ./config.sh --url https://10.1.1.26/enterprises/octo-org --token AAAAAA5RHF34QLYBDCHWLJC7L73MA
    
  12. 复制 config.sh 命令并将其粘贴到 Actions 运行器(先前已创建)上的会话中。

    Screenshot showing the GitHub Actions runner registration and settings.

  13. 使用 ./run.sh 命令运行运行器

    提示

    要使该运行器可用于企业中的组织,请编辑其组织访问权限。 可以将访问权限限制为组织的一个子集,甚至特定存储库。

    Screenshot of how to edit access for the self-hosted runners.

(可选)配置 GitHub Connect

尽管这一步骤是可选的,但如果你计划使用 GitHub.com 上可用的开源操作,我们建议执行该步骤。 它这一步可以让你在工作流中引用这些可重复使用的操作,从而在他人的工作基础上继续开发。

要启用 GitHub Connect,请遵循使用 GitHub Connect 启用对 GitHub.com 操作的自动访问权限

启用 GitHub Connect 之后,选择“在工作流运行中使用来自 GitHub.com 的操作的服务器”选项。

Screenshot of the Server can use actions from GitHub.com in workflow runs Enabled.

设置并运行首个工作流

现在已设置了 Actions 和 GitHub Connect,接下来让我们妥善运用。 这是一个示例工作流,该工作流引用了出色的 octokit/request-action,允许我们使用由 GitHub Actions 提供技术支持的 GitHub API 通过交互来为 GitHub 编写脚本。

在此基本工作流中,用于 octokit/request-action 使用 API 在 GitHub 上提出问题。

Screenshot of an example workflow.

注意

GitHub.com 托管该操作,但是当它在 GitHub Enterprise Server 上运行时,会自动使用 GitHub Enterprise Server API。

如果选择不启用 GitHub Connect,则可以使用以下备用工作流。

Screenshot of an alternative example workflow.

  1. 导航到你实例上的存储库,并将上述工作流添加为:.github/workflows/hello-world.yml

    Screenshot of another alternative example workflow.

  2. 在存储库的“操作”选项卡中,等待工作流程执行。

    Screenshot of an executed example workflow.

    可以看到它正在处理。

    Screenshot of the workflow processed by runner.

如果运行顺利,你应该在存储库中看到一个名为“Hello world”的新问题。

Screenshot of the Hello world issue in GitHub created by github-actions.

祝贺你! 你刚刚在 Azure VMware Solution 私有云上运行的 GitHub Enterprise Server 上完成了第一个 Actions 工作流。

本文在你的 Azure VMware 解决方案私有云之上设置了 GitHub Enterprise Server 的新实例,该实例是 GitHub.com 的自托管等效项。 该实例包括对 GitHub Actions 的支持,并使用 Azure Blob 存储来保持日志和工件的持久性。 但是,我们只是浅显地介绍了你可以通过 GitHub Actions 执行的操作。 在 GitHub 的 Marketplace上查看 Actions 列表,或自行创建

后续步骤

了解如何在 Azure VMware 解决方案 私有云上设置 GitHub Enterprise Server 后,请详细了解: