-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker.compose.yaml
More file actions
279 lines (233 loc) · 6.68 KB
/
docker.compose.yaml
File metadata and controls
279 lines (233 loc) · 6.68 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# docker-compose.yml for Beam
#
# Complete local development and production environment for Beam
#
# Services:
# - PostgreSQL: Durable storage with TimescaleDB for time-series data
# - Redis: Hot path operations (sub-millisecond balance checks)
# - Beam API: Main gRPC + REST server
# - pgAdmin: Database management UI (optional)
# - Redis Commander: Redis inspection UI (optional)
#
# Usage:
# docker-compose up -d # Start all services
# docker-compose logs -f beam-api # Follow API logs
# docker-compose down # Stop all services
# docker-compose down -v # Stop and remove volumes (fresh start)
version: '3.8'
services:
# PostgreSQL with TimescaleDB for durable storage
postgres:
image: timescale/timescaledb:latest-pg16
container_name: beam-postgres
restart: unless-stopped
environment:
POSTGRES_DB: beam
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# Performance tuning
POSTGRES_SHARED_BUFFERS: 256MB
POSTGRES_MAX_CONNECTIONS: 100
POSTGRES_EFFECTIVE_CACHE_SIZE: 1GB
POSTGRES_WORK_MEM: 16MB
ports:
- "5432:5432"
volumes:
# Persist database data
- postgres_data:/var/lib/postgresql/data
# Auto-run migrations on startup
- ./backend/migrations:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d beam"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
networks:
- beam-network
# Redis for hot path balance operations
redis:
image: redis:7-alpine
container_name: beam-redis
restart: unless-stopped
command: >
redis-server
--maxmemory 512mb
--maxmemory-policy allkeys-lru
--save 60 1000
--appendonly yes
--appendfsync everysec
ports:
- "6379:6379"
volumes:
# Persist Redis data (RDB snapshots and AOF)
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 5s
networks:
- beam-network
# Beam API server (gRPC + REST)
beam-api:
build:
context: ./backend
dockerfile: ../docker/Dockerfile
args:
GO_VERSION: "1.25"
container_name: beam-api
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
environment:
# Server ports
GRPC_PORT: "9090"
HTTP_PORT: "8080"
# Database connections
REDIS_ADDR: "redis:6379"
POSTGRES_URL: "postgres://postgres:postgres@postgres:5432/beam?sslmode=disable"
# Application config
LOG_LEVEL: "debug"
ENVIRONMENT: "development"
# Optional: Enable detailed metrics
ENABLE_METRICS: "true"
ENABLE_PROFILING: "false"
ports:
- "9090:9090" # gRPC
- "8080:8080" # HTTP (REST + health checks + metrics)
healthcheck:
test: ["CMD", "wget", "-q", "-O", "-", "http://localhost:8080/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
networks:
- beam-network
# Resource limits (adjust for production)
deploy:
resources:
limits:
cpus: '2.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 256M
# pgAdmin for database management (optional, disable in production)
pgadmin:
image: dpage/pgadmin4:latest
container_name: beam-pgadmin
restart: unless-stopped
profiles:
- tools # Only start with --profile tools
environment:
PGADMIN_DEFAULT_EMAIL: admin@beam.dev
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_CONFIG_SERVER_MODE: 'False'
ports:
- "5050:80"
volumes:
- pgadmin_data:/var/lib/pgadmin
networks:
- beam-network
# Redis Commander for Redis inspection (optional, disable in production)
redis-commander:
image: rediscommander/redis-commander:latest
container_name: beam-redis-commander
restart: unless-stopped
profiles:
- tools # Only start with --profile tools
environment:
REDIS_HOSTS: local:redis:6379
ports:
- "8081:8081"
networks:
- beam-network
# Prometheus for metrics collection (optional)
prometheus:
image: prom/prometheus:latest
container_name: beam-prometheus
restart: unless-stopped
profiles:
- monitoring
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
ports:
- "9091:9090"
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
networks:
- beam-network
# Grafana for metrics visualization (optional)
grafana:
image: grafana/grafana:latest
container_name: beam-grafana
restart: unless-stopped
profiles:
- monitoring
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
GF_USERS_ALLOW_SIGN_UP: "false"
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
- ./config/grafana-dashboards:/etc/grafana/provisioning/dashboards
networks:
- beam-network
volumes:
postgres_data:
driver: local
redis_data:
driver: local
pgadmin_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
networks:
beam-network:
driver: bridge
# =============================================================================
# USAGE EXAMPLES
# =============================================================================
#
# Development (minimal setup):
# docker-compose up -d postgres redis beam-api
#
# Development with tools:
# docker-compose --profile tools up -d
#
# Development with monitoring:
# docker-compose --profile monitoring up -d
#
# Production:
# docker-compose up -d postgres redis beam-api
#
# Scaling:
# docker-compose up -d --scale beam-api=3
#
# Fresh start:
# docker-compose down -v && docker-compose up -d
#
# View logs:
# docker-compose logs -f beam-api
#
# Access services:
# - Beam gRPC: localhost:9090
# - Beam REST: http://localhost:8080
# - PostgreSQL: localhost:5432 (user: postgres, password: postgres)
# - Redis: localhost:6379
# - pgAdmin: http://localhost:5050 (tools profile)
# - Redis Commander: http://localhost:8081 (tools profile)
# - Prometheus: http://localhost:9091 (monitoring profile)
# - Grafana: http://localhost:3000 (monitoring profile)