-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.dev-lb.yml
More file actions
151 lines (140 loc) · 5 KB
/
Copy pathdocker-compose.dev-lb.yml
File metadata and controls
151 lines (140 loc) · 5 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# SyncDoc — Local load balancer + monitoring stack
#
# Matches your tweaked setup (port 8080, sslmode=disable) plus adds
# Prometheus and Grafana for live metrics.
#
# Usage:
# docker-compose -f docker-compose.dev-lb.yml up --build
#
# Access:
# App: http://localhost:8080
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (login: admin / admin)
# Metrics: http://localhost:8080/metrics (via nginx → app round-robin)
version: '3.8'
# Shared env — matches your working tweaked version
x-app-env: &app-env
NODE_ENV: production
PORT: 3001
DATABASE_URL: postgresql://syncdoc:syncdoc@postgres:5432/syncdoc?sslmode=disable
REDIS_URL: redis://redis:6379
CLIENT_ORIGIN: http://localhost:8080
services:
# ── Nginx load balancer ──────────────────────────────────────────────────────
nginx:
image: nginx:1.25-alpine
ports:
- "8080:80"
volumes:
- ./nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro
depends_on:
- app1
- app2
networks:
- internal
# ── App container 1 ─────────────────────────────────────────────────────────
# No external port needed — Prometheus is on the same Docker network
# and can reach app1:3001 directly by container hostname.
app1:
build: .
container_name: syncdoc_app1
environment:
<<: *app-env
SERVER_ID: app1
ports:
- "3001:3001" # direct access for cross-server load test
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- internal
# ── App container 2 ─────────────────────────────────────────────────────────
app2:
build: .
container_name: syncdoc_app2
environment:
<<: *app-env
SERVER_ID: app2
ports:
- "3002:3001" # direct access for cross-server load test
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- internal
# ── PostgreSQL ───────────────────────────────────────────────────────────────
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: syncdoc
POSTGRES_USER: syncdoc
POSTGRES_PASSWORD: syncdoc
volumes:
- postgres_dev_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U syncdoc"]
interval: 5s
timeout: 5s
retries: 10
networks:
- internal
# ── Redis ─────────────────────────────────────────────────────────────────────
redis:
image: redis:7-alpine
command: redis-server --appendonly yes
volumes:
- redis_dev_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
networks:
- internal
# ── Prometheus ───────────────────────────────────────────────────────────────
# On the same internal network — can reach app1:3001 and app2:3001 directly.
prometheus:
image: prom/prometheus:latest
container_name: syncdoc_prometheus
ports:
- "9090:9090"
volumes:
- ./monitoring/prometheus.dev.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_dev_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.enable-lifecycle'
- '--storage.tsdb.retention.time=7d'
networks:
- internal
# ── Grafana ──────────────────────────────────────────────────────────────────
# Auto-provisions Prometheus as a datasource and loads the SyncDoc dashboard.
grafana:
image: grafana/grafana:latest
container_name: syncdoc_grafana
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
GF_USERS_ALLOW_SIGN_UP: "false"
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /etc/grafana/provisioning/dashboards/syncdoc.json
volumes:
- grafana_dev_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
depends_on:
- prometheus
networks:
- internal
volumes:
postgres_dev_data:
redis_dev_data:
prometheus_dev_data:
grafana_dev_data:
networks:
internal:
driver: bridge