diff --git a/README.md b/README.md index c6b4a6d7..ca78bc07 100644 --- a/README.md +++ b/README.md @@ -31,38 +31,43 @@ Read complete medium posts **Introducing SAMA** and **What is SAMA** about what Frontend app (web + mobile) is available at https://github.com/SAMA-Communications/sama-client -## Development +## Local development -- Make sure you have `Node 18.20.x` installed. +- Make sure you have latest `Node 18` installed. - Copy `.env.example` to `.env`. -- Run `docker-compose up` to run dependant services (MongoDB, Minio, Redis) +- Run `docker-compose -f docker-compose.yml -f docker-compose.development.yml up` to run dependant services (MongoDB, Minio, Redis) - `npm install` to install dependencies - `npm run migrate-mongo-up` to run DB migrations - `npm run start` to run server (in a case of running under Windows - see https://github.com/SAMA-Communications/sama-server/issues/128) +- Now the server will be listening for incoming connections at `ws://localhost:9001` -There are also other components. Make sure to check [Deploying SAMA chat server stack: a comprehensive guide](https://medium.com/sama-communications/deploying-sama-chat-server-stack-a-comprehensive-guide-294ddb9a2d78) +There are also other components available in SAMA stack - check it out [Deploying SAMA chat server stack: a comprehensive guide](https://medium.com/sama-communications/deploying-sama-chat-server-stack-a-comprehensive-guide-294ddb9a2d78) + + +## Deployment + +Deploying the SAMA application can be done easily with Docker, whether you want a complete setup with all dependencies or a local environment with the main applications. Below are the steps to follow: ### Docker one-command deployment -To build and run the `SAMA` with all dependencies, you can use the following command: +This approach builds and runs the entire SAMA application, including all dependencies, in a single command. It is ideal for setting up the full environment quickly. + +To deploy using this method, run: ``` docker-compose -f docker-compose-full.yml up --build ``` -If you only want to run dependency services (for local development without Docker), use this command: +### Docker local deployment -``` -docker-compose up -``` - -Run dependency services with `SAMA` main apps (sama-client, sama-server, sama-push-daemon): +To run the dependency services along with the main `SAMA` applications (`sama-client`, `sama-server`, and `sama-push-daemon`), use: ``` -RUN_SAMA=true docker-compose up --build +docker-compose up --build ``` :warning: If you are using MacOS or Windows, and want run `SAMA` apps, add these two variables before the launch command: + MacOS ``` diff --git a/docker-compose.development.yml b/docker-compose.development.yml new file mode 100644 index 00000000..da3990ae --- /dev/null +++ b/docker-compose.development.yml @@ -0,0 +1,23 @@ +version: "3.8" + +services: + sama-client: + # Define the service here as an empty object to effectively exclude it + # Or simply leave it out if you want to remove it completely + # Example: + deploy: + replicas: 0 + + sama-server: + # Define the service here as an empty object to effectively exclude it + # Or simply leave it out if you want to remove it completely + # Example: + deploy: + replicas: 0 + + sama-push-daemon: + # Define the service here as an empty object to effectively exclude it + # Or simply leave it out if you want to remove it completely + # Example: + deploy: + replicas: 0 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 01b85d41..c2f27dd5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,150 +10,45 @@ networks: services: sama-client: - build: - context: ./prefs/client - dockerfile: Dockerfile.frontend - environment: - - RUN_SAMA=${RUN_SAMA:-false} - entrypoint: > - sh -c "if [ \$$RUN_SAMA = 'true' ]; then - npm run start; - else - sleep infinity; - fi" - networks: - sama_network: - ipv4_address: 172.25.0.8 - ports: - - "3000:3000" - volumes: - - ./prefs/client/.env.frontend:/app/.env + extends: + file: ./prefs/docker-compose/services/frontend.yml + service: sama-client sama-server: - build: - context: . - dockerfile: Dockerfile - depends_on: - mongo: - condition: service_healthy - environment: - - RUN_SAMA=${RUN_SAMA:-false} - - MINIO_ENDPOINT=${MINIO_ENDPOINT:-172.25.0.2} - - MINIO_PORT=${MINIO_PORT:-9000} - entrypoint: > - sh -c "if [ \$$RUN_SAMA = 'true' ]; then - npm run migrate-mongo-up; - npm run start; - else - sleep infinity; - fi" - networks: - sama_network: - ipv4_address: 172.25.0.7 - volumes: - - ./.env.local:/app/.env - ports: - - "9000:9001" + extends: + file: ./prefs/docker-compose/services/backend.yml + service: sama-server sama-push-daemon: - build: - context: ./prefs/push - dockerfile: Dockerfile.push - environment: - - RUN_SAMA=${RUN_SAMA:-false} - entrypoint: > - sh -c "if [ \$$RUN_SAMA = 'true' ]; then - npm run start; - else - sleep infinity; - fi" - networks: - sama_network: - ipv4_address: 172.25.0.10 - volumes: - - ./prefs/push/.env.push:/app/.env + extends: + file: ./prefs/docker-compose/services/push-daemon.yml + service: sama-push-daemon s3: - image: minio/minio - networks: - sama_network: - ipv4_address: 172.25.0.2 - ports: - - "9011:9001" - - "9010:9000" - volumes: - - data:/data - env_file: - - ./.env.local - command: server --address 0.0.0.0:9000 --console-address :9001 /data - healthcheck: - test: ["CMD", "mc", "ready", "local"] - interval: 30s - timeout: 20s - retries: 3 + extends: + file: ./prefs/docker-compose/services/s3.yml + service: s3 s3-service: - image: minio/mc - networks: - sama_network: - ipv4_address: 172.25.0.3 - depends_on: - s3: - condition: service_healthy - env_file: - - ./.env.local - entrypoint: > - /bin/sh -c " - /usr/bin/mc alias set sama http://s3:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD}; - /usr/bin/mc mb sama/samabucket; - /usr/bin/mc policy set public sama/samabucket; - /usr/bin/mc admin user svcacct add --access-key $${MINIO_ACCESS_KEY} --secret-key $${MINIO_SECRET_KEY} sama $${MINIO_ROOT_USER} - " + extends: + file: ./prefs/docker-compose/services/s3.yml + service: s3-service mongo: - platform: linux/x86_64 - image: mongo:4.4 - networks: - sama_network: - ipv4_address: 172.25.0.4 - container_name: server_mongo_database - restart: always - volumes: - - mongo:/data/db - environment: - - MONGO_INITDB_DATABASE=samadb - ports: - - "27017:27017" - healthcheck: - test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/samadb --quiet - interval: 30s - timeout: 20s - retries: 3 + extends: + file: ./prefs/docker-compose/services/db.yml + service: mongo redis: - image: redis - networks: - sama_network: - ipv4_address: 172.25.0.5 - container_name: server_redis_database - restart: always - ports: - - "6379:6379" + extends: + file: ./prefs/docker-compose/services/db.yml + service: redis redis-commander: - container_name: redis-commander - hostname: redis-commander - image: rediscommander/redis-commander:latest - networks: - sama_network: - ipv4_address: 172.25.0.6 - restart: always - environment: - - REDIS_HOSTS=local:redis:6379 - ports: - - "8081:8081" + extends: + file: ./prefs/docker-compose/services/db.yml + service: redis-commander volumes: data: - mongo: - mongo-tests: + mongo: \ No newline at end of file diff --git a/prefs/client/Dockerfile.frontend b/prefs/client/Dockerfile.frontend index effee985..e47b3c38 100644 --- a/prefs/client/Dockerfile.frontend +++ b/prefs/client/Dockerfile.frontend @@ -1,8 +1,8 @@ FROM alpine/git as clone WORKDIR /app - -RUN git clone https://github.com/SAMA-Communications/sama-client.git . +RUN git config --global http.version HTTP/1.1 +RUN git clone https://github.com/SAMA-Communications/sama-client.git . --depth 1 FROM node:18.16.0 as builder diff --git a/prefs/docker-compose/services/backend.yml b/prefs/docker-compose/services/backend.yml new file mode 100644 index 00000000..1c53237f --- /dev/null +++ b/prefs/docker-compose/services/backend.yml @@ -0,0 +1,22 @@ +version: "3.8" + +services: + + sama-server: + build: + context: ../../../. + dockerfile: Dockerfile + container_name: "sama-server" + depends_on: + mongo: + condition: service_healthy + environment: + - MINIO_ENDPOINT=${MINIO_ENDPOINT:-172.25.0.2} + - MINIO_PORT=${MINIO_PORT:-9000} + networks: + sama_network: + ipv4_address: 172.25.0.7 + volumes: + - ../../../.env.local:/app/.env + ports: + - "9000:9001" \ No newline at end of file diff --git a/prefs/docker-compose/services/db.yml b/prefs/docker-compose/services/db.yml new file mode 100644 index 00000000..06d3f979 --- /dev/null +++ b/prefs/docker-compose/services/db.yml @@ -0,0 +1,45 @@ +version: "3.8" + +services: + mongo: + platform: linux/x86_64 + image: mongo:4.4 + networks: + sama_network: + ipv4_address: 172.25.0.4 + container_name: server_mongo_database + restart: always + volumes: + - mongo:/data/db + environment: + - MONGO_INITDB_DATABASE=samadb + ports: + - "27017:27017" + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/samadb --quiet + interval: 30s + timeout: 20s + retries: 3 + + redis: + image: redis + networks: + sama_network: + ipv4_address: 172.25.0.5 + container_name: server_redis_database + restart: always + ports: + - "6379:6379" + + redis-commander: + container_name: redis-commander + hostname: redis-commander + image: rediscommander/redis-commander:latest + networks: + sama_network: + ipv4_address: 172.25.0.6 + restart: always + environment: + - REDIS_HOSTS=local:redis:6379 + ports: + - "8081:8081" \ No newline at end of file diff --git a/prefs/docker-compose/services/frontend.yml b/prefs/docker-compose/services/frontend.yml new file mode 100644 index 00000000..133fe2bc --- /dev/null +++ b/prefs/docker-compose/services/frontend.yml @@ -0,0 +1,15 @@ +version: "3.8" + +services: + sama-client: + build: + context: ../../client + dockerfile: Dockerfile.frontend + container_name: "sama-client" + networks: + sama_network: + ipv4_address: 172.25.0.8 + ports: + - "3000:3000" + volumes: + - ../../client/.env.frontend:/app/.env \ No newline at end of file diff --git a/prefs/docker-compose/services/push-daemon.yml b/prefs/docker-compose/services/push-daemon.yml new file mode 100644 index 00000000..dfaf2137 --- /dev/null +++ b/prefs/docker-compose/services/push-daemon.yml @@ -0,0 +1,12 @@ +version: "3.8" + +services: + sama-push-daemon: + build: + context: ../../push + dockerfile: Dockerfile.push + networks: + sama_network: + ipv4_address: 172.25.0.10 + volumes: + - ../../push/.env.push:/app/.env \ No newline at end of file diff --git a/prefs/docker-compose/services/s3.yml b/prefs/docker-compose/services/s3.yml new file mode 100644 index 00000000..929d1047 --- /dev/null +++ b/prefs/docker-compose/services/s3.yml @@ -0,0 +1,39 @@ +version: "3.8" + +services: + s3: + image: minio/minio + networks: + sama_network: + ipv4_address: 172.25.0.2 + ports: + - "9011:9001" + - "9010:9000" + volumes: + - data:/data + env_file: + - ../../../.env.local + command: server --address 0.0.0.0:9000 --console-address :9001 /data + healthcheck: + test: ["CMD", "mc", "ready", "local"] + interval: 30s + timeout: 20s + retries: 3 + + s3-service: + image: minio/mc + networks: + sama_network: + ipv4_address: 172.25.0.3 + depends_on: + s3: + condition: service_healthy + env_file: + - ../../../.env.local + entrypoint: > + /bin/sh -c " + /usr/bin/mc alias set sama http://s3:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD}; + /usr/bin/mc mb sama/samabucket; + /usr/bin/mc policy set public sama/samabucket; + /usr/bin/mc admin user svcacct add --access-key $${MINIO_ACCESS_KEY} --secret-key $${MINIO_SECRET_KEY} sama $${MINIO_ROOT_USER} + " \ No newline at end of file