-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Redis and NGINX proxy/load balancer for backend services
- Loading branch information
1 parent
88e8390
commit 8a1f479
Showing
17 changed files
with
483 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Spins up mock production environment | ||
version: '3' | ||
services: | ||
# Reverse proxy/load balancer | ||
nginx: | ||
build: ./nginx | ||
depends_on: | ||
- rtcServer | ||
- sessionServer | ||
ports: | ||
- '5000:80' | ||
|
||
# mediasoup voice server | ||
rtcServer: | ||
build: | ||
context: ./rtc-server | ||
dockerfile: Dockerfile | ||
image: insync-rtc-service | ||
volumes: | ||
- /rtc-server/node_modules | ||
expose: | ||
- '4000' | ||
|
||
# socketio session server | ||
sessionServer: | ||
build: | ||
context: ./server | ||
dockerfile: Dockerfile | ||
image: insync-session-service | ||
volumes: | ||
- /server/node_modules | ||
expose: | ||
- '5000' | ||
depends_on: | ||
- redisSocketIoAdapter | ||
- redisRoomState | ||
- redisClientRoomId | ||
- redisWaitingRoomId | ||
|
||
# spin up 4 redis containers, 1 for socket.io adapter, 3 for holding room state | ||
redisSocketIoAdapter: | ||
image: redis:alpine | ||
expose: | ||
- '6379' | ||
redisRoomState: | ||
image: redis:alpine | ||
command: --port 6380 | ||
expose: | ||
- '6380' | ||
redisClientRoomId: | ||
image: redis:alpine | ||
command: --port 6381 | ||
expose: | ||
- '6381' | ||
redisWaitingRoomId: | ||
image: redis:alpine | ||
command: --port 6382 | ||
expose: | ||
- '6382' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM nginx:alpine | ||
COPY nginx.conf /etc/nginx/nginx.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
worker_processes 4; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
server { | ||
listen 80; | ||
|
||
location /rtcService/ { | ||
# enable WebSockets | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_http_version 1.1; | ||
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $host; | ||
proxy_pass http://rtc_server; | ||
} | ||
|
||
location /sessionService/ { | ||
# enable WebSockets | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_http_version 1.1; | ||
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $host; | ||
proxy_pass http://socket_nodes; | ||
} | ||
} | ||
|
||
upstream rtc_server { | ||
ip_hash; | ||
server rtcServer:4000; | ||
} | ||
|
||
upstream socket_nodes { | ||
ip_hash; | ||
server sessionServer:5000; | ||
# TODO: add more physical nodes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Base alpine image to install npm packages and compile ts -> js | ||
FROM node:14-alpine AS build | ||
COPY . . | ||
RUN apk update \ | ||
&& apk add --no-cache --virtual .gyp \ | ||
python \ | ||
make \ | ||
g++ \ | ||
linux-headers \ | ||
&& npm install \ | ||
&& npm install mediasoup \ | ||
&& npm run build \ | ||
&& apk del .gyp | ||
|
||
# Main application image | ||
FROM node:14-alpine | ||
WORKDIR /server | ||
COPY --from=build ./node_modules ./node_modules | ||
COPY --from=build ./build ./build | ||
RUN npm install pm2 -g | ||
ENV NODE_ENV=production | ||
EXPOSE 4000 | ||
CMD ["pm2-runtime", "./build/server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM node:14-alpine | ||
WORKDIR /server | ||
COPY . . | ||
RUN npm install \ | ||
&& npm install -g pm2 \ | ||
&& npm run build | ||
ENV NODE_ENV=production | ||
EXPOSE 5000 | ||
CMD ["pm2-runtime", "./build/server.js"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Spins up all redis containers for development purposes | ||
version: '3' | ||
services: | ||
redisSocketIoAdapter: | ||
image: redis:alpine | ||
ports: | ||
- '6379:6379' | ||
redisRoomState: | ||
image: redis:alpine | ||
command: --port 6380 | ||
ports: | ||
- '6380:6380' | ||
redisClientRoomId: | ||
image: redis:alpine | ||
command: --port 6381 | ||
ports: | ||
- '6381:6381' | ||
redisWaitingRoomId: | ||
image: redis:alpine | ||
command: --port 6382 | ||
ports: | ||
- '6382:6382' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.