-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
167 lines (161 loc) · 4.71 KB
/
docker-compose.prod.yml
File metadata and controls
167 lines (161 loc) · 4.71 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
# =============================================================================
# Production Docker Compose Configuration
# =============================================================================
# This file demonstrates production-ready Docker Compose configuration
# Copy this file and customize for your production environment
#
# Usage:
# docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# =============================================================================
services:
# PostgreSQL Database - Production Configuration
postgres:
environment:
# IMPORTANT: Set these via environment variables or secrets management
# Never commit actual passwords to version control
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
# Enable SSL for production
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=en_US.UTF-8"
volumes:
- postgres_data:/var/lib/postgresql/data
# Optional: Mount SSL certificates
# - ./ssl/postgres:/var/lib/postgresql/ssl:ro
# Production: Remove port mapping and use internal network only
# ports:
# - "5434:5432"
deploy:
resources:
limits:
cpus: '2.0'
memory: 4G
reservations:
cpus: '1.0'
memory: 2G
# Enable logging
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Redis - Production Configuration
redis:
# Production: Remove port mapping and use internal network only
# ports:
# - "6379:6379"
command: >
sh -c "
redis-server
--appendonly yes
--requirepass $$REDIS_PASSWORD
--maxmemory 2gb
--maxmemory-policy allkeys-lru
--save 60 1000
"
deploy:
resources:
limits:
cpus: '1.0'
memory: 2G
reservations:
cpus: '0.5'
memory: 512M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Backend API - Production Configuration
backend:
environment:
# Set these via environment variables
- DEBUG=False
- ENVIRONMENT=production
- LOG_LEVEL=INFO
- LOG_FORMAT=json
- ENABLE_FILE_LOGGING=True
- SENTRY_DSN=${SENTRY_DSN:-}
- SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT:-production}
- CHECKPOINTS_DIR=/tmp/checkpoints
# Database connection (uses internal Docker network)
- DB_HOST=postgres
- DB_PORT=5432
- DB_USER=${POSTGRES_USER}
- DB_PASSWORD=${POSTGRES_PASSWORD}
- DB_NAME=${POSTGRES_DB}
# Redis connection (uses internal Docker network)
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
# Production: Use multiple workers
command: >
sh -c "mkdir -p /tmp/checkpoints; python -m uvicorn api.main:app
--host 0.0.0.0
--port 8000
--workers 4
--access-log
--log-level info"
deploy:
resources:
limits:
cpus: '4.0'
memory: 4G
reservations:
cpus: '2.0'
memory: 2G
replicas: 2 # Run 2 backend instances for high availability
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
# Health checks with more strict settings
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 5
start_period: 180s
# Frontend - Production Configuration
frontend:
environment:
- NODE_ENV=production
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:8001}
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '1.0'
memory: 512M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# =============================================================================
# Production Environment Variables Required
# =============================================================================
# Create a .env.prod file (DO NOT commit to version control) with:
#
# POSTGRES_USER=powerhouse_user
# POSTGRES_PASSWORD=<generate-secure-password>
# POSTGRES_DB=powerhouse_prod
# REDIS_PASSWORD=<generate-secure-password>
# NEXT_PUBLIC_API_URL=https://api.yourdomain.com
#
# Generate secure passwords:
# openssl rand -base64 32
#
# =============================================================================