【问题标题】:Can't Pull Google Source Repo During Automated Cloud Build在自动云构建期间无法提取 Google 源代码库
【发布时间】:2018-10-04 18:14:44
【问题描述】:

我有一个Dockerfile 用于构建将在 Google Compute Engine 上运行的映像。

Dockerfile 的一部分应提取 Google Cloud Source Repo 并将其添加到图像中。

使用 Cloud Builder 时出现以下错误:

```

Step 6/6 : RUN gcloud source repos clone repoXXX --project=projectXXX
---> Running in xxx
[91mERROR: (gcloud.source.repos.clone) You do not currently have an active account selected.
Please run:
  $ gcloud auth login 
    to obtain new credentials, or if you have already logged in with a different account:
  $ gcloud config set account ACCOUNT
    to select an already authenticated account to use.
The command '/bin/sh -c gcloud source repos clone repoXXX -- 
project=projectXXX' returned a non-zero code: 1

```

我不确定我在这里做错了什么?

我没有使用 cloudbuild.yaml 文件,但我认为 cloudbuilder 服务帐户能够提取存储库,因为它在 IAM 中具有编辑器访问权限。

我应该怎么做才能成功构建镜像?

更新:

如果您发现了这个问题,我可以通过以下两个步骤构建来添加 Google Cloud Source Repos:

  1. 构建cloudbuild.yaml 文件并包括以下步骤:

steps: # Pull Search Console repo to include in the build. - name: 'gcr.io/cloud-builders/gcloud' args: ['source', 'repos', 'clone', 'xxx']

  1. Dockerfile 中,您可以将工作区中的存储库复制到新映像中:

FROM xxx:latest # Copy the repo into Docker copy xxx /xxx

你可以阅读更多关于creating a basic build configuration file here的信息。

【问题讨论】:

  • 您定义的步骤不会创建 docker 映像,那么如何添加 FROM xxx:latest

标签: google-compute-engine google-container-registry


【解决方案1】:

--network=cloudbuild 添加到您的 args 以允许构建器服务帐户凭据传递到您的 Dockerfile 步骤。

steps:
- name: gcr.io/cloud-builders/docker
  args: ['build', '-t', 'THE_IMAGE', '--network=cloudbuild', '.']

【讨论】:

  • 我需要将这些参数添加到cloudbuild.yaml吗?
  • 是的,在您的 cloudbuild.yaml 中
猜你喜欢
  • 2016-05-17
  • 2020-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-01
  • 2014-01-22
  • 2020-08-11
  • 1970-01-01
相关资源
最近更新 更多