Legacy Setting up a new service - Arthyon/microservice-poc GitHub Wiki
There are som things that need to be set up regardless of the technology used. This is outlined here.
For specifics about a technology, check out the Node or .Net sections.
Each service needs two dockerfiles. The one named Dockerfile should contain the production build, utilizing Multi-stage builds to create lean production images.
Dockerfile-dev is used to build an image with debugging capabilities and volume mounting so we don't need to rebuild the image each time the code changes locally.
Tip: Since VSCode only recognizes and adds code highlighting to files name Dockerfile, it is possible to add this code snippet to your user settings:
"files.associations": { "Dockerfile-dev": "dockerfile" }
We are using docker-compose to start all services at once. To make docker start your new service, add a new entry to the docker-compose.yml file. The existing file should have enough comments to get you started. It is important to note that the name you are giving your service here is the hostname other containers can reach your service on.
This means that a GET-request to http://service1/ will reach the container registered as service1 in docker-compose.yml.
If you need to expose a port out of the container, you can use the ports-list to map an internal port in the container to a port on the host. Then the container will be reachable on http://localhost:.
ports:
- "5000:80"
will make port 80 inside the container reachable on http://localhost:5000/.
All development-specific settings are set in docker-compose.override.yml, for example exposing the node debug port (9229) or specifying which dockerfile to use.
The gateway must be made aware of the new service. Add an entry to gateway/routes/ocelot.routes.json.
UpstreamPathTemplate should be the prefix you want the service to respond to in the gateway, and DownstreamPathTemplate is what url is called on the service.
Host should be the name chosen in docker-compose.yml, as the gateway container will be able to reach your service on this hostname.
Priority must be defined and be 1 or above. This is due to how the catch all route used to redirect all unmatched requests to our monolith is defined.
NOTE: Another thing to beware here is that the first defined route must be the catch all route. Always add new routes below the first in the json.