我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Virtual environments for GitHub-hosted runners

GitHub offers hosted virtual machines to run workflows. 虚拟机包含可供 GitHub 操作 使用的工具、包和设置。

GitHub 操作 is available with GitHub Free, GitHub Pro, GitHub Team, and GitHub Enterprise Cloud. GitHub 操作 is unavailable for per-repository plans, which are legacy billing plans. For more information, see "GitHub's products."

本文内容

About GitHub-hosted runners

A GitHub-hosted runner is a virtual machine hosted by GitHub with the GitHub 操作 runner application installed. GitHub offers runners with Linux, Windows, and macOS operating systems.

When you use a GitHub-hosted runner, machine maintenance and upgrades are taken care of for you. 您可以直接在虚拟机上或 Docker 容器中运行工作流程。

You can specify the runner type for each job in a workflow. Each job in a workflow executes in a fresh instance of the virtual machine. All steps in the job execute in the same instance of the virtual machine, allowing the actions in that job to share information using the filesystem.

Cloud hosts for GitHub-hosted runners

GitHub hosts Linux and Windows runners on Standard_DS2_v2 virtual machines in Microsoft Azure with the GitHub 操作 runner application installed. The GitHub-hosted runner is a fork of the Azure Pipelines Agent. 有关 Standard_DS2_v2 机器资源的更多信息,请参阅 Microsoft Azure 文档中的“DSv2-系列”。

GitHub uses MacStadium to host the macOS runners.

Administrative privileges of GitHub-hosted runners

Linux 和 macOS 虚拟机都使用无密码的 sudo 运行。 在需要比当前用户更多的权限才能执行命令或安装工具时,您可以使用无需提供密码的 sudo。 For more information, see the "Sudo Manual."

Windows virtual machines are configured to run as administrators with User Account Control (UAC) disabled. 更多信息请参阅“用户帐户控制工作原理”。

Supported runners and hardware resources

每台虚拟机都有相同的硬件资源。

  • 2-core CPU
  • 7 GB RAM 内存
  • 14 GB SSD 硬盘空间
虚拟环境 YAML 工作流程标签
Windows Server 2019 windows-latest
Ubuntu 18.04 ubuntu-latestubuntu-18.04
Ubuntu 16.04 ubuntu-16.04
macOS Catalina 10.15 macos-latest

For a list of supported software, tools, and packages for each runner, see "Software in virtual environments for GitHub 操作."

IP addresses of GitHub-hosted runners

Windows and Ubuntu runners are hosted in Azure and have the same IP address ranges as Azure Data centers. Currently, all hosted runners are in the East US 2 Azure region, but more regions may be added over time.

Microsoft 每周通过 JSON 文件更新 Azure IP 地址范围,您可以从 Azure IP 范围和服务标签 - 公共云网站下载该文件。 如果需要一个允许列表来阻止未经授权访问您的内部资源,您可以使用此 IP 地址范围。

JSON 文件包含一个名为 values 的数组。 在该数组内,您可以通过包含 "AzureCloud.eastus2"nameid 的对象找到支持的 IP 地址。

您可以在 "addressPrefixes" 对象中找到支持的 IP 地址范围。 这是 JSON 文件的精简示例。

{
  "changeNumber": 84,
  "cloud": "Public",
  "values": [
    {
      "name": "AzureCloud.eastus2",
      "id": "AzureCloud.eastus2",
      "properties": {
        "changeNumber": 33,
        "region": "eastus2",
        "platform": "Azure",
        "systemService": "",
        "addressPrefixes": [
          "13.68.0.0/17",
          "13.77.64.0/18",
          "13.104.147.0/25",
          ...
        ]
      }
    }
  ]
}

Filesystems on GitHub-hosted runners

GitHub executes actions and shell commands in specific directories on the virtual machine. The file paths on virtual machines are not static. Use the environment variables GitHub provides to construct file paths for the home, workspace, and workflow directories.

Directory 环境变量 描述
home HOME Contains user-related data. 例如,此目录可能包含登录凭据。
workspace GITHUB_WORKSPACE Actions and shell commands execute in this directory. 操作可以修改此目录的内容,后续操作可以访问这些修改。
workflow/event.json GITHUB_EVENT_PATH The POST payload of the webhook event that triggered the workflow. 每当操作执行时,GitHub 都会重写此变量,以隔离操作之间的文件内容。

For a list of the environment variables GitHub creates for each workflow, see "Using environment variables."

Docker 容器文件系统

在 Docker 容器中运行的操作在 /github 路径下有静态目录。 However, we strongly recommend using the default environment variables to construct file paths in Docker containers.

GitHub 保留 /github 路径前缀,并为操作创建三个目录。

  • /github/home

  • /github/workspace - Note: GitHub 操作 must be run by the default Docker user (root). Ensure your Dockerfile does not set the USER instruction, otherwise you will not be able to access GITHUB_WORKSPACE.

  • /github/workflow

延伸阅读

问问别人

找不到要找的内容?

联系我们