英文:
Gcloud, Cloud build: Update all cloud run services with new image at once
问题
我有一个Cloud Build触发器,当在主分支上推送新的提交时,会将一个镜像推送到容器注册表。
当这种情况发生时,我想要使用新创建的镜像更新所有我的Cloud Run作业。
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
entrypoint: gcloud
args:
- beta
- run
- jobs
- update
- $_JOB_ID_1
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- --labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
问题在于我有类似N个作业ID(job-id1; job-id2 .... job-idN)。是否有一种方法可以迭代我作为替代变量提供的数组,以一次更新所有作业?
英文:
I have a Cloud Build trigger that push an image to container registry when a new commit is pushed on master branch.
When this occurs, I would like to update all my cloud run jobs with newly created image.
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
entrypoint: gcloud
args:
- beta
- run
- jobs
- update
- $_JOB_ID_1
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
The problem is that I have like N jobs ids (job-id1; job-id2 .... job-idN). Is there a way to iterate over an array I would give as substitution variable to update all jobs at once ?
答案1
得分: 1
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
env:
- HOST=$_GCR_HOSTNAME
- PROJECT=$PROJECT_ID
- REPO=$REPO_NAME
- SERVICE=$_SERVICE_NAME
- COMMIT=$COMMIT_SHA
id: 部署作业
script: |
#!/usr/bin/env bash
jobs=$(gcloud beta run jobs list --format="value(name)")
for job in $jobs; do
if [[ $job == *"prod"* ]]; then
gcloud beta run jobs update $job --image=$HOST/$PROJECT/$REPO/$SERVICE:$COMMIT --region=europe-southwest1
fi
done
英文:
I could do it like this:
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
env:
- HOST=$_GCR_HOSTNAME
- PROJECT=$PROJECT_ID
- REPO=$REPO_NAME
- SERVICE=$_SERVICE_NAME
- COMMIT=$COMMIT_SHA
id: Deploy Jobs
script: |
#!/usr/bin/env bash
jobs=$(gcloud beta run jobs list --format="value(name)")
for job in $jobs; do
if [[ $job == *"prod"* ]]; then
gcloud beta run jobs update $job --image=$HOST/$PROJECT/$REPO/$SERVICE:$COMMIT --region=europe-southwest1
fi
done
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论