Mic*_*ard 9 python service-accounts google-cloud-platform dockerfile google-cloud-build
在我的代码中,我尝试从 Cloud Build 中的关联服务帐户收集应用程序默认凭据:
from google.auth import default
credentials, project_id = default()
Run Code Online (Sandbox Code Playgroud)
这在我的本地空间中工作得很好,因为我已经适当地设置了环境变量GOOGLE_APPLICATION_CREDENTIALS。但是,当在 Cloud Build 中执行此行(通过构建配置中的测试步骤)时,会引发以下错误:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.
For more information, please see https://cloud.google.com/docs/authentication/getting-started
Run Code Online (Sandbox Code Playgroud)
这让我很困惑,因为根据文档:
默认情况下,Cloud Build 使用特殊服务帐户代表您执行构建。此服务帐号称为 Cloud Build 服务帐号,当您在 Google Cloud 项目中启用 Cloud Build API 时,它会自动创建。 在这里阅读
如果未设置环境变量 GOOGLE_APPLICATION_CREDENTIALS,ADC 将使用附加到正在运行代码的资源的服务帐户。 在这里阅读
那么为什么默认调用无法访问 Cloud Build 服务帐户凭据呢?
gui*_*ere 18
有一个技巧:您必须定义要在 Docker 构建中使用的网络。使用参数--network=cloudbuild,就像这样
steps:
- name: gcr.io/cloud-builders/docker
entrypoint: 'docker'
args:
- build
- '--no-cache'
- '--network=cloudbuild'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- 'Dockerfile'
...
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到文档
| 归档时间: |
|
| 查看次数: |
5782 次 |
| 最近记录: |