1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-08-24 20:08:55 +02:00

Add deployment and Redis sections

This commit is contained in:
ebosas
2021-11-01 17:10:20 +02:00
parent 5aa1003ff0
commit 9598bf8adc

View File

@@ -6,9 +6,12 @@ A basic example of microservice architecture which demonstrates communication be
* Uses RabbitMQ to communicate between services * Uses RabbitMQ to communicate between services
* Uses WebSocket to talk to the front end * Uses WebSocket to talk to the front end
* Stores data in PostgreSQL * Stores data in PostgreSQL
* Stores cache in Redis
* Uses React for front end development * Uses React for front end development
* Uses Redis for cache
* Builds and runs with Docker * Builds and runs with Docker
* Deployed on AWS with CloudFormation templates
* ECS using EC2
* AWS Fargate
![](demo.gif) ![](demo.gif)
@@ -24,14 +27,6 @@ cd microservices
docker-compose up docker-compose up
``` ```
### Back end
To access the back end service, attach to its docker container from a separate terminal window. Messages from the front end will show up here. Also, standart input will be sent to the front end for two way communication.
```bash
docker attach microservices_backend
```
### Database ### Database
To inspect the database, launch a new container that will connect to our Postgres database. Then enter the password `demopsw` (see the `.env` file). To inspect the database, launch a new container that will connect to our Postgres database. Then enter the password `demopsw` (see the `.env` file).
@@ -49,21 +44,80 @@ Select everything from the messages table:
select * from messages; select * from messages;
``` ```
### Redis
To inspect Redis, connect to its container via redis-cli.
```bash
docker run -it --rm \
--network microservices_network \
redis:6-alpine \
redis-cli -h redis
```
Get all cached messages or show the number of messages.
```bash
lrange messages 0 -1
get total
```
### RabbitMQ ### RabbitMQ
Access the RabbitMQ management interface by visiting `localhost:15672` with `guest` as both username and password. Access the RabbitMQ management interface by visiting `localhost:15672` with `guest` as both username and password.
### Redis ### Back end
To access the back end service, attach to its docker container from a separate terminal window. Messages from the front end will show up here. Also, standart input will be sent to the front end for two way communication.
```bash ```bash
docker run -it --rm --network microservices_network redis:6-alpine redis-cli -h redis docker attach microservices_backend
``` ```
## Deployment on Amazon ECS/AWS Fargate
### ECR
To deploy on ECS, the first step is to publish the service images to Amazon ECR. In Makefile, replace the `registry` variable with your own registry. [Login](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html#get-login-password) to ECR. Then run the following command:
```bash ```bash
lrange messages 0 -1 make ecr
get count
``` ```
### CloudFormation stacks
There are several CloudFormation stacks to create. `cd deployments` and create the network stack:
```bash
aws cloudformation create-stack --stack-name MicroservicesNetwork --template-body file://network.yml
```
Create the following stacks in any order (for an EC2 cluster). To create a Fargate cluster, change the `cluster-ec2.yml` to `cluster-fargate.yml`.
```bash
aws cloudformation create-stack --stack-name MicroservicesResources --template-body file://resources.yml
aws cloudformation create-stack --stack-name MicroservicesAlb --template-body file://alb.yml
aws cloudformation create-stack --stack-name MicroservicesClusterEC2 --template-body file://cluster-ec2.yml --capabilities CAPABILITY_NAMED_IAM
```
Once done, create the services (for an EC2 cluster). For Fargate, change the `services-ec2` directory to `services-fargate`.
```bash
aws cloudformation create-stack --stack-name MicroservicesServiceServer --template-body file://services-ec2/server.yml
aws cloudformation create-stack --stack-name MicroservicesServiceCache --template-body file://services-ec2/cache.yml
aws cloudformation create-stack --stack-name MicroservicesServiceDatabase --template-body file://services-ec2/database.yml
```
To visit the website, head to the MicroservicesAlb stack and open the `ExternalUrl` from the Outputs tab.
### Deleting stacks
When deleting the `cluster-ec2.yml` stack in CloudFormation, delete the auto scaling group manually from the AWS EC2 console.
### References
Deployment is based on these templates: https://github.com/nathanpeck/ecs-cloudformation
## Development environment ## Development environment
For development, run the RabbitMQ and Postgres containers with Docker Compose. For development, run the RabbitMQ and Postgres containers with Docker Compose.