refactor: use replicas instead of node forks

This commit is contained in:
tdurieux
2024-04-01 06:43:51 +01:00
parent d3924698f6
commit d2aa5d6361
2 changed files with 18 additions and 14 deletions
+16 -3
View File
@@ -1,10 +1,14 @@
version: "3" version: "3.8"
services: services:
anonymous_github: anonymous_github:
build: . build: .
restart: always restart: always
image: tdurieux/anonymous_github:v2 image: tdurieux/anonymous_github:v2
deploy:
mode: replicated
replicas: 4
endpoint_mode: vip
env_file: env_file:
- ./.env - ./.env
volumes: volumes:
@@ -12,8 +16,6 @@ services:
environment: environment:
- REDIS_HOSTNAME=redis - REDIS_HOSTNAME=redis
- DB_HOSTNAME=mongodb - DB_HOSTNAME=mongodb
ports:
- $PORT:$PORT
healthcheck: healthcheck:
test: test:
- CMD - CMD
@@ -27,6 +29,17 @@ services:
- redis - redis
- opentelemetry - opentelemetry
nginx:
image: nginx:stable-alpine
env_file:
- ./.env
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- anonymous_github
ports:
- "$EXPOSED_PORT:4000"
redis: redis:
image: "redis:alpine" image: "redis:alpine"
restart: always restart: always
+2 -11
View File
@@ -1,16 +1,7 @@
const cluster = require('node:cluster');
import { config } from "dotenv"; import { config } from "dotenv";
config(); config();
import server from "./src/server"; import server from "./src/server";
if (cluster.isPrimary) { // start the server
console.log(`Master process ${process.pid} is running`); server();
for (let i = 0; i < 8; i++) {
cluster.fork();
}
} else {
// start the server
server();
}