From c44f98fac4e5321d52a47e4b81d457ee64a2e03b Mon Sep 17 00:00:00 2001 From: ebosas Date: Tue, 1 Jun 2021 21:38:22 +0300 Subject: [PATCH] updates to readme, dockerfiles --- README.md | 44 +++++++++++++++++++++- Dockerfile.backend => backend.Dockerfile | 0 Dockerfile.database => database.Dockerfile | 0 docker-compose.yml | 22 ++++------- Dockerfile.server => server.Dockerfile | 0 5 files changed, 50 insertions(+), 16 deletions(-) rename Dockerfile.backend => backend.Dockerfile (100%) rename Dockerfile.database => database.Dockerfile (100%) rename Dockerfile.server => server.Dockerfile (100%) diff --git a/README.md b/README.md index 29a1cb7..2f1a418 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ -# Microservices with Go and RabbitMQ -As well as Docker, PostgreSQL, WebSocket and React. \ No newline at end of file +# Microservices + +A basic example of microservice architecture which demonstrates communication between a few loosely coupled services. This includes messages between a server terminal and a web user interface with a database service in the middle. + +Written in Go, this mainly showcases the exchange of information using RabbitMQ—between backend services—and WebSocket—between frontend and backend. + +The services are built using Docker which includes a multistage build example. The whole application is served with Docker Compose. + +## Running the code + +To run the example, clone the Github repository and start the services with Docker Compose. Once Docker finishes downloading and building images, the front end is accessible by visiting `localhost:8080` in a browser. + +```bash +git clone https://github.com/ebosas/microservices +cd microservices +``` +```bash +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 from this service is sent to the front end to have communication both ways. + +```bash +docker attach microservices_backend +``` + +### 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). + +```bash +docker run -it --rm --network microservices_network postgres:13-alpine psql -h postgres -U postgres +``` + +Select everything from the messages table: + +```sql +\c microservices +select * from messages; +``` diff --git a/Dockerfile.backend b/backend.Dockerfile similarity index 100% rename from Dockerfile.backend rename to backend.Dockerfile diff --git a/Dockerfile.database b/database.Dockerfile similarity index 100% rename from Dockerfile.database rename to database.Dockerfile diff --git a/docker-compose.yml b/docker-compose.yml index 7273ba9..c3b8d95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3.9" services: rabbitmq: image: "rabbitmq:3-management-alpine" @@ -27,20 +26,10 @@ services: timeout: 10s retries: 5 - psql: - image: "postgres:13-alpine" - stdin_open: true - tty: true - command: ["psql", "-h", "postgres", "-U", "postgres"] - depends_on: - postgres: - condition: service_healthy - server: - # container_name: server build: context: . - dockerfile: Dockerfile.server + dockerfile: server.Dockerfile ports: - 8080:8080 env_file: @@ -51,9 +40,10 @@ services: condition: service_healthy backend: + container_name: microservices_backend build: context: . - dockerfile: Dockerfile.backend + dockerfile: backend.Dockerfile env_file: - .env stdin_open: true @@ -65,7 +55,7 @@ services: database: build: context: . - dockerfile: Dockerfile.database + dockerfile: database.Dockerfile env_file: - .env depends_on: @@ -73,3 +63,7 @@ services: condition: service_healthy postgres: condition: service_healthy + +networks: + default: + name: microservices_network diff --git a/Dockerfile.server b/server.Dockerfile similarity index 100% rename from Dockerfile.server rename to server.Dockerfile