如何将package.json版本ID部署到AppEngine灵活环境--version参数? [英] How do I deploy the package.json version id to AppEngine flexible environment --version argument?

查看:92
本文介绍了如何将package.json版本ID部署到AppEngine灵活环境--version参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用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": {...}
}

实际上-这很简单.

  1. 获取npm_package_version并由-更改为sed .(连字符可以使用GAE)
  2. 将结果分配给变量(此处为GAE_VERSION)
  3. 使用gcloud命令使用GAE_VERSION变量进行部署.
  1. get npm_package_version and change with sed . by - (GAE is ok with hyphen)
  2. Assign the result to a variable (here : GAE_VERSION)
  3. Use gcloud command to deploy using GAE_VERSION variable.

这篇关于如何将package.json版本ID部署到AppEngine灵活环境--version参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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