-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
199 lines (189 loc) · 5.14 KB
/
docker-compose.yml
File metadata and controls
199 lines (189 loc) · 5.14 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
version: '3.8'
services:
postgres:
image: postgres:16-alpine
container_name: crypto_analytics_db
environment:
POSTGRES_DB: crypto_analytics
POSTGRES_USER: crypto_user
POSTGRES_PASSWORD: ${DB_PASSWORD:-crypto_secure_password_2024}
# Performance optimizations
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./db_init:/docker-entrypoint-initdb.d
ports:
- "5432:5432"
command: >
postgres
-c max_connections=300
-c shared_buffers=512MB
-c effective_cache_size=2GB
-c work_mem=16MB
-c maintenance_work_mem=256MB
-c checkpoint_completion_target=0.9
-c wal_buffers=32MB
-c default_statistics_target=100
-c random_page_cost=1.1
-c effective_io_concurrency=200
-c max_worker_processes=12
-c max_parallel_workers_per_gather=6
-c max_parallel_workers=12
-c max_parallel_maintenance_workers=4
-c log_statement=ddl
-c log_duration=on
-c log_min_duration_statement=1000
deploy:
resources:
limits:
cpus: '4'
memory: 4G
reservations:
cpus: '2'
memory: 2G
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U crypto_user -d crypto_analytics"]
interval: 30s
timeout: 10s
retries: 5
start_period: 30s
redis:
image: redis:7-alpine
container_name: crypto_analytics_cache
volumes:
- redis_data:/data
- ./config/redis.conf:/usr/local/etc/redis/redis.conf:ro
ports:
- "6379:6379"
command: redis-server /usr/local/etc/redis/redis.conf
deploy:
resources:
limits:
cpus: '1'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
# Read replica for analytics queries (optional, uncomment when needed)
# postgres_replica:
# image: postgres:16-alpine
# container_name: crypto_analytics_replica
# environment:
# POSTGRES_DB: crypto_analytics
# POSTGRES_USER: crypto_user
# POSTGRES_PASSWORD: ${DB_PASSWORD:-crypto_secure_password_2024}
# PGUSER: postgres
# volumes:
# - postgres_replica_data:/var/lib/postgresql/data
# ports:
# - "5433:5432"
# depends_on:
# postgres:
# condition: service_healthy
# restart: unless-stopped
# Database administration interface (optional)
adminer:
image: adminer:4.8.1
container_name: crypto_analytics_admin
ports:
- "8080:8080"
environment:
ADMINER_DEFAULT_SERVER: postgres
ADMINER_DESIGN: lucas
depends_on:
postgres:
condition: service_healthy
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
reservations:
cpus: '0.25'
memory: 256M
restart: unless-stopped
profiles: ["admin"]
# PGAdmin - PostgreSQL administration interface
pgadmin:
image: dpage/pgadmin4:latest
container_name: crypto_analytics_pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL:-admin@example.com}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD:-admin_secure_password_2024}
PGADMIN_CONFIG_SERVER_MODE: 'False'
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
ports:
- "5050:80"
volumes:
- pgadmin_data:/var/lib/pgadmin
- ./config/pgadmin_servers.json:/pgadmin4/servers.json:ro
depends_on:
postgres:
condition: service_healthy
deploy:
resources:
limits:
cpus: '1'
memory: 1G
reservations:
cpus: '0.25'
memory: 256M
restart: unless-stopped
profiles: ["admin"]
# Backup service
postgres_backup:
image: postgres:16-alpine
container_name: crypto_analytics_backup
environment:
POSTGRES_DB: crypto_analytics
POSTGRES_USER: crypto_user
POSTGRES_PASSWORD: ${DB_PASSWORD:-crypto_secure_password_2024}
POSTGRES_HOST: postgres
volumes:
- ./backups:/backups
- ./backup_scripts:/scripts:ro
depends_on:
postgres:
condition: service_healthy
command: >
sh -c "
echo 'Starting backup service...'
while true; do
echo 'Creating backup at $(date)'
pg_dump -h postgres -U crypto_user -d crypto_analytics > /backups/crypto_analytics_$(date +%Y%m%d_%H%M%S).sql
echo 'Backup completed'
# Keep only last 7 days of backups
find /backups -name '*.sql' -type f -mtime +7 -delete
# Wait 24 hours
sleep 86400
done
"
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
restart: unless-stopped
profiles: ["backup"]
volumes:
postgres_data:
driver: local
postgres_replica_data:
driver: local
redis_data:
driver: local
pgadmin_data:
driver: local
networks:
default:
name: crypto_analytics_network