How do I deploy the package.json version id to AppEngine flexible environment --version argument?

陌路散爱 提交于 2019-12-23 22:23:56

问题


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.

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

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 takes the values in the config and adds it to environment variables prefixed with $npm_package_ out of the box so that's fine.

However, AppEngine does not accept . in their version names.

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.


回答1:


I've found a simple solution that works for me.

Below my troncated 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": {...}
}

This is - in fact - pretty simple.

  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.


来源:https://stackoverflow.com/questions/45065007/how-do-i-deploy-the-package-json-version-id-to-appengine-flexible-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!