-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
115 lines (108 loc) · 3.56 KB
/
docker-compose.prod.yml
File metadata and controls
115 lines (108 loc) · 3.56 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
services:
# ── PostgreSQL + PostGIS ─────────────────────────────
db:
image: postgis/postgis:16-3.4
environment:
POSTGRES_DB: ${POSTGRES_DB:-espalert}
POSTGRES_USER: ${POSTGRES_USER:-espalert}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-espalert} -d ${POSTGRES_DB:-espalert}" ]
interval: 10s
timeout: 5s
retries: 5
restart: always
# ── Redis ────────────────────────────────────────────
redis:
image: redis:7-alpine
command: redis-server --requirepass ${REDIS_PASSWORD} --appendonly yes
volumes:
- redisdata:/data
healthcheck:
test: [ "CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping" ]
interval: 10s
timeout: 5s
retries: 5
restart: always
# ── FastAPI Backend (Production) ─────────────────────
api:
build:
context: ./apps/api
dockerfile: Dockerfile
env_file:
- .env
environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
DATABASE_URL_SYNC: postgresql+psycopg2://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
ENVIRONMENT: production
DEBUG: "false"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
command: >
sh -c "
alembic upgrade head &&
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000 --access-logfile - --error-logfile -
"
restart: always
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
# ── Celery Worker ────────────────────────────────────
worker:
build:
context: ./apps/api
dockerfile: Dockerfile
env_file:
- .env
environment:
DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
ENVIRONMENT: production
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
command: celery -A app.tasks.celery_app worker --loglevel=info --concurrency=2
restart: always
# ── Celery Beat ──────────────────────────────────────
beat:
build:
context: ./apps/api
dockerfile: Dockerfile
env_file:
- .env
environment:
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379/0
ENVIRONMENT: production
depends_on:
redis:
condition: service_healthy
command: celery -A app.tasks.celery_app beat --loglevel=info
restart: always
# ── Nginx Reverse Proxy ──────────────────────────────
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/certs:/etc/nginx/certs:ro
- ./nginx/vhost.d:/etc/nginx/vhost.d
- ./nginx/html:/usr/share/nginx/html
- /etc/letsencrypt:/etc/letsencrypt:ro
depends_on:
- api
restart: always
volumes:
pgdata:
redisdata: