4

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?

Alan
  • 1,510
  • 1
  • 18
  • 35
  • 1
    I hear you, I have been on this topic for awhile now trying to figure out a way to send device-to-device notification; say when a new message arrives. I can't provide you any help as I'm trying to figure out how to deploy the Firebase queue on app engine and get it to work. I would appreciate it if there's any hint or tutorial you have come across that I could use for that. sorry again for not being to help.. – TheBen Oct 16 '16 at 18:49
  • @TheeBen Create a my-queue-processer.js for each type of queue task, follow firebase-queue guides for setup, then use my below answer to separate into individual services, and deploy – Alan Dec 14 '16 at 17:16
  • thanks, I've setup up the firebase queue. just wondered about having multiple of those and I was pretty sure there should be a way to combine them. I'm trying to find the optimized way to reduce the cost on google app engine – TheBen Dec 14 '16 at 18:54
  • @TheeBen I was running everything on a single service, but i'm just realising each service uses an instance. Bills will run high! They worked fine on a single service, but the risk of one exception taking them all out is worrying.. Let me know if you find anything – Alan Dec 14 '16 at 21:26

2 Answers2

7

(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
Alan
  • 1,510
  • 1
  • 18
  • 35
  • This is exactly what I was looking for! The documentation talks about how great the microservices architecture is but doesn't actually explain how you run different services in the same project. – Aron Jan 20 '17 at 11:33
4

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!

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
  • Thanks Justin, I'm doing so to determine whether I'm deploying production or development builds. It's the default "scripts":{"start":"scripts to run..."} in package.json that I need to define dynamically. I can't figure out how to do so using the yaml. Any tips? I had a look at your repo but it also seems to only be running a single service? Appreciate the help – Alan Dec 14 '16 at 11:07