jasonsirota
jasonsirota

Reputation: 4061

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

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.

Upvotes: 3

Views: 877

Answers (1)

charnould
charnould

Reputation: 2907

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.

Upvotes: 4

Related Questions