How do I deploy the package.json version id to App

2019-07-13 15:27发布

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条回答
Luminary・发光体
2楼-- · 2019-07-13 16:03

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.
查看更多
登录 后发表回答