使用gcloud停止当前版本的应用引擎的推荐方式是什么? [英] What's the recommended way to stop the current version of app engine using gcloud?

查看:107
本文介绍了使用gcloud停止当前版本的应用引擎的推荐方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过运行bash脚本自动启动/停止我们的应用程序引擎服务。

I want to automatically start/stop our app engine services by running a bash script.

我知道很容易运行 gcloud应用版本的开始/停止,但我不想手动检查版本号。我想动态地将提供100%流量的版本传递给gcloud并告诉它停止。

I know it's easy to run gcloud app versions start/stop, but I don't want to manually check the version number. I want to dynamically pass the version that is serving 100% traffic to gcloud and tell it to stop.

另一方面,我也想告诉gcloud启动最近部署的版本。

On the flip side, I also want to tell gcloud to start the most recently deployed version.

什么是推荐的方式做到这一点?

What's the recommended way to do this?

谢谢!

Thanks!

推荐答案

One方法是使用 gcloud 的键和标志: 预测 - format - filters 。要直接从终端阅读,请使用 gcloud topic

One way to do that is to use gcloud's keys and flags: projections, --format, --filters. To read more directly from the terminal use gcloud topic, for example:

gcloud topic projections

为了查看哪些字段/属性可用,使用 - format = flattened ,例如:

In order to see what fields/properties are available use --format=flattened, like:

gcloud app services list --format=flattened

为简单起见,我会离开一切,但不包括 gcloud

For the sake of simplicity I will leave outside everything but gcloud.

for SERVICE in $(gcloud app services list --format='table[no-heading](id)'); do
    echo "for service $SERVICE :"

    RECENT=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE" | tail -n1)

    echo 'y' | gcloud app versions start $RECENT

    VERSIONS=$(gcloud app versions list --format='table[no-heading](id)' --filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" | tr '\n' ' ')

    echo 'y' | gcloud app versions stop $VERSIONS
done

'表格[no -heading](service)'输出一个没有标题的表格,标题设置在括号内,单个列标注设置在括号内的服务标识。

'table[no-heading](service)' outputs a table without heading, which is set in brackets, and a single column with service IDs, which is set in parentheses.

- filter =service = $ SERVICE AND version.servingStatus = SERVING AND NOT id = $ RECENT将仅显示正在服务的指定服务的版本,除了 RECENT

--filter="service=$SERVICE AND version.servingStatus=SERVING AND NOT id=$RECENT" will only show versions from indicated service that are serving, except the one indicated by RECENT.

所显示的值之外,如果您想要使用日期进行过滤:

Additionally, if you would want to use dates for filtering:

gcloud app versions list --format='table(id, version.servingStatus, version.createTime.date(format="%s"))' --filter="service=default" --sort-by="~version.createTime"

version.createTime.date(format =%s)函数日期转换 version.createTime .date 为自Epoch以来的秒数。

version.createTime.date(format="%s") is a function date converting version.createTime.date into the number of seconds since the Epoch.

%s 来自 strftime(3)并以Epoch格式返回日期更容易理解和比较。

%s comes from strftime(3) and returns dates in Epoch format which is easier to understand and compare.

- sort-by =〜version.createTime按创建日期排序并且因为以降序排列。

--sort-by="~version.createTime"sorts by creation date and because of ~ in descending order.

这篇关于使用gcloud停止当前版本的应用引擎的推荐方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆