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.
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.
npm_package_version and change with sed . by - (GAE is ok with hyphen)GAE_VERSION)gcloud command to deploy using GAE_VERSION variable.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With