1

I am trying to integrate PM2 to Google Cloud App Engine but I just couldn't work it around. I am using PM2 for my site's staging site and I am very impressed with it. I use Digital Ocean droplet for staging. I realized that Google Cloud App Engine is not that flexible.

This is my package.json:

"main": "server.js",
"scripts": {
  "start": "NODE_ENV=production npm run server:prod",
  "server:prod": "node server.js",
  "server:stage": "NODE_ENV=stage pm2 start server.js --exp-backoff-restart-delay=100 -i max",
  "dev": "nodemon server.js",
  "gcp-deploy-stage": "gcloud app deploy app.backend.stage.yaml --project=xxxxx",
  "gcp-deploy-prod": "gcloud app deploy app.backend.prod.yaml --project=xxxx -v=alpha-16"
},

When I set production script start as staging like this:

"server:prod":"pm2 start server.js --exp-backoff-restart-delay=100 -i max"

and deploy this Google Cloud App Engine normally crashes because there is no global PM2 installed via NPM to start PM2.

Is there anybody went through this and made it work? Or any piece of code or any documentation that could lead me to the right solution?

Or the only option is migrating this to Google Cloud Compute Engine?

Thank you for reading this and your help.

1 Answers1

3

If you want to use any module, you're going to have to include it in your package.json. Have you tried running npm install --save-dev pm2, and then redeploying your site? My guess is, that's going to get you where you want to go.

All of that aside - this probably isn't a good idea :) pm2 does a lot to manage processes on the machine, specifically dealing with crashes. App Engine Flexible does a lot of this at the infrastructure layer, automatically looking at instance health. It uses docker under the hood, which has it's own restart strategy. And then on top of that, if the the docker retry strategy doesn't work, the Google Load Balancer kicks in and will start a new compute instance for you. It's entirely possible doing process level monitoring and restarting like this will work, I just want to make sure you understand everything else that's happening under the hood.

Curiosity killed the cat - why did you end up going with App Engine Flexible over App Engine Standard?

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55