-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
127 lines (118 loc) · 4.09 KB
/
Copy pathdocker-compose.yml
File metadata and controls
127 lines (118 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# SyncDoc — Production docker-compose
#
# Architecture:
# nginx → reverse proxy / load balancer (ip_hash sticky sessions)
# app1, app2 → two Node.js app containers (Express + WebSocket)
# postgres → PostgreSQL 16 (shared by both app containers)
# redis → Redis 7 (pub/sub for cross-server Yjs update relay)
#
# Prerequisites:
# 1. Create a .env file in this directory:
# POSTGRES_PASSWORD=your_strong_password
# DOMAIN=syncdoc.yourdomain.com
# 2. Obtain SSL certs first:
# certbot certonly --standalone -d syncdoc.yourdomain.com
# 3. Update nginx/nginx.conf — replace syncdoc.yourdomain.com with your domain
#
# Start: docker-compose up -d --build
# Logs: docker-compose logs -f app1 app2
# Stop: docker-compose down
version: '3.8'
# Shared environment variables — avoids repetition between app1 and app2.
# SERVER_ID is set per-service below so Prometheus can label metrics by instance.
x-app-env: &app-env
NODE_ENV: production
PORT: 3001
DATABASE_URL: postgresql://syncdoc:${POSTGRES_PASSWORD:-syncdoc}@postgres:5432/syncdoc
REDIS_URL: redis://redis:6379
CLIENT_ORIGIN: https://${DOMAIN:-localhost}
services:
# ── Nginx load balancer ──────────────────────────────────────────────────────
# Handles SSL termination, ip_hash sticky sessions for WebSocket,
# and round-robin for REST API calls.
nginx:
image: nginx:1.25-alpine
container_name: syncdoc_nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- /etc/letsencrypt:/etc/letsencrypt:ro
- nginx_logs:/var/log/nginx
depends_on:
- app1
- app2
restart: unless-stopped
networks:
- internal
# ── App container 1 ─────────────────────────────────────────────────────────
app1:
build: .
container_name: syncdoc_app1
environment:
<<: *app-env
SERVER_ID: app1
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
networks:
- internal
# ── App container 2 ─────────────────────────────────────────────────────────
app2:
build: .
container_name: syncdoc_app2
environment:
<<: *app-env
SERVER_ID: app2
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
networks:
- internal
# ── PostgreSQL ───────────────────────────────────────────────────────────────
postgres:
image: postgres:16-alpine
container_name: syncdoc_postgres
environment:
POSTGRES_DB: syncdoc
POSTGRES_USER: syncdoc
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-syncdoc}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U syncdoc"]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped
networks:
- internal
# ── Redis ─────────────────────────────────────────────────────────────────────
redis:
image: redis:7-alpine
container_name: syncdoc_redis
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
networks:
- internal
volumes:
postgres_data:
redis_data:
nginx_logs:
networks:
internal:
driver: bridge