[英]Connecting Google Compute Engine with Google App Engine
[英]Unable to deploy container images on Google Compute Engine
我正在嘗試使用cloudbuild.yaml
在 Compute Engine 上部署我的容器映像,但出現錯誤。 下面是我的cloudbuild.yaml
文件內容:
# gis-account-manager -> Project ID on GCP
steps:
# Build the Docker image.
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/gis-account-manager/ams', '-f', 'Dockerfile', '.']
# Push it to GCR.
- name: gcr.io/cloud-builders/docker
args: ['push', 'gcr.io/gis-account-manager/ams']
# Deploy to Prod env (THIS STEP IS FAILING)
- name: gcr.io/cloud-builders/gcloud
args: [ 'compute', 'instances', 'update-container', 'instance-2-production' , '--container-image', 'gcr.io/gis-account-manager/ams:latest']
# Set the Docker image in Cloud Build
images: ['gcr.io/gis-account-manager/ams']
# Build timeout
timeout: '3600s'
錯誤:
開始步驟#2
第 2 步:已經有圖像(帶摘要):gcr.io/cloud-builders/gcloud
第 2 步:錯誤:(gcloud.compute.instances.update-container) 未指定資源 [instance-2-production]。 指定 [--zone] 標志。
如果我從 Cloud SDK Sheel 運行相同的命令,它會按預期工作。
PS:我也嘗試過提供 ZONE Flag。
您需要在 gcloud compute 命令中指定您的區域:
# Deploy to Prod env (THIS STEP IS FAILING)
- name: gcr.io/cloud-builders/gcloud
args: [ 'config', 'set', 'compute/zone', 'us-central1-a']
- name: gcr.io/cloud-builders/gcloud
args: [ 'compute', 'instances', 'update-container', 'instance-2-production' , '--container-image', 'gcr.io/gis-account-manager/ams:latest']
您需要從此列表中按區域更改 asia-east1 。 並且由於您正在更新容器,因此可能已經指定了區域。
您可以編寫命令: gcloud compute zones list
以列出所有可用區域
Cloud Build 沒有足夠的權限來執行該操作,因此您在 Cloud Build 上操作時會收到錯誤消息,但在
gcloud
命令行工具中執行相同操作時不會收到錯誤gcloud
,該工具的工作方式有所不同。
我授予這些 Cloud Build Service Account 和 Cloud Build Service Agent Compute Admin 角色:
我的cloudbuild.yaml
看起來與您現在應該擁有的相同:
steps:
- name: gcr.io/cloud-builders/gcloud
args: [ 'config', 'set', 'compute/zone', 'YOUR_ZONE']
- name: gcr.io/cloud-builders/gcloud
args: [ 'compute', 'instances', 'update-container', '[YOUR_INSTANCE_NAME]' , '--container-image', 'gcr.io/gis-account-manager/ams:latest']
其中[YOUR_ZONE]
是您配置的區域, [YOUR_INSTANCE_NAME]
是您的實例名稱。
我建議您閱讀此文檔以了解有關 Cloud Build 服務帳戶權限的更多信息。
我已經通過服務帳戶進行身份驗證解決了這個問題(首先需要為 Compute Engine 服務帳戶生成密鑰)。
更新了cloudbuild.yaml
文件:
# Deploy to GOOGLE COMPUTE ENGINE Prod env
- name: gcr.io/cloud-builders/gcloud
args: [ 'auth', 'activate-service-account', '123456789-compute@developer.gserviceaccount.com', '--key-file=PATH_TO_FILE', '--project=${_PROJECT_ID}']
- name: gcr.io/cloud-builders/gcloud
args: ['compute', 'instances', 'update-container', '${_VM_INSTANCE}' , '--container-image=gcr.io/${_PROJECT_ID}/ams:latest', '--zone=us-central1-a']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.