Setting up node service - Arthyon/microservice-poc GitHub Wiki
This section describes how to set up a production image and development image for a node service.
Production image
A node production image is pretty straightforward to set up.
Start with a node image as the first stage, copy everything and install production dependencies. Copy these production-modules to another folder for now, and restore everything.
Run a build task to compile typescript and other needed steps.
Create a new stage to test the build.
Finally, create a stage to act as the released image. Copy the built files and the restored production modules. Then run a task from package.json, or another task (like pm2 start).
TODO: We should check out these best practices to see if our chosen image (pm2) is compliant. It is at least handling kernel signals correctly for us.
Development image
Start with the same image as the production stage uses, copy only settings-files (like yarn.lock, package.json, tsconfig.json) and run a yarn/npm restore.
Set NODE_ENV to development and run a package.json-task that builds and starts the server. Remember to run node with --inspect=0.0.0.0:9229 to enable debugging from outside the container.
Helm
We need to set up a few things in the kubernetes templates.
Expose the debug port 9229 from the container to a port on localhost. If there are more than one node-service, you must bind to different ports for each service.
Mount the local service directory into the directory inside the docker-container. This enables us to skip rebuilding the image every time our code changes.
This is done in values.dev.yaml
launch.json
A launch-configuration must be added for the service of type node. Start out by copying an existing one for easy setup.
port must be changed to the one you exposed in the template, and localroot must be updated to point to the folder your service resides in.