The Wayback Machine - https://web.archive.org/web/20230117162936/https://docs.github.com/zh/codespaces/setting-up-your-project-for-codespaces/configuring-dev-containers/setting-a-minimum-specification-for-codespace-machines
Skip to main content

Setting a minimum specification for codespace machines

You can avoid under-resourced machine types being used for GitHub Codespaces for your repository.

Who can use this feature

People with write permissions to a repository can create or edit the codespace configuration.

Overview

Each codespace that you create is hosted on a separate virtual machine. When you create a codespace from a repository, you can usually choose from different types of virtual machines. Each machine type has different resources (processor cores, memory, storage) and, by default, the machine type with the least resources is used. For more information, see "Changing the machine type for your codespace."

If your project needs a certain level of compute power, you can configure GitHub Codespaces so that only machine types that meet these requirements can be used by default, or selected by users. You configure this in a devcontainer.json file.

未发布的 codespace(使用模板创建且未链接到 GitHub 上存储库的 codespace)始终在具有相同规范的虚拟机上运行。 无法更改未发布的 codespace 的计算机类型。

Important: Access to some machine types may be restricted at the organization level. Typically this is done to prevent people choosing higher resourced machines that are billed at a higher rate. If your repository is affected by an organization-level policy for machine types you should make sure you don't set a minimum specification that would leave no available machine types for people to choose. For more information, see "Restricting access to machine types."

Setting a minimum machine specification

  1. 存储库的 GitHub Codespaces 可在 devcontainer.json 文件中配置。 如果存储库尚未包含 devcontainer.json 文件,可以立即添加一个。 请参阅“将开发容器配置添加到存储库”。

  2. Edit the devcontainer.json file, adding the hostRequirements property at the top level of the file, within the enclosing JSON object. For example:

    JSON
    "hostRequirements": {
       "cpus": 8,
       "memory": "8gb",
       "storage": "32gb"
    }

    You can specify any or all of the options: cpus, memory, and storage.

    To check the specifications of the GitHub Codespaces machine types that are currently available for your repository, step through the process of creating a codespace until you see the choice of machine types. For more information, see "Creating a codespace for a repository."

  3. Save the file and commit your changes to the required branch of the repository.

    Now when you create a codespace for that branch of the repository, and you go to the creation configuration options, you will only be able to select machine types that match or exceed the resources you've specified.

    Dialog box showing a limited choice of machine types

Further reading