由于资源位置限制,Cloud Build 失败

Bla*_*ack 4 google-cloud-platform

我们制定了一项政策,将资源限制在欧盟地区。

\n\n

当我尝试执行云构建时,gcloud 希望创建一个存储桶 (gs://[PROJECT_ID]_cloudbuild) 来存储暂存源。此步骤失败,因为使用了默认存储桶位置 (\'us\'):

\n\n
"code": 412,\n"message": "\'us\' violates constraint \xe2\x80\x98constraints/gcp.resourceLocations\xe2\x80\x99"\n
Run Code Online (Sandbox Code Playgroud)\n\n

作为解决方法,我尝试传递位于有效区域中的现有存储桶(使用 --gcs-source-staging-dir),但出现了相同的错误。

\n\n

如何解决这个问题?

\n\n

这里是 HTTP 日志:

\n\n
$ gcloud --log-http builds submit --gcs-source-staging-dir gs://my-custom-bucket/staging \\\n--tag gcr.io/xxxxxxxxxx/quickstart-image .\n=======================\n==== request start ====\nuri: https://www.googleapis.com/storage/v1/b?project=xxxxxxxxxx&alt=json\nmethod: POST\n== headers start ==\naccept: application/json\ncontent-type: application/json\n== headers end ==\n== body start ==\n{"name": "my-custom-bucket"}\n== body end ==\n==== request end ====\n---- response start ----\n-- headers start --\nserver: UploadServer\nstatus: 412\n-- headers end --\n-- body start --\n{\n "error": {\n  "errors": [\n   {\n    "domain": "global",\n    "reason": "conditionNotMet",\n    "message": "\'us\' violates constraint \xe2\x80\x98constraints/gcp.resourceLocations\xe2\x80\x99",\n    "locationType": "header",\n    "location": "If-Match"\n   }\n  ],\n  "code": 412,\n  "message": "\'us\' violates constraint \xe2\x80\x98constraints/gcp.resourceLocations\xe2\x80\x99"\n }\n}\n\n-- body end --\n---- response end ----\n----------------------\nERROR: (gcloud.builds.submit) HTTPError 412: \'us\' violates constraint \xe2\x80\x98constraints/gcp.resourceLocations\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

Neb*_*tic 19

我找到了这个问题的解决方案。[PROJECT_ID]_cloudbuild创建项目(启用资源位置限制)后,您应该使用首选位置中的名称创建一个新存储桶。

如果您不这样做,云构建提交将自动在美国创建一个存储桶,这是不可配置的。由于资源限制,cloud build 无法在美国创建此存储桶,并且失败并出现以下错误:

ERROR: (gcloud.builds.submit) HTTPError 412: 'us' violates constraint 'constraints/gcp.resourceLocations'
Run Code Online (Sandbox Code Playgroud)

当您(手动)创建同名的存储桶时,cloudbuild 会将该存储桶作为默认存储桶。该解决方案并不是立即可见,因为对于应用资源限制时已经有 cloudbuild 存储桶的项目,问题不会出现。

  • @Tobbey我同意,他们至少应该抛出一个错误来指出正确的方向。因为失败的并不是实际运行,而是一个前提条件不满足。这可能是因为云构建首先在美国推出。但这不是借口,因为根据立法,公司通常希望将所有数据(包括构建工件)存储在某个区域内。 (3认同)
  • 这纯粹是疯狂。非常感谢您分享修复程序。我从来没有想象过谷歌会留下如此琐碎的东西。 (2认同)