如何将package.json版本ID部署到AppEngine灵活环境--version参数? [英] How do I deploy the package.json version id to AppEngine flexible environment --version argument?
问题描述
使用gcloud app deploy
部署AppEngine灵活环境通常较慢,因为AppEngine必须先部署容器环境,然后才能部署代码并将流量切换到该环境.
AppEngine Flexible Environment deploys using gcloud app deploy
are generally slow because AppEngine has to spin up the container environment before deploying the code and switching traffic to it.
加快部署速度的常见方法是指定版本,这样AppEngine会将新代码部署到相同的容器环境中.如:
A common method to speed up the deployment is to specify the version, that way AppEngine deploys new code to the same container environment. Such as:
gcloud app deploy --version=12345
在节点环境中,我想在我的部署脚本中使用package.json版本,例如:
In a node environment, I would like to use the package.json version in my deploy scripts, for example:
{
"name": "MyApp",
"version": "1.3.4",
"scripts": {
"deploy":"gcloud app deploy --version=$npm_package_version"
}
NPM开箱即用,将配置中的值添加到以$ npm_package_为前缀的环境变量中,这样就可以了.
NPM takes the values in the config and adds it to environment variables prefixed with $npm_package_ out of the box so that's fine.
但是,AppEngine的版本名称不接受.
.
However, AppEngine does not accept .
in their version names.
因此,我正在寻找一种将$ npm_package_version转换为AppEngine批准的版本号的好方法,然后才能将其传递到<scripts>
节点上的gcloud
中.
So I am looking for a good way to transform $npm_package_version into an AppEngine-approved version number before being able to pass it into gcloud
on the <scripts>
node.
推荐答案
我找到了一个适用于我的简单解决方案.
I've found a simple solution that works for me.
在我被选好的package.json
{
"name": "...",
"version": "1.0.1",
"scripts": {
"deploy": "GAE_VERSION=$(echo ${npm_package_version} | sed 's/\\./-/g') && gcloud app deploy --version $GAE_VERSION"
},
"dependencies": {...},
"devDependencies": {...}
}
实际上-这很简单.
- 获取
npm_package_version
并由-
更改为sed
.
(连字符可以使用GAE) - 将结果分配给变量(此处为
GAE_VERSION
) - 使用
gcloud
命令使用GAE_VERSION
变量进行部署.
- get
npm_package_version
and change withsed
.
by-
(GAE is ok with hyphen) - Assign the result to a variable (here :
GAE_VERSION
) - Use
gcloud
command to deploy usingGAE_VERSION
variable.
这篇关于如何将package.json版本ID部署到AppEngine灵活环境--version参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!