localenv/README.md
2023-08-05 22:10:48 +02:00

85 lines
5.1 KiB
Markdown

# localenv
This project aims to deploy a microservices environment on local. It will connect and deploy all the microservices and their dependencies (postgres, rabbitmq, etc...).
## Requirements
* Linux (feel sorry for macos users 😭)
* dockerd >= 20.10.23
* [sysbox](https://github.com/nestybox/sysbox/blob/master/docs/user-guide/install-package.md)
* go >= 1.20
* dockerd ubuntu image
```bash
make docker-swarm
```
* nginx with embedded microservice conf
```bash
make docker-nginx
```
## Run
* Create a `.env` and feed values for your needs
```bash
cp .env.example .env
```
* Launch/install the local environment
```bash
make start
```
* Stop it
```bash
make stop
```
* Purge (remove the environment and all the data)
> Be careful ! All the local data will be removed !
```bash
make purge
```
* Enable watcher
> The watcher is used to auto deploy a microservice on the Swarm when the microservice is built.
```bash
make start-watch
```
## How it works ?
`localenv` uses a container with **Docker Swarm** to deploy microservices as Docker services. It is completely isolated and does not pollute your docker environment.
```ascii
local dockerd
┌─────────────────────────────────────────────────────────────────────┐
│ docker swarm (DinD) │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌────────────┐ ┌───────────────────────────────┐ │ │
│ │ │rabbitmq │ │ │ │ │
│ │ │ │ │ ┌─────────┐ ┌─────────┐ │ │ │
│ │ │ ├────────┼─┤ms │ │postgres │ │ │ │
│ │ │ │ │ │ ├──────┤ │ │ │ │
│ │ └──┬─────────┘ │ │ │ │ │ │ │ │
│ │ │:15672 │ │ │ │ │ │ │ │
│ │ │ │ └─┬───────┘ └────┬────┘ │ │ │
│ │ │ │ │ │ │ │ │
│ │ │ ┌──────────┐ │ │ ┌───────────────┴─────┐ │ │ │
│ │ │ │nginx │ │ │ │persistent storage │ │ │ │
│ │ │ │ ├───┼───┘ └─────────────────────┘ │ │ │
│ │ │ │ │ │ │ │ │
│ │ │ └──┬───────┘ │ db-network│ │ │
│ │ │ │:4443 └───────────────────────────────┘ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │:4523 ms-network│ │
│ └────┼──────┼───────────────────────────────┼───────────────────┘ │
│ │ │ │ │
└───────┼──────┼───────────────────────────────┼──────────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
```
The scheme above explains how the `localenv `is deployed.
* A container, running with the **sysbox** runtime, as a Docker Swarm.
* The Swarm **dockerd** is available from the outside to interact easily with it.
* `ms` is connected to the `ms-network` to communicate with the others microservices (DNS resolution).
* A Postgres DB can be connected to a microservice and be isolated in a network. For simplicity, if a microservice needs a database, a new database is deployed.
* **RabbitMQ** is common between all microservices. The management UI is available and accessible at http://localhost:15672.
* **nginx** as a reverse proxy. To access `authorizations` for example: https://localhost:4443/authorizations/health.