-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
201 lines (195 loc) · 5.2 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
201 lines (195 loc) · 5.2 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
# GameLink 生产环境 Docker Compose 配置
# 使用方式: docker-compose -f docker-compose.prod.yml --env-file .env.production up -d
#
# 与开发环境的区别:
# 1. CRYPTO_ENABLED=true (强制加密)
# 2. SEED_ENABLED=false (不初始化种子数据)
# 3. PostgreSQL/Redis 性能调优
# 4. 资源限制
# 5. 包含后端和前端服务
services:
# PostgreSQL 数据库
postgres:
image: postgres:16-alpine
container_name: gamelink-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-gamelink}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB:-gamelink}
POSTGRES_INITDB_ARGS: --encoding=UTF8 --lc-collate=C --lc-ctype=C
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- gamelink-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-gamelink} -d ${POSTGRES_DB:-gamelink}"]
interval: 10s
timeout: 5s
retries: 5
# PostgreSQL 性能调优
command:
- "postgres"
- "-c"
- "max_connections=200"
- "-c"
- "shared_buffers=256MB"
- "-c"
- "effective_cache_size=768MB"
- "-c"
- "maintenance_work_mem=64MB"
- "-c"
- "checkpoint_completion_target=0.9"
- "-c"
- "wal_buffers=16MB"
- "-c"
- "default_statistics_target=100"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "effective_io_concurrency=200"
- "-c"
- "work_mem=4MB"
- "-c"
- "min_wal_size=1GB"
- "-c"
- "max_wal_size=4GB"
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M
# Redis 缓存
redis:
image: redis:7-alpine
container_name: gamelink-redis
restart: unless-stopped
command: >
redis-server
--requirepass ${REDIS_PASSWORD}
--appendonly yes
--appendfsync everysec
--maxmemory 512mb
--maxmemory-policy allkeys-lru
--tcp-backlog 511
--tcp-keepalive 300
--timeout 0
--save ""
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis_data:/data
networks:
- gamelink-network
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# 后端服务
backend:
build:
context: ./api
dockerfile: Dockerfile
args:
GOPROXY: https://goproxy.cn,direct
container_name: gamelink-backend
restart: unless-stopped
ports:
- "${BACKEND_PORT:-8080}:8080"
environment:
# 应用配置
- APP_ENV=production
- SERVICE_PORT=8080
- GIN_MODE=release
- GOMAXPROCS=${GOMAXPROCS:-4}
# 数据库配置
- DB_DSN=host=postgres port=5432 user=${POSTGRES_USER:-gamelink} password=${POSTGRES_PASSWORD} dbname=${POSTGRES_DB:-gamelink} sslmode=disable
- DB_MAX_CONNS=${DB_MAX_CONNS:-50}
- DB_MAX_IDLE=${DB_MAX_IDLE:-25}
# Redis配置
- CACHE_TYPE=redis
- REDIS_ADDR=redis:6379
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_DB=${REDIS_DB:-0}
# JWT配置
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- JWT_TOKEN_TTL_HOURS=${JWT_TOKEN_TTL_HOURS:-24}
# 加密配置 (生产环境强制开启)
- CRYPTO_ENABLED=true
- CRYPTO_SECRET_KEY=${CRYPTO_SECRET_KEY}
- CRYPTO_IV=${CRYPTO_IV}
- CRYPTO_USE_SIGNATURE=true
# 超级管理员配置
- SUPER_ADMIN_EMAIL=${SUPER_ADMIN_EMAIL}
- SUPER_ADMIN_PASSWORD=${SUPER_ADMIN_PASSWORD}
- SUPER_ADMIN_NAME=${SUPER_ADMIN_NAME:-Super Admin}
# 种子数据 (生产环境关闭)
- SEED_ENABLED=false
volumes:
- ./api/configs:/app/configs:ro
- backend_data:/app/var
- backend_logs:/app/logs
networks:
- gamelink-network
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/api/v1/healthz"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
# 管理后台前端
admin:
build:
context: ./admin
dockerfile: Dockerfile
args:
NPM_REGISTRY: https://registry.npmmirror.com
container_name: gamelink-admin
restart: unless-stopped
ports:
- "${ADMIN_HTTP_PORT:-80}:80"
- "${ADMIN_HTTPS_PORT:-443}:443"
depends_on:
backend:
condition: service_healthy
networks:
- gamelink-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
networks:
gamelink-network:
driver: bridge
name: gamelink-network
volumes:
postgres_data:
name: gamelink-postgres-data
redis_data:
name: gamelink-redis-data
backend_data:
name: gamelink-backend-data
backend_logs:
name: gamelink-backend-logs