Alan
Alan

Reputation: 1700

Multiple NodeJS Services/Modules on Google App Engine Flexible Environment

I'm struggling to figure out how to deploy multiple nodejs services on google app engine flexible.

I'm using multiple nodejs classes with firebase-queue to process my tasks. Right now, i'm using my package.json to trigger starting everything at once. However, this has become problematic. I would like to be able to push a change to one particular service/script without having to stop every other script.

My package.json currently looks like something like this:

"scripts": {
    "task1": "node ./src/task1.js",
    "task2": "node ./src/task2.js",
    "start": "npm-run-all -p task1 task2"
}

I'm using different .yaml files to determine which build variant I want to push (Debug or Release) but am finding it hard to deploy each task individually. I found documentation on how to do so in python, but nothing on nodejs. Does anyone have any suggestions?

Upvotes: 5

Views: 1864

Answers (2)

Alan
Alan

Reputation: 1700

(Answering my own question, big thanks to Justin for helping)

I was specifically having issues dynamically changing the script to start in my package.json. I found the package.json can access environment variables using '$'

package.json:

"scripts": {
    "start": "node $SCRIPT_TO_RUN"
}

myService.yaml

runtime: nodejs
vm: true
api_version: 1
instance_class: B4
manual_scaling:
  instances: 1
service: cart-monitor-dev

env_variables:
  SCRIPT_TO_RUN: './src/mytask.js'

Then deploy using:

gcloud app deploy myService.yaml

Upvotes: 7

Justin Beckwith
Justin Beckwith

Reputation: 7866

This is exactly why App Engine services exist :) You can create a {serviceName}.yaml for each service you want to deploy. Then, call gcloud app deploy service.yaml for each one. That creates multiple services in the same app. For an example see:

https://github.com/JustinBeckwith/cloudcats

Hope this helps!

Upvotes: 4

Related Questions