duraark-microservice-base

Base docker image and initial Sails.js setup a REST microservice.

Usage no npm install needed!

<script type="module">
  import duraarkMicroserviceBase from 'https://cdn.skypack.dev/duraark-microservice-base';
</script>

README

microservice-base

This is the documentation for 'microservice-base' source. Most likely you are reading this because you are using the generator-duraark scaffolding tool. If not I recommend to check out the project before returning to this page. generator-duraark allows you to scaffold microservices development and deploy environments via a CLI tool.

The microservice-base gives you a sane starting point for developing NodeJS based microservices with SailsJS.

The repository includes:

Installation

  1. Checkout this repository and delete the '.git' folder to be able to add the files to your own revision control system.
  2. Install SailsJS via 'sudo npm -g install sails'

After that you can add you own API logic via the SailsJS CLI (if you are not familiar with SailsJS have a look at the short introduction video).

Local development

For local development nodemon is used as process manager. To start developing locally change into the '_devops' folder and run the script 'serve-dev.sh' there (it is important to change into the _devops directory before, as the scripts are working relativ to this folder!). The SailsJS server is started on port 1337. We are currently not using the more sophisticated PM2 as process manager due to an issue where the service is constantly restarted when using PM2's '--watch' option.

Docker deployment

The 'devops' folder also contains helper scripts for deploying your service via Docker. Two steps are necessary to configure the deployment:

  1. Change the name of your service in ./devops/service-info.txt to your liking
  2. Have a look at the ./Dockerfile. Per default it installs NodeJS and SailsJS and starts the SailsJS server on port 1337.

To deploy the service do the following:

  1. Build the docker container via './devops/docker-build-image.sh'. The docker image will be available as 'local/your-service-name' afterwards.
  2. Start the docker container via './devops/docker-start-container.sh $PORT'.

When the container is started successfully the service is available on $PORT. If no $PORT is given as parameter SailsJS's default port 1337 is assumed.

Debugging the Docker container

The script './devops/docker-run-container.sh' starts the built docker container and gives you an interactive shell for debugging. You can also give the script a custom command as parameter. In this case the container will execute this command when the container starts (the default is '/bin/bash').