跳至主要内容

移除 Dependabot 对公共注册表的访问

示例:如何通过移除对公共注册表的调用,将 Dependabot 配置为仅访问私有注册表。

谁可以使用此功能?

具有 写入 访问权限的用户

关于将 Dependabot 配置为仅访问私有注册表

Dependabot 默认可以访问公共注册表,您还可以将其配置为访问私有注册表。有关私有注册表支持和配置的更多信息,请参阅 Configuring access to private registries for Dependabot。有关可用选项的深入信息,以及在配置私有注册表时的建议和指导,请参阅 Guidance for the configuration of private registries for Dependabot

为了更好地控制 Dependabot 对私有注册表和内部网络资源的访问,您可以将 Dependabot 配置为在 GitHub Actions 自托管运行程序上运行。更多信息,请参阅 About Dependabot on GitHub Actions runnersConfiguring Dependabot on self-hosted runners

您可以通过移除对公共注册表的调用,将 Dependabot 配置为仅访问私有注册表。这仅能对本文列出的生态系统进行配置。

Bundler

要将 Bundler 生态系统配置为仅访问私有注册表,您可以在 dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

Bundler 生态系统还要求在仓库中提交包含私有注册表 URL 的 Gemfile 文件。

YAML
# Example Gemfile

 source "https://private_registry_url"

Docker

要将 Docker 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中定义私有注册表配置,且不使用 replaces-base。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中移除 replaces-base: true

YAML
version: 2
registries:
  azuretestregistry: # Define access for a private registry
    type: docker-registry
    url: firewallregistrydep.azurecr.io
    username: firewallregistrydep
    password: ${{ secrets.AZUREHUB_PASSWORD }}

Dockerfile 中,以 IMAGE[:TAG] 的格式添加镜像名称,其中 IMAGE 由您的用户名和仓库名称组成。

YAML
 FROM firewallregistrydep.azurecr.io/myreg/ubuntu:22.04

选项 2

dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot。使用 replaces-base 配置的注册表可以作为镜像或拉取缓存使用。详细说明请参阅 Docker 文档中的 Registry as a pull through cache

Gradle

要将 Gradle 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中移除 replaces-base: true

此外,您还需要在 build.gradle 文件的 repositories 部分指定私有注册表的 URL。

# Example build.gradle file

repositories {
    maven {
        url "https://private_registry_url"
    }
}

Maven

要将 Maven 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

选项 2

pom.xml 文件中仅使用私有注册表的 URL。

<project>
...
 <repositories>
  <repository>
    <id>central</id>
    <name>your custom repo</name>
    <url>https://private_registry_url</url>
 </repository>
...
</project>

Node

npm

要将 npm 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中移除 replaces-base: true

npm 生态系统还要求在仓库中提交包含私有注册表 URL 的 .npmrc 文件。

YAML
 registry=https://private_registry_url

选项 2

如果在 .npmrc 文件中未定义全局注册表,您可以在 dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

对于作用域依赖(@my-org/my-dep),Dependabot 要求在项目的 .npmrc 文件中定义私有注册表。要为单独的作用域定义私有注册表,请使用 @myscope:registry=https://private_registry_url

Yarn

Dependabot 同时支持 Yarn Classic 与 Yarn Berry 的私有注册表,但两者需要不同的配置才能仅访问私有注册表。

Yarn Classic

要将 Yarn Classic 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中删除 replaces-base: true

为确保私有注册表作为依赖来源列在项目的 yarn.lock 中,请在能够访问私有注册表的机器上运行 yarn install。Yarn 应会更新 resolved 字段,包含私有注册表的 URL。

YAML
encoding@^0.1.11:
  version "0.1.13"
  resolved "https://private_registry_url/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9"
  integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==
  dependencies:
    iconv-lite "^0.6.2"

选项 2

如果 yarn.lock 未将私有注册表列为依赖来源,您可以按照常规包管理器的说明配置 Yarn Classic。

  1. dependabot.yml 文件中定义私有注册表配置。

  2. 在项目根目录的 .yarnrc 文件中添加键 registry 并设为私有注册表 URL;或者运行 yarn config set registry <private registry URL>

    YAML
    registry https://private_registry_url
    

选项 3

如果在 .yarnrc 文件中未定义全局注册表,您可以在 dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

对于作用域依赖(@my-org/my-dep),Dependabot 要求在项目的 .npmrc 文件中定义私有注册表。要为单独的作用域定义私有注册表,请使用 @myscope:registry=https://private_registry_url

Yarn Berry

要将 Yarn Berry 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中删除 replaces-base: true

为确保私有注册表作为依赖来源列在项目的 yarn.lock 中,请在能够访问私有注册表的机器上运行 yarn install。Yarn 应会更新 resolved 字段,包含私有注册表的 URL。

YAML
encoding@^0.1.11:
  version "0.1.13"
  resolved "https://private_registry_url/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9"
  integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==
  dependencies:
    iconv-lite "^0.6.2"

选项 2

如果 yarn.lock 未将私有注册表列为依赖来源,您可以按照常规包管理器的说明配置 Yarn Berry。

  1. dependabot.yml 文件中定义私有注册表配置。
  2. 在项目根目录的 .yarnrc.yml 文件中添加键 npmRegistryServer 并设为私有注册表 URL;或者运行 yarn config set npmRegistryServer <private registry URL>。示例:npmRegistryServer: "https://private_registry_url"

注意

对于作用域依赖(@my-org/my-dep),Dependabot 要求在项目的 .yarnrc 文件中定义私有注册表。要为单独的作用域定义私有注册表,请使用 "@myscope:registry" "https://private_registry_url"

NuGet

要使 NuGet 生态系统仅访问私有注册表,您可以在 dependabot.yml 文件中进行配置。更多信息,请参阅 Configuring access to private registries for Dependabot

NuGet 生态系统还要求在仓库中提交一个 nuget.config 文件,该文件在 <packageSources> 部分必须包含 <clear /> 标记,或在 disabledPackageSources 部分将键 nuget.org 设为 true。

以下示例展示了在 nuget.configpackageSources 部分使用 <clear /> 标记的写法。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <packageSources>
   < clear />
   <add key="example-nuget" value="https://private_registry_url/nuget/example-nuget/index.json" />
 </packageSources>
</configuration>

以下示例展示了在 nuget.configdisabledPackageSources 部分将键 nuget.org 设置为 true 的写法。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="example-nuget" value="https://private_registry_url/nuget/example-nuget/index.json" />
  </packageSources>
  <disabledPackageSources>
    <add key="nuget.org" value="true" />
  </disabledPackageSources>
</configuration>

若要将 Dependabot 配置为同时访问私有公共源,请参考下面的 dependabot.yml 示例,其中在 registries 下已配置了 public 源。

YAML
version: 2
registries:
  nuget-example:
    type: nuget-feed
    url: https://nuget.example.com/v3/index.json
    username: $
    password: $
  public:
    type: nuget-feed
    url: https://api.nuget.org/v3/index.json
updates:
  - package-ecosystem: nuget
    directory: "/"
    registries: "*"
    schedule:
      interval: daily

Python

Pip、Pip-compile、Pipenv 和 Poetry 是 Python 生态系统当前支持的四种包管理器。

Pip

要将 Pip 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中删除 replaces-base: true

pip.conf 文件的 [global] 部分添加私有注册表 URL,并将该文件提交到仓库。

YAML
[global]
timeout = 60
index-url = https://private_registry_url

选项 2

dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

Pip-compile

要将 Pip-compile 生态系统配置为仅访问私有注册表,您可以使用以下配置方法。

选项 1

dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

选项 2

dependabot.yml 文件中定义私有注册表配置。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中删除 replaces-base: true

requirements.txt 文件中添加私有注册表 URL,并将该文件提交到仓库。

YAML
--index-url https://private_registry_url

Pipenv

要将 Pipenv 配置为仅访问私有注册表,请从 dependabot.yml 文件中移除 replaces-base。更多信息,请参阅 Configuring access to private registries for Dependabot

注意

从配置文件中删除 replaces-base: true

Pipfile[[source]] 部分添加私有注册表 URL,并将该文件提交到仓库。

YAML
[[source]]
url = "https://private_registry_url"
verify_ssl = true
name = "pypi"

Poetry

要将 Poetry 配置为仅访问私有注册表,请在 dependabot.yml 文件中设置 replaces-base: true。更多信息,请参阅 Configuring access to private registries for Dependabot

pyproject.toml[[tool.poetry.source]] 部分添加私有注册表 URL,并将该文件提交到仓库。

YAML
[[tool.poetry.source]]
name = "private"
url = "https://private_registry_url"
default = true
© . This site is unofficial and not affiliated with GitHub, Inc.