Zam*_*ues 2 google-cloud-platform gcloud google-cloud-functions
我正在使用以下命令来更新已部署的 GCP Cloud 功能的标签。
$ gcloud functions deploy GCFunction --update-labels env=dev,app=myapp
Deploying function (may take a while - up to 2 minutes)...failed.
Run Code Online (Sandbox Code Playgroud)
当我们尝试更改现有函数的标签时,它看起来会进行部署。我们是否可以在不进行任何部署的情况下进行标签更改,就像任何其他 API 或云函数一样来完成相同的任务。
有用。
PROJECT=[[YOUR-PROJECT]]
REGION=[[YOUR-REGION]]
FUNCTION=[[YOUR-FUNCTION]]
ENDPOINT="https://cloudfunctions.googleapis.com/v1"
NAME="projects/${PROJECT}/locations/${REGION}/functions/${FUNCTION}"
URL="${ENDPOINT}/${NAME}"
gcloud functions describe ${FUNCTION} \
--project=${PROJECT} \
--region=${REGION} \
--format="yaml(labels)"
labels:
app: myapp
deployment-tool: cli-gcloud
env: dev
curl \
--request PATCH \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json" \
--data "{\"labels\":{\"env\":\"testing\"}}" \
${URL}?updateMask=labels
gcloud functions describe ${FUNCTION} \
--project=${PROJECT} \
--region=${REGION} \
--format="yaml(labels)"
labels:
env: testing
Run Code Online (Sandbox Code Playgroud)
注意您需要复制要保留的标签。在我的示例中,我没有重复
app
,它被 PATCH 删除。
注意响应正文是一个异步操作,因此您需要检查其完成情况。
如果您安装了最优秀的jq
(或类似的 JSON 解析器),那么您可以轮询操作的状态,直到它完成(更好的是,也为读者设置一个超时...)。
ENDPOINT="https://cloudfunctions.googleapis.com/v1"
NAME="projects/${PROJECT}/locations/${REGION}/functions/${FUNCTION}"
URL="${ENDPOINT}/${NAME}"
TOKEN=$(gcloud auth print-access-token)
VALUE="full-testing"
DATA="{\"labels\":{\"env\":\"${VALUE}\"}}"
NAME=$(curl \
--silent \
--request PATCH \
--header "Authorization: Bearer ${TOKEN}" \
--header "content-type: application/json" \
--data "${DATA}" \
${URL}?updateMask=labels |\
jq -r .name) && echo ${NAME}
URL="${ENDPOINT}/${NAME}"
while [ $(curl --silent --request GET --header "Authorization: Bearer ${TOKEN}" ${URL} | jq -r .done) != "true" ]
do
printf "."
sleep 15s
done
gcloud functions describe ${FUNCTION} \
--project=${PROJECT} \
--region=${REGION} \
--format="yaml(labels)"
Run Code Online (Sandbox Code Playgroud)
我无法找到gcloud functions operations
已实现的。
归档时间: |
|
查看次数: |
3854 次 |
最近记录: |