A distributed chat system
Run the command below and wait for all the services to initialize.
$ docker compose up
Modify .env and .env.chat-server.base according to your needs. Remember to change these variables when deploying to production:
BACKEND_CORS_ORIGINSVITE_MASTERJWT_PRIVATE_KEYJWT_PUBLIC_KEY
Also consider modifying these variables for security reasons (especially if RabbitMQ or PostgreSQL are going to be available externally):
RABBITMQ_DEFAULT_USERRABBITMQ_DEFAULT_PASSPOSTGRES_USERPOSTGRES_PASSWORD
Remember to update BROKER_URL in .env.chat-server.base when RABBITMQ_DEFAULT_USER or RABBITMQ_DEFAULT_PASS changes.
See Environmental variables section for more details.
Use the command below to generate a Swarm configuration from the template:
$ docker-compose -f swarm-template.yml config > swarm.yml
Then depending on the docker compose version, you might need to edit swarm.yml and for example:
- insert
version: "3.8"line, - remove
name: ...line, - remove quote characters from the numeric values of
published:nodes, - delete the
networks.defaultandservices.front-end.networksnodes.
If the generated swarm.yml file is invalid, docker stack deploy will fail.
On the manager node:
$ docker swarm init
$ docker network create -d overlay --attachable meepo-chat-network
$ docker stack deploy -c swarm.yml meepo-chat
On the worker nodes apply the join command printed from previously issued docker swarm init:
$ docker join ...
Choose a Swarm node to serve the main database:
$ docker node ls
$ docker node update --label-add maindb=true <id-of-selected-node>
Deploy a chat server on any Swarm node:
-
Make your own copy of
.env.chat-server.exampleand name it e.g..env.chat-server.my-server-1 -
Adjust the advertising and server name settings in the copied environmental variables file.
-
Deploy the chat server:
$ docker compose -f compose-chat-server.yml --env-file .env.chat-server.my-server-1 -p chat-server-my-server-1 up -d
BACKEND_CORS_ORIGINS– a list of allowed cross origin domains.SERVER_NAME– a chat server name.MAX_CLIENTS– a maximum number of users in the chat room.ADVERTISED_ADDRESS– a published (external) chat server address (IP or domain).ADVERTISED_PORT– a published (external) chat server port.VITE_MASTER– a master server address (reachable by users).JWT_PUBLIC_KEY- an RSA public key used to verify JWT tokens.JWT_PRIVATE_KEY– an RSA private key used to sign JWT tokens. Must be kept secret.RABBITMQ_DEFAULT_USER– a default user name for the Message Broker.RABBITMQ_DEFAULT_PASS– a default user password for the Message Broker.POSTGRES_USER– a default user name for the Main Database server.POSTGRES_PASSWORD– a default user's password for the Main Database server.POSTGRES_DB– a default database name for the Main Database server.