Skip to content

Commit

Permalink
OpenVidu deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nyakaspeter committed Nov 9, 2021
1 parent 2ed14e2 commit fa8c426
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 9 deletions.
29 changes: 25 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# Environment variables for production (dockerized)

# The port where ChattR will listen
NGINX_PORT=80

# The port where the REST API will listen
SERVER_PORT=5000

# The port where the MongoDB instance will listen
MONGODB_PORT=27017

# The MongoDB collection name to use
MONGODB_COLLECTION_NAME=chattr

# The MongoDB collection where uploaded files will go
MONGODB_UPLOAD_BUCKET_NAME=uploads
MONGODB_UPLOAD_MAX_FILE_SIZE=52428800

SERVER_PORT=5000
# Maximum allowed size for file uploads, in bytes
UPLOAD_MAX_FILE_SIZE=52428800

# Session cookie secret, set it to a random string
SESSION_SECRET=sessionsecret

# OpenVidu deployment public IP or domain name and secret
# Documentation: https://docs.openvidu.io/en/2.20.0/deployment/
OPENVIDU_URL=https://openvidu.server
OPENVIDU_SECRET=openvidusecret

# Google OAuth 2.0 client id and secret, you'll need this for Google Sign-In
# Documentation: https://developers.google.com/identity/protocols/oauth2/openid-connect
# You'll also need to add ${DOMAIN_OR_PUBLIC_IP} to Authorized JavaScript origins in GCP
# control panel and ${DOMAIN_OR_PUBLIC_IP}/auth/google/callback to Authorized redirect URIs
GOOGLE_CLIENT_ID=clientid
GOOGLE_CLIENT_SECRET=clientsecret

NGINX_PORT=80
29 changes: 29 additions & 0 deletions .env.openvidu.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# ChattR configuration
# --------------------------
# First please check above and make sure SUPPORT_DEPRECATED_API is set to false

# The port where the REST API will listen
SERVER_PORT=5000

# The port where the MongoDB instance will listen
MONGODB_PORT=27017

# The MongoDB collection name to use
MONGODB_COLLECTION_NAME=chattr

# The MongoDB collection where uploaded files will go
MONGODB_UPLOAD_BUCKET_NAME=uploads

# Maximum allowed size for file uploads, in bytes
UPLOAD_MAX_FILE_SIZE=52428800

# Session cookie secret, set it to a random string
SESSION_SECRET=sessionsecret

# Google OAuth 2.0 client id and secret, you'll need this for Google Sign-In
# Documentation: https://developers.google.com/identity/protocols/oauth2/openid-connect
# You'll also need to add ${DOMAIN_OR_PUBLIC_IP} to Authorized JavaScript origins in GCP
# control panel and ${DOMAIN_OR_PUBLIC_IP}/auth/google/callback to Authorized redirect URIs
GOOGLE_CLIENT_ID=clientid
GOOGLE_CLIENT_SECRET=clientsecret
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
# ChattR

Experimental chat app powered by WebSockets & WebRTC

## What is ChattR?

ChattR is a real-time text & video chat application based on modern web technologies. The app consists of a [React](https://reactjs.org/) based frontend and a [Node.js](https://nodejs.org/) REST API, that communicates with a [MongoDB](https://www.mongodb.com/) database.

The video & voice in calls in ChattR are handled by the open source [OpenVidu](https://openvidu.io/index) video call application platform, which uses [Kurento](https://www.kurento.org/) WebRTC media server under the hood. The real-time messaging is made possible with WebSockets using [Socket.IO](https://socket.io/)

## Deployment

<details><summary>How to deploy for development</summary>

ChattR is a [Node.js](https://nodejs.org/) application at it's core, and uses [yarn](https://yarnpkg.com/) for package management, so install those respectively.

The ChattR backend needs a MongoDB instance for data storage. [Install MongoDB](https://www.mongodb.com/try/download) or set up a database in [MongoDB Atlas](https://www.mongodb.com/try).

If you want to be able to make video & voice calls using ChattR, you must [deploy OpenVidu platform](https://docs.openvidu.io/en/2.20.0/deployment/) on premise, or to the cloud. The OpenVidu Call application is not needed, you can disable that.

When you have MongoDB and OpenVidu ready, you can start up the development environment following these steps:

- Clone the ChattR repo
- `git clone https://github.com/nyakaspeter/ChattR.git`
- Install dependencies with yarn
- `yarn install`
- Set up the environmental variables for the server in a `.env` file inside the `server` directory, based on the `.env.example` file
- Once the variables are set up properly, you can start up ChattR in development mode
- `yarn dev` (from the repo root folder)
- If you use VSCode you can also use one of the pre-defined tasks to start the client, the server or both

</details>

<details><summary>How to deploy for production as standalone application</summary>

You can deploy ChattR as a standalone application with docker-compose. If you want to be able to make video & voice calls using ChattR, you must first [deploy OpenVidu platform](https://docs.openvidu.io/en/2.20.0/deployment/) on premise, or to the cloud. The OpenVidu Call application is not needed, you can disable that.

When you have OpenVidu ready, you can deploy ChattR following these steps:

- Install docker & docker-compose if they are not already installed
- Clone the ChattR repo
- `git clone https://github.com/nyakaspeter/ChattR.git`
- Set up the environmental variables by renaming the `.env.example` file to `.env` and setting the values. See the notes in the file for more information.
- Once the variables are set up properly, you can spin up ChattR with docker-compose
- `docker-compose up` (from the repo root folder)

</details>

<details><summary>How to deploy for production as OpenVidu based application</summary>

You can deploy ChattR alongside OpenVidu platform using the same port and SSL certificate. This way you don't have to configure the connection between the two applications and they share the same lifecycle.

More information about [deploying OpenVidu](https://docs.openvidu.io/en/2.20.0/deployment/ce/on-premises/) and [OpenVidu based applications](https://docs.openvidu.io/en/2.20.0/deployment/deploying-openvidu-apps/) can be found in the [OpenVidu docs](https://docs.openvidu.io/en/2.20.0/).

The steps of deployment are the following (you can issue these commands on basically any modern linux distribution):

- Enter root shell, you'll need it
- `sudo su`
- Install docker
- `curl -fsSL https://get.docker.com | bash`
- Install docker-compose
- `curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose`
- `chmod +x /usr/local/bin/docker-compose`
- Deploy OpenVidu platform
- `cd /opt`
- `curl https://s3-eu-west-1.amazonaws.com/aws.openvidu.io/install_openvidu_2.20.0.sh | bash`
- Clone the ChattR repo
- `git clone https://github.com/nyakaspeter/ChattR.git`
- Override OpenVidu's default configuration files
- `mv ./ChattR/docker-compose.openvidu.yml docker-compose.override.yml`
- `cat ./ChattR/.env.openvidu.example >> .env`
- Set up the environmental variables by editing the `.env` file, see the notes in the file for more information
- Make sure that `SUPPORT_DEPRECATED_API` is set to false! Otherwise OpenVidu will override the paths for the ChattR backend.
- Once the variables are set up properly, you can manage the lifecycle of ChattR along with the OpenVidu platform with the following commands
- Start: `./openvidu start`
- Stop: `./openvidu stop`
- Restart: `./openvidu restart`

</details>
41 changes: 41 additions & 0 deletions docker-compose.openvidu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3'

services:
mongo:
image: mongo
command: mongod --port ${MONGODB_PORT}
restart: always
network_mode: host
server:
depends_on:
- mongo
build:
context: ./ChattR
dockerfile: ./server/Dockerfile
image: chattr-server
restart: always
network_mode: host
environment:
NODE_ENV: production
PORT: ${SERVER_PORT}
SESSION_SECRET: ${SESSION_SECRET}
MONGODB_URL: mongodb://localhost:${MONGODB_PORT}/${MONGODB_COLLECTION_NAME}
MONGODB_UPLOAD_BUCKET_NAME: ${MONGODB_UPLOAD_BUCKET_NAME}
MONGODB_UPLOAD_MAX_FILE_SIZE: ${UPLOAD_MAX_FILE_SIZE}
OPENVIDU_URL: http://localhost:5443
OPENVIDU_SECRET: ${OPENVIDU_SECRET}
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
client:
depends_on:
- server
build:
context: ./ChattR
dockerfile: ./client/Dockerfile
image: chattr-client
restart: always
network_mode: host
environment:
PORT: 5442
SERVER_URL: http://localhost:${SERVER_PORT}
MAX_BODY_SIZE: ${UPLOAD_MAX_FILE_SIZE}
11 changes: 6 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ version: '3'
services:
mongo:
image: mongo
command: mongod --port ${MONGODB_PORT}
restart: always
ports:
- ${MONGODB_PORT}:27017
- ${MONGODB_PORT}:${MONGODB_PORT}
server:
depends_on:
- mongo
Expand All @@ -22,8 +23,8 @@ services:
SESSION_SECRET: ${SESSION_SECRET}
MONGODB_URL: mongodb://mongo:${MONGODB_PORT}/${MONGODB_COLLECTION_NAME}
MONGODB_UPLOAD_BUCKET_NAME: ${MONGODB_UPLOAD_BUCKET_NAME}
MONGODB_UPLOAD_MAX_FILE_SIZE: ${MONGODB_UPLOAD_MAX_FILE_SIZE}
OPENVIDU_URL: http://localhost:5443
MONGODB_UPLOAD_MAX_FILE_SIZE: ${UPLOAD_MAX_FILE_SIZE}
OPENVIDU_URL: ${OPENVIDU_URL}
OPENVIDU_SECRET: ${OPENVIDU_SECRET}
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
Expand All @@ -36,8 +37,8 @@ services:
image: chattr-client
restart: always
ports:
- 5442:${NGINX_PORT}
- ${NGINX_PORT}:${NGINX_PORT}
environment:
PORT: ${NGINX_PORT}
SERVER_URL: http://server:${SERVER_PORT}
MAX_BODY_SIZE: ${MONGODB_UPLOAD_MAX_FILE_SIZE}
MAX_BODY_SIZE: ${UPLOAD_MAX_FILE_SIZE}
1 change: 1 addition & 0 deletions server/config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ passport.use(
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: '/auth/google/callback',
proxy: true,
},
(accessToken, refreshToken, profile, done) => {
User.findOneAndUpdate(
Expand Down

0 comments on commit fa8c426

Please sign in to comment.