GCP 创建或替换 Cloud Run 任务

huangapple go评论56阅读模式
英文:

GCP Create or replace Cloud Run Job

问题

有没有用于创建或替换Cloud Run作业的GCP命令?我正在使用GitHub Actions来创建Cloud Run和调度器作业,并需要在以下命令之间切换:

gcloud alpha run jobs create

gcloud alpha run jobs update

有没有一种方法可以创建作业并在已存在时进行覆盖?

英文:

Is there a GCP command for creating OR replacing a cloud run job? I'm using github-actions to create cloud run and scheduler jobs, and need to keep switching the commands between:

gcloud alpha run jobs create

and

gcloud alpha run jobs update

Is there a way to create the job and overwrite it if it already exists?

答案1

得分: 2

gcloud beta run jobs deploy是最近添加到gcloud中的,它可以完成您寻找的操作。文档在这里

英文:

gcloud beta run jobs deploy was recently added to gcloud which does what you're looking for. Documentation is here

答案2

得分: 1

要创建一个Cloud Run新作业:

gcloud beta run jobs create JOB_NAME --image IMAGE_URL OPTIONS

要更新现有作业:

gcloud beta run jobs update JOB_NAME

如果您希望使用单个命令同时处理创建和更新,您可以开发自己的Shell脚本,示例:

#!/usr/bin/env bash

set -e
set -o pipefail
set -u

export JOB_NAME=my_job

res=$(gcloud beta run jobs describe $JOB_NAME --region=europe-west1 || echo "NOT_EXIST")

echo "#######Result : $res"

if [ "$res" = "NOT_EXIST" ]; then
  echo "Creating your job..."
  gcloud beta run jobs create $JOB_NAME
else
  echo "Updating your job..."
  gcloud beta run jobs update $JOB_NAME
fi
英文:

To create a Cloud Run new job :

gcloud beta run jobs create JOB_NAME --image IMAGE_URL OPTIONS

To update existing job :

gcloud beta run jobs update JOB_NAME

If you want a single command to handle the creation and update at the same time, you can develop your own Shell script, example :

#!/usr/bin/env bash

set -e
set -o pipefail
set -u

export JOB_NAME=my_job

res=$(gcloud beta run jobs describe $JOB_NAME --region=europe-west1 || echo "NOT_EXIST")

echo "#######Result : $res"

if [ "$res" = "NOT_EXIST" ]; then
  echo "Creating your job..."
  gcloud beta run jobs create $JOB_NAME
else
  echo "Updating your job..."
  gcloud beta run jobs update $JOB_NAME
fi

huangapple
  • 本文由 发表于 2023年2月14日 18:45:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75446719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定