Skip to content

Commit

Permalink
Add cluster support
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jun 7, 2024
1 parent 1d4fcb2 commit e79bc3d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ $ wget https://raw.githubusercontent.com/Clivern/Lynx/main/nginx.conf \
$ docker-compose up -d
```

To run a 3 Nodes of `Lynx` behind nginx reverse proxy on port `80` on docker.

```bash
$ wget https://raw.githubusercontent.com/Clivern/Lynx/main/docker-compose-cluster.yml \
-O docker-compose.yml
$ wget https://raw.githubusercontent.com/Clivern/Lynx/main/nginx-cluster.conf \
-O nginx.conf

$ docker-compose up -d
```

Here is a [video demonstration](https://www.youtube.com/watch?v=YNkHfysr3-0)


Expand Down
94 changes: 94 additions & 0 deletions docker-compose-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: '3.8'

services:
app1:
image: clivern/lynx:0.11.10
environment:
APP_NAME: Lynx
APP_PORT: 4001
APP_SECRET: koPmu7TJCwD8mttV9vgWUeU7iuu/zTPOR3sX4UalM9KkYEVGPfyi0PeTVzu1TT8C
APP_HOST: localhost
APP_HTTP_SCHEMA: http
DB_USERNAME: root
DB_PASSWORD: D1q9f0C2&PEW
DB_HOSTNAME: db
DB_DATABASE: lynx
DB_PORT: 5432
DB_SSL: null
DB_CA_CERTFILE_PATH: null
MIX_ENV: prod
command: sh -c "/app/bin/migrate && /app/bin/server"
restart: unless-stopped
depends_on:
- db

app2:
image: clivern/lynx:0.11.10
environment:
APP_NAME: Lynx
APP_PORT: 4002
APP_SECRET: koPmu7TJCwD8mttV9vgWUeU7iuu/zTPOR3sX4UalM9KkYEVGPfyi0PeTVzu1TT8C
APP_HOST: localhost
APP_HTTP_SCHEMA: http
DB_USERNAME: root
DB_PASSWORD: D1q9f0C2&PEW
DB_HOSTNAME: db
DB_DATABASE: lynx
DB_PORT: 5432
DB_SSL: null
DB_CA_CERTFILE_PATH: null
MIX_ENV: prod
command: sh -c "/app/bin/migrate && /app/bin/server"
restart: unless-stopped
depends_on:
- db

app3:
image: clivern/lynx:0.11.10
environment:
APP_NAME: Lynx
APP_PORT: 4003
APP_SECRET: koPmu7TJCwD8mttV9vgWUeU7iuu/zTPOR3sX4UalM9KkYEVGPfyi0PeTVzu1TT8C
APP_HOST: localhost
APP_HTTP_SCHEMA: http
DB_USERNAME: root
DB_PASSWORD: D1q9f0C2&PEW
DB_HOSTNAME: db
DB_DATABASE: lynx
DB_PORT: 5432
DB_SSL: null
DB_CA_CERTFILE_PATH: null
MIX_ENV: prod
command: sh -c "/app/bin/migrate && /app/bin/server"
restart: unless-stopped
depends_on:
- db

db:
image: postgres:16.3
environment:
POSTGRES_DB: lynx
POSTGRES_USER: root
POSTGRES_PASSWORD: D1q9f0C2&PEW
restart: unless-stopped
volumes:
- db:/var/lib/postgresql/data

nginx:
image: nginx:1.25.4-alpine3.18
ports:
- '80:80'
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost/_ready"]
interval: 30s
retries: 3
restart: unless-stopped
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- nginx_logs:/var/log/nginx

volumes:
db:
driver: local
nginx_logs:
driver: local
26 changes: 26 additions & 0 deletions nginx-cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
events { }

http {
upstream app_servers {
# Default Algorithm is Round Robin
server app1:4001;
server app2:4002;
server app3:4003;
}

server {
listen 80;
server_name lynx.sh; # Replace with your actual domain name

location / {
proxy_pass http://app_servers;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;

proxy_redirect off;
}
}
}

0 comments on commit e79bc3d

Please sign in to comment.