moleculer template for byte microservices
This is a moleculer template for Byte Technology micro-services. This will provide a functional service along with required packages and tooling to build a micro-service for the Byte Technology cloud backend.
- Install Node.js (preferred version 12 or higher) and npm.
- Setup micro-dev-environment (BYTE_SW_MICRO_REPO_PATH should be set)
- Install moleculer comman line interface
sudo npm install -g moleculer-cli
- Create new service code via moleculer-cli. Below command will create service basing on
master
branch of micro-service-template repo in BYTE_SW_MICRO_REPO_PATH:
moleculer init --no-install "bytetechnology/micro-service-template" micro-<SERVICE_NAME>
You can specify branch using #
:
moleculer init --no-install "bytetechnology/micro-service-template#my/branch" micro-<SERVICE_NAME>
-
Add your new service to git repo
https://github.com/bytetechnology/micro-<SERVICE_NAME>
-
Add new service from BYTE_SW_MICRO_REPO_PATH/micro-dev-environment
sh add-new-service.sh <SERVICE_NAME>
At point 3. you created new file micro-dev-environment/docker-compose.<SERVICE_NAME>.yml
- it is definition of container that serves you to run service in dev env. To use it just call from micro-dev-environment sh up.sh -d
.
You have 2 options for development:
- Run service on host OS - can be faster but you will be only able to run tests (no dev mode runtime)
- Run service in container.
! Imporant:
- If you made
npm install
from host OS and you want to work inside container then remove node_modules direcory and install it again from inside container. The same for opposite scenario.
Prerequisites:
Windows: - npm i -g windows-build-tools
via admin powershell
Linux: - apk add --no-cache make gcc g++ python git
npm install
frommicro-<SERVICE_NAME>
dir. If failed try multiple times.npm test
to run tests
Prerequisites:
- After you've created new
.yml
file viash add-new-service.sh <SERIVCE_NAME>
you should have running container for your new service. From BYTE_SW_MICRO_REPO_PATH/micro-dev-environment callsh up.sh
Steps:
- go into container. From
micro-<SERVICE_NAME>
dir call: sh enter-container
npm install
npm test
to run testsnpm run dev
to run service in development environment with interactive moleculer-cli.
- Services need to be written in TypeScript.
- 100% unit test coverage is expected.
- Run
npm run lint
and fix any issues before checking in. - Format your code ``npm run format`. There should be NO comments in code reviews about format issues.
There is a Dockerfile that will generate a production ready docker image:
docker build -t "bytetechnology/<service>:latest" .
- Do not modify
src/lib
- it is readonly - Do not modify filenames or export names of (files used by
src/lib
):api/index.ts
env.schema.ts
service.types.ts
- Server framework - moleculer + TypeScript overlay libs
- DB framework - mikro-orm
- Data Validation (config and payloads) - joiful.
- Don't try to put
index.ts
insidesrc/lib
(briefly - you may end up with undefined dependencies at runtime).
Feel free to update above list.