如何将自定义 Cloud Builders 与来自 Google Artifact Repository 的图像一起使用

How to use custom Cloud Builders with images from Google Artifact Repository

如何在 Cloud Build 中使用存储在 Artifact Registry(而不是 Container Registry)存储库中的自定义构建器映像?

我在 Cloud Build 中设置了一个管道,其中一些 python 代码使用官方 python 图像执行。因为我想缓存我的 python 依赖项,所以我想创建一个自定义 Cloud Builder,如官方文档 here.

所示

GCP 明确表示要切换到 Artifact Registry,因为 Container Registry 将被前者取代。因此,我已将 docker 图像推送到 Artifact Registry。我还向我的 Cloud Builder 服务帐户授予了对 Artifact Registry 的 reader 权限。

像这样在云构建步骤中使用图像

steps:
  - name: 'europe-west3-docker.pkg.dev/xxxx/yyyy:latest'
    id: install_dependencies
    entrypoint: pip
    args: ["install", "-r", "requirements.txt", "--user"]

抛出以下错误

Step #0 - "install_dependencies": Pulling image: europe-west3-docker.pkg.dev/xxxx/yyyy:latest Step #0 - "install_dependencies": Error response from daemon: manifest for europe-west3-docker.pkg.dev/xxxx/yyyy:latest not found: manifest unknown: Requested entity was not found.

“xxxx”是存储库名称,“yyyy”是我的图像名称。标签“最新”存在。 我可以在本地拉取镜像并访问存储库。

我找不到任何关于如何从 Artifact Registry 集成这些图像的文档。只有 this official guide,其中图像是使用 Container Registry 中的 Docker 图像构建的 – 但这不应该是未来的证据。

您似乎需要将项目 ID 添加到图像名称中。 您可以使用“$PROJECT_ID”Cloud Build 默认替换变量。 因此,您更新后的图像名称将如下所示:

steps:
  - name: 'europe-west3-docker.pkg.dev/$PROJECT_ID/xxxx/yyyy:latest'

有关在 Cloud Build 中替换变量值的更多详细信息,请参阅:

https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values