-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
184 lines (168 loc) · 4.87 KB
/
docker-compose.prod.yml
File metadata and controls
184 lines (168 loc) · 4.87 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
version: '3.8'
# Production Docker Compose Configuration
# This extends docker-compose.yml with production-specific settings
# Usage: docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
services:
db:
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- dbdata:/var/lib/postgresql/data
- ./backups/db:/backups
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '1'
memory: 2G
redis:
restart: unless-stopped
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
migrations:
env_file: .env.prod
environment:
DATABASE_URL: postgresql+psycopg://postgres:${DB_PASSWORD:-change-me-in-production}@db:5432/transcripts
api:
env_file: .env.prod
environment:
DATABASE_URL: postgresql+psycopg://postgres:${DB_PASSWORD:-change-me-in-production}@db:5432/transcripts
REDIS_URL: redis://redis:6379/0
OPENSEARCH_URL: http://opensearch:9200
ENVIRONMENT: production
LOG_LEVEL: INFO
LOG_FORMAT: json
ENABLE_METRICS: "true"
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2'
memory: 4G
reservations:
cpus: '0.5'
memory: 1G
labels:
- "com.centurylinklabs.watchtower.enable=true"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
worker:
env_file: .env.prod
environment:
DATABASE_URL: postgresql+psycopg://postgres:${DB_PASSWORD:-change-me-in-production}@db:5432/transcripts
OPENSEARCH_URL: http://opensearch:9200
ENVIRONMENT: production
LOG_LEVEL: INFO
LOG_FORMAT: json
restart: unless-stopped
deploy:
resources:
limits:
cpus: '4'
memory: 16G
reservations:
cpus: '2'
memory: 8G
labels:
- "com.centurylinklabs.watchtower.enable=true"
opensearch:
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
# Reverse proxy with automatic SSL
caddy:
image: caddy:2-alpine
ports:
- "80:80"
- "443:443"
- "443:443/udp" # HTTP/3 support
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
depends_on:
- api
restart: unless-stopped
deploy:
resources:
limits:
cpus: '1'
memory: 512M
# Automated backups service
backup:
image: transcript-create:latest
env_file: .env.prod
environment:
DATABASE_URL: postgresql+psycopg://postgres:${DB_PASSWORD}@db:5432/transcripts
BACKUP_DIR: /backups
BACKUP_RETENTION_DAILY: ${BACKUP_RETENTION_DAILY:-7}
BACKUP_RETENTION_WEEKLY: ${BACKUP_RETENTION_WEEKLY:-4}
BACKUP_RETENTION_MONTHLY: ${BACKUP_RETENTION_MONTHLY:-12}
MEDIA_RETENTION_DAYS: ${MEDIA_RETENTION_DAYS:-30}
volumes:
- ./data:/data:ro
- ./backups:/backups
- ./scripts:/scripts:ro
entrypoint: ["/bin/bash", "-c"]
command:
- |
# Install cron if not present
apt-get update && apt-get install -y cron postgresql-client
# Create cron jobs
echo "0 2 * * * /scripts/backup_db.sh >> /backups/backup.log 2>&1" > /etc/cron.d/backup-db
echo "0 3 * * * /scripts/backup_media.sh >> /backups/backup.log 2>&1" > /etc/cron.d/backup-media
echo "0 4 * * 0 /scripts/verify_backup.sh >> /backups/verify.log 2>&1" > /etc/cron.d/verify-backup
# Set permissions
chmod 0644 /etc/cron.d/*
# Apply cron jobs
crontab /etc/cron.d/backup-db
crontab /etc/cron.d/backup-media
crontab /etc/cron.d/verify-backup
# Start cron in foreground
echo "Backup service started. Logs in /backups/backup.log"
cron && tail -f /backups/backup.log
depends_on:
- db
restart: unless-stopped
# Automatic container updates (optional but recommended)
watchtower:
image: containrrr/watchtower:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
WATCHTOWER_CLEANUP: "true"
WATCHTOWER_POLL_INTERVAL: ${WATCHTOWER_POLL_INTERVAL:-86400} # Check daily
WATCHTOWER_LABEL_ENABLE: "true"
WATCHTOWER_INCLUDE_STOPPED: "false"
WATCHTOWER_REVIVE_STOPPED: "false"
WATCHTOWER_NOTIFICATION_URL: ${WATCHTOWER_NOTIFICATION_URL:-} # Slack/email notifications
restart: unless-stopped
volumes:
dbdata:
driver: local
redis-data:
driver: local
caddy-data:
driver: local
caddy-config:
driver: local
networks:
default:
name: transcript-create-prod
driver: bridge