Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сhange development flow #132

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -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
155 changes: 25 additions & 130 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
4 changes: 2 additions & 2 deletions prefs/client/Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -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

Expand Down
22 changes: 22 additions & 0 deletions prefs/docker-compose/services/backend.yml
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions prefs/docker-compose/services/db.yml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 15 additions & 0 deletions prefs/docker-compose/services/frontend.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions prefs/docker-compose/services/push-daemon.yml
Original file line number Diff line number Diff line change
@@ -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
Loading