From 04387722722adc25be64665232ee3ba323e91e61 Mon Sep 17 00:00:00 2001 From: arkadiy Date: Fri, 8 Jul 2022 11:44:03 +0400 Subject: [PATCH 1/7] Add CD pipeline to docker hub --- .github/workflows/commit.yml | 19 +++++++++++++++---- apps/anime-service/.dockerignore | 1 + apps/anime-service/docker-compose.yml | 7 ++++++- apps/anime-service/dockerfile | 1 + apps/auth-service/.dockerignore | 1 + apps/auth-service/docker-compose.yml | 13 ++++++++++++- apps/auth-service/dockerfile | 1 + 7 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 apps/anime-service/.dockerignore create mode 100644 apps/anime-service/dockerfile create mode 100644 apps/auth-service/.dockerignore create mode 100644 apps/auth-service/dockerfile diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 86bff1b..8da3d4d 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -25,9 +25,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Checkout cache - uses: actions/cache@v3.0.2 - - name: Start installation process run: npm i @@ -44,4 +41,18 @@ jobs: run: npm run test - name: Check E2E tests - run: npm run test:e2e \ No newline at end of file + run: npm run test:e2e + + - name: Login to Docker Hub + uses: docker/login-action@1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./dockerfile + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/simplewhale:latest \ No newline at end of file diff --git a/apps/anime-service/.dockerignore b/apps/anime-service/.dockerignore new file mode 100644 index 0000000..191381e --- /dev/null +++ b/apps/anime-service/.dockerignore @@ -0,0 +1 @@ +.git \ No newline at end of file diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index f09d488..c74e5e0 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -7,4 +7,9 @@ services: - "5433:5432" environment: POSTGRES_USER: postgres - POSTGRES_PASSWORD: pass123 \ No newline at end of file + POSTGRES_PASSWORD: pass123 + volumes: + - pg_data:/var/lib/postgresql/data + +volumes: + pg_data: \ No newline at end of file diff --git a/apps/anime-service/dockerfile b/apps/anime-service/dockerfile new file mode 100644 index 0000000..6b3722e --- /dev/null +++ b/apps/anime-service/dockerfile @@ -0,0 +1 @@ +FROM node:16.14.0 \ No newline at end of file diff --git a/apps/auth-service/.dockerignore b/apps/auth-service/.dockerignore new file mode 100644 index 0000000..191381e --- /dev/null +++ b/apps/auth-service/.dockerignore @@ -0,0 +1 @@ +.git \ No newline at end of file diff --git a/apps/auth-service/docker-compose.yml b/apps/auth-service/docker-compose.yml index 7af0382..cb801a0 100644 --- a/apps/auth-service/docker-compose.yml +++ b/apps/auth-service/docker-compose.yml @@ -7,4 +7,15 @@ services: POSTGRES_USER: prisma POSTGRES_PASSWORD: pass123 ports: - - '5432:5432' \ No newline at end of file + - '5432:5432' + volumes: + - pg_data:/var/lib/postgresql/data + networks: + - auth-network + +volumes: + pg_data: + +networks: + auth-nework: + driver: bridge \ No newline at end of file diff --git a/apps/auth-service/dockerfile b/apps/auth-service/dockerfile new file mode 100644 index 0000000..6b3722e --- /dev/null +++ b/apps/auth-service/dockerfile @@ -0,0 +1 @@ +FROM node:16.14.0 \ No newline at end of file From 14070f20a4d76c8ebbdaa7abde0cf9d7dab96132 Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 14:53:06 +0400 Subject: [PATCH 2/7] Add kafka container --- .github/workflows/commit.yml | 16 +--------------- apps/anime-service/docker-compose.yml | 8 +++++++- apps/anime-service/dockerfile | 12 +++++++++++- apps/api-gateway/docker-compose.yaml | 25 +++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 apps/api-gateway/docker-compose.yaml diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 8da3d4d..ff9c7f5 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -41,18 +41,4 @@ jobs: run: npm run test - name: Check E2E tests - run: npm run test:e2e - - - name: Login to Docker Hub - uses: docker/login-action@1 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./dockerfile - push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/simplewhale:latest \ No newline at end of file + run: npm run test:e2e \ No newline at end of file diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index c74e5e0..5a957fb 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -10,6 +10,12 @@ services: POSTGRES_PASSWORD: pass123 volumes: - pg_data:/var/lib/postgresql/data + networks: + - anime-network volumes: - pg_data: \ No newline at end of file + pg_data: + +networks: + anime-network: + driver: bridge \ No newline at end of file diff --git a/apps/anime-service/dockerfile b/apps/anime-service/dockerfile index 6b3722e..c5bf44c 100644 --- a/apps/anime-service/dockerfile +++ b/apps/anime-service/dockerfile @@ -1 +1,11 @@ -FROM node:16.14.0 \ No newline at end of file +FROM node:16.14.0 + +WORKDIR /app + +COPY package*.json . + +RUN npm install --production + +COPY anime-service /app + +CMD ["npm", "run", "anime-service"] \ No newline at end of file diff --git a/apps/api-gateway/docker-compose.yaml b/apps/api-gateway/docker-compose.yaml new file mode 100644 index 0000000..ae8b227 --- /dev/null +++ b/apps/api-gateway/docker-compose.yaml @@ -0,0 +1,25 @@ +version: "3.9" + +services: + zookeeper: + image: confluentinc/cp-zookeeper:7.0.1 + container_name: zookeeper-container + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + + kafka: + image: confluentinc/cp-kafka:7.0.1 + container_name: kafka-container + ports: + - "9092:9092" + depends_on: + - zookeeper + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 + KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 From becf3d12849d9901b2fe9f8e7e9a2ea47703d0bd Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 14:55:28 +0400 Subject: [PATCH 3/7] Revert "Add kafka container" This reverts commit 14070f20a4d76c8ebbdaa7abde0cf9d7dab96132. --- .github/workflows/commit.yml | 16 +++++++++++++++- apps/anime-service/docker-compose.yml | 8 +------- apps/anime-service/dockerfile | 12 +----------- apps/api-gateway/docker-compose.yaml | 25 ------------------------- 4 files changed, 17 insertions(+), 44 deletions(-) delete mode 100644 apps/api-gateway/docker-compose.yaml diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index ff9c7f5..8da3d4d 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -41,4 +41,18 @@ jobs: run: npm run test - name: Check E2E tests - run: npm run test:e2e \ No newline at end of file + run: npm run test:e2e + + - name: Login to Docker Hub + uses: docker/login-action@1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./dockerfile + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/simplewhale:latest \ No newline at end of file diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index 5a957fb..c74e5e0 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -10,12 +10,6 @@ services: POSTGRES_PASSWORD: pass123 volumes: - pg_data:/var/lib/postgresql/data - networks: - - anime-network volumes: - pg_data: - -networks: - anime-network: - driver: bridge \ No newline at end of file + pg_data: \ No newline at end of file diff --git a/apps/anime-service/dockerfile b/apps/anime-service/dockerfile index c5bf44c..6b3722e 100644 --- a/apps/anime-service/dockerfile +++ b/apps/anime-service/dockerfile @@ -1,11 +1 @@ -FROM node:16.14.0 - -WORKDIR /app - -COPY package*.json . - -RUN npm install --production - -COPY anime-service /app - -CMD ["npm", "run", "anime-service"] \ No newline at end of file +FROM node:16.14.0 \ No newline at end of file diff --git a/apps/api-gateway/docker-compose.yaml b/apps/api-gateway/docker-compose.yaml deleted file mode 100644 index ae8b227..0000000 --- a/apps/api-gateway/docker-compose.yaml +++ /dev/null @@ -1,25 +0,0 @@ -version: "3.9" - -services: - zookeeper: - image: confluentinc/cp-zookeeper:7.0.1 - container_name: zookeeper-container - environment: - ZOOKEEPER_CLIENT_PORT: 2181 - ZOOKEEPER_TICK_TIME: 2000 - - kafka: - image: confluentinc/cp-kafka:7.0.1 - container_name: kafka-container - ports: - - "9092:9092" - depends_on: - - zookeeper - environment: - KAFKA_BROKER_ID: 1 - KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092 - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 - KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 From dc2fac2d622124aaec11f10e2fe6e4e81c015308 Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 16:51:49 +0400 Subject: [PATCH 4/7] Add Nginx load balancer --- .github/workflows/commit.yml | 16 +--------------- apps/anime-service/docker-compose.yml | 9 ++++++++- apps/anime-service/nginx/dockerfile | 3 +++ apps/anime-service/nginx/nginx.conf | 26 ++++++++++++++++++++++++++ apps/auth-service/docker-compose.yml | 1 + apps/auth-service/nginx/dockerfile | 3 +++ apps/auth-service/nginx/nginx.conf | 23 +++++++++++++++++++++++ 7 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 apps/anime-service/nginx/dockerfile create mode 100644 apps/anime-service/nginx/nginx.conf create mode 100644 apps/auth-service/nginx/dockerfile create mode 100644 apps/auth-service/nginx/nginx.conf diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 8da3d4d..ff9c7f5 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -41,18 +41,4 @@ jobs: run: npm run test - name: Check E2E tests - run: npm run test:e2e - - - name: Login to Docker Hub - uses: docker/login-action@1 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./dockerfile - push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/simplewhale:latest \ No newline at end of file + run: npm run test:e2e \ No newline at end of file diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index c74e5e0..58db705 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -1,4 +1,5 @@ version: "3" + services: db: image: postgres @@ -10,6 +11,12 @@ services: POSTGRES_PASSWORD: pass123 volumes: - pg_data:/var/lib/postgresql/data + networks: + - anime-network volumes: - pg_data: \ No newline at end of file + pg_data: + +networks: + anime-network: + driver: bridge \ No newline at end of file diff --git a/apps/anime-service/nginx/dockerfile b/apps/anime-service/nginx/dockerfile new file mode 100644 index 0000000..dc755b0 --- /dev/null +++ b/apps/anime-service/nginx/dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.23.0 + +COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/anime-service/nginx/nginx.conf b/apps/anime-service/nginx/nginx.conf new file mode 100644 index 0000000..f3f01bb --- /dev/null +++ b/apps/anime-service/nginx/nginx.conf @@ -0,0 +1,26 @@ +worker_processes auto; + +events { + worker_connections 512; +} + +http { + # LoadBalancing name space + upstream animeservice { + least_conn; + server service_container_1:5000; + server service_container_2:5000; + server service_container_3:5000; + } + + server { + listen 80; + + location / { + access_log off; + + # Future Node container name + proxy_pass http://animeservice; + } + } +} \ No newline at end of file diff --git a/apps/auth-service/docker-compose.yml b/apps/auth-service/docker-compose.yml index cb801a0..0adf618 100644 --- a/apps/auth-service/docker-compose.yml +++ b/apps/auth-service/docker-compose.yml @@ -1,4 +1,5 @@ version: '3.8' + services: postgres: image: postgres:10.3 diff --git a/apps/auth-service/nginx/dockerfile b/apps/auth-service/nginx/dockerfile new file mode 100644 index 0000000..dc755b0 --- /dev/null +++ b/apps/auth-service/nginx/dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.23.0 + +COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/auth-service/nginx/nginx.conf b/apps/auth-service/nginx/nginx.conf new file mode 100644 index 0000000..eabcb0a --- /dev/null +++ b/apps/auth-service/nginx/nginx.conf @@ -0,0 +1,23 @@ +worker_processes auto; + +events { + worker_connections 512; +}; + +http { + # LoadBalancing name space + upstream authservice { + least_conn; + server auth_container_1:5500; + server auth_container_2:5500; + server auth_container_3:5500; + } + + server { + listen 80; + + location / { + proxy_pass http://authservice; + } + } +} \ No newline at end of file From b2c8233204fae5ade07cda8bba0b2d7a42984d3d Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 16:53:09 +0400 Subject: [PATCH 5/7] Revert "Add Nginx load balancer" This reverts commit dc2fac2d622124aaec11f10e2fe6e4e81c015308. --- .github/workflows/commit.yml | 16 +++++++++++++++- apps/anime-service/docker-compose.yml | 9 +-------- apps/anime-service/nginx/dockerfile | 3 --- apps/anime-service/nginx/nginx.conf | 26 -------------------------- apps/auth-service/docker-compose.yml | 1 - apps/auth-service/nginx/dockerfile | 3 --- apps/auth-service/nginx/nginx.conf | 23 ----------------------- 7 files changed, 16 insertions(+), 65 deletions(-) delete mode 100644 apps/anime-service/nginx/dockerfile delete mode 100644 apps/anime-service/nginx/nginx.conf delete mode 100644 apps/auth-service/nginx/dockerfile delete mode 100644 apps/auth-service/nginx/nginx.conf diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index ff9c7f5..8da3d4d 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -41,4 +41,18 @@ jobs: run: npm run test - name: Check E2E tests - run: npm run test:e2e \ No newline at end of file + run: npm run test:e2e + + - name: Login to Docker Hub + uses: docker/login-action@1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./dockerfile + push: true + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/simplewhale:latest \ No newline at end of file diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index 58db705..c74e5e0 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -1,5 +1,4 @@ version: "3" - services: db: image: postgres @@ -11,12 +10,6 @@ services: POSTGRES_PASSWORD: pass123 volumes: - pg_data:/var/lib/postgresql/data - networks: - - anime-network volumes: - pg_data: - -networks: - anime-network: - driver: bridge \ No newline at end of file + pg_data: \ No newline at end of file diff --git a/apps/anime-service/nginx/dockerfile b/apps/anime-service/nginx/dockerfile deleted file mode 100644 index dc755b0..0000000 --- a/apps/anime-service/nginx/dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM nginx:1.23.0 - -COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/anime-service/nginx/nginx.conf b/apps/anime-service/nginx/nginx.conf deleted file mode 100644 index f3f01bb..0000000 --- a/apps/anime-service/nginx/nginx.conf +++ /dev/null @@ -1,26 +0,0 @@ -worker_processes auto; - -events { - worker_connections 512; -} - -http { - # LoadBalancing name space - upstream animeservice { - least_conn; - server service_container_1:5000; - server service_container_2:5000; - server service_container_3:5000; - } - - server { - listen 80; - - location / { - access_log off; - - # Future Node container name - proxy_pass http://animeservice; - } - } -} \ No newline at end of file diff --git a/apps/auth-service/docker-compose.yml b/apps/auth-service/docker-compose.yml index 0adf618..cb801a0 100644 --- a/apps/auth-service/docker-compose.yml +++ b/apps/auth-service/docker-compose.yml @@ -1,5 +1,4 @@ version: '3.8' - services: postgres: image: postgres:10.3 diff --git a/apps/auth-service/nginx/dockerfile b/apps/auth-service/nginx/dockerfile deleted file mode 100644 index dc755b0..0000000 --- a/apps/auth-service/nginx/dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM nginx:1.23.0 - -COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/auth-service/nginx/nginx.conf b/apps/auth-service/nginx/nginx.conf deleted file mode 100644 index eabcb0a..0000000 --- a/apps/auth-service/nginx/nginx.conf +++ /dev/null @@ -1,23 +0,0 @@ -worker_processes auto; - -events { - worker_connections 512; -}; - -http { - # LoadBalancing name space - upstream authservice { - least_conn; - server auth_container_1:5500; - server auth_container_2:5500; - server auth_container_3:5500; - } - - server { - listen 80; - - location / { - proxy_pass http://authservice; - } - } -} \ No newline at end of file From cce9d47f49406608964311d9e44e6a4ba222575a Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 16:58:44 +0400 Subject: [PATCH 6/7] Add Nginx load balancer --- apps/anime-service/docker-compose.yml | 9 ++++++++- apps/anime-service/nginx/dockerfile | 3 +++ apps/anime-service/nginx/nginx.conf | 21 +++++++++++++++++++++ apps/auth-service/nginx/dockerfile | 3 +++ apps/auth-service/nginx/nginx.conf | 21 +++++++++++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 apps/anime-service/nginx/dockerfile create mode 100644 apps/anime-service/nginx/nginx.conf create mode 100644 apps/auth-service/nginx/dockerfile create mode 100644 apps/auth-service/nginx/nginx.conf diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index c74e5e0..58db705 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -1,4 +1,5 @@ version: "3" + services: db: image: postgres @@ -10,6 +11,12 @@ services: POSTGRES_PASSWORD: pass123 volumes: - pg_data:/var/lib/postgresql/data + networks: + - anime-network volumes: - pg_data: \ No newline at end of file + pg_data: + +networks: + anime-network: + driver: bridge \ No newline at end of file diff --git a/apps/anime-service/nginx/dockerfile b/apps/anime-service/nginx/dockerfile new file mode 100644 index 0000000..dc755b0 --- /dev/null +++ b/apps/anime-service/nginx/dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.23.0 + +COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/anime-service/nginx/nginx.conf b/apps/anime-service/nginx/nginx.conf new file mode 100644 index 0000000..7a02e05 --- /dev/null +++ b/apps/anime-service/nginx/nginx.conf @@ -0,0 +1,21 @@ +events { + worker_connections 512; +} + +http { + upstream anime_service { + server anime_service_1:5000; + server anime_service_2:5000; + server anime_service_3:5000; + } + + server { + listen 80; + + location / { + access_log off; + + proxy_pass http://anime_service; + } + } +} \ No newline at end of file diff --git a/apps/auth-service/nginx/dockerfile b/apps/auth-service/nginx/dockerfile new file mode 100644 index 0000000..dc755b0 --- /dev/null +++ b/apps/auth-service/nginx/dockerfile @@ -0,0 +1,3 @@ +FROM nginx:1.23.0 + +COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/apps/auth-service/nginx/nginx.conf b/apps/auth-service/nginx/nginx.conf new file mode 100644 index 0000000..146cba8 --- /dev/null +++ b/apps/auth-service/nginx/nginx.conf @@ -0,0 +1,21 @@ +events { + worker_connections 512; +} + +http { + upstream auth_service { + server auth_service_1:5500; + server auth_service_2:5500; + server auth_service_3:5500; + } + + server { + listen 80; + + location / { + access_log off; + + proxy_pass http://auth_service; + } + } +} \ No newline at end of file From 75aa2fef5b1f994937860348afbf8557bfe2f2fe Mon Sep 17 00:00:00 2001 From: arkadiy Date: Sun, 10 Jul 2022 23:15:31 +0400 Subject: [PATCH 7/7] Add Nginx load-balancer for 2 microservices --- apps/anime-service/docker-compose.yml | 13 +++++++++++++ apps/anime-service/nginx/dockerfile | 4 +++- apps/anime-service/nginx/nginx.conf | 12 +++++++----- apps/auth-service/docker-compose.yml | 14 ++++++++++++++ apps/auth-service/nginx/dockerfile | 4 +++- apps/auth-service/nginx/nginx.conf | 6 ++++++ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/apps/anime-service/docker-compose.yml b/apps/anime-service/docker-compose.yml index 58db705..afd93bc 100644 --- a/apps/anime-service/docker-compose.yml +++ b/apps/anime-service/docker-compose.yml @@ -1,6 +1,19 @@ version: "3" services: + anime_balancer: + image: anime-balancer + container_name: anime-service-balancer + build: + context: ./nginx + dockerfile: dockerfile + environment: + - NGINX_PORT=80 + ports: + - 80:80 + networks: + - anime-network + db: image: postgres restart: always diff --git a/apps/anime-service/nginx/dockerfile b/apps/anime-service/nginx/dockerfile index dc755b0..019a3d0 100644 --- a/apps/anime-service/nginx/dockerfile +++ b/apps/anime-service/nginx/dockerfile @@ -1,3 +1,5 @@ FROM nginx:1.23.0 -COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file +RUN mkdir /etc/nginx/anime-service + +COPY ./nginx.conf /etc/nginx/anime-service/ \ No newline at end of file diff --git a/apps/anime-service/nginx/nginx.conf b/apps/anime-service/nginx/nginx.conf index 7a02e05..bde0305 100644 --- a/apps/anime-service/nginx/nginx.conf +++ b/apps/anime-service/nginx/nginx.conf @@ -1,3 +1,5 @@ +worker_processes 1; + events { worker_connections 512; } @@ -10,12 +12,12 @@ http { } server { - listen 80; + listen 80; - location / { - access_log off; + location / { + access_log off; - proxy_pass http://anime_service; - } + proxy_pass http://anime_service; + } } } \ No newline at end of file diff --git a/apps/auth-service/docker-compose.yml b/apps/auth-service/docker-compose.yml index cb801a0..b78e8f9 100644 --- a/apps/auth-service/docker-compose.yml +++ b/apps/auth-service/docker-compose.yml @@ -1,5 +1,19 @@ version: '3.8' + services: + auth_balancer: + image: auth-balancer + container_name: auth-service-balancer + build: + context: ./nginx + dockerfile: dockerfile + environment: + - NGINX_PORT=80 + ports: + - 80:80 + networks: + - auth-network + postgres: image: postgres:10.3 restart: always diff --git a/apps/auth-service/nginx/dockerfile b/apps/auth-service/nginx/dockerfile index dc755b0..d5aff19 100644 --- a/apps/auth-service/nginx/dockerfile +++ b/apps/auth-service/nginx/dockerfile @@ -1,3 +1,5 @@ FROM nginx:1.23.0 -COPY ./nginx.conf /etc/nginx/nginx.conf \ No newline at end of file +RUN mkdir /etc/nginx/auth-service + +COPY ./nginx.conf /etc/nginx/auth-service/ \ No newline at end of file diff --git a/apps/auth-service/nginx/nginx.conf b/apps/auth-service/nginx/nginx.conf index 146cba8..4417fe9 100644 --- a/apps/auth-service/nginx/nginx.conf +++ b/apps/auth-service/nginx/nginx.conf @@ -1,3 +1,5 @@ +worker_processes 1; + events { worker_connections 512; } @@ -16,6 +18,10 @@ http { access_log off; proxy_pass http://auth_service; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; } } } \ No newline at end of file