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:
- SailsJS for API-layer
- Mocha test suite integration for SailsJS (based on http://stackoverflow.com/questions/21798840/how-use-mocha-test-framework-with-node-js-and-sails-js)
- Full Docker support for deployment (see the 'devops' folder)
- Setup for local testing with and production with PM2 and nodemon.
- Checkout this repository and delete the '.git' folder to be able to add the files to your own revision control system.
- 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).
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.
The 'devops' folder also contains helper scripts for deploying your service via Docker. Two steps are necessary to configure the deployment:
- Change the name of your service in ./devops/service-info.txt to your liking
- 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:
- Build the docker container via './devops/docker-build-image.sh'. The docker image will be available as 'local/your-service-name' afterwards.
- 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').