-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.production.yml
More file actions
190 lines (183 loc) · 5.55 KB
/
Copy pathdocker-compose.production.yml
File metadata and controls
190 lines (183 loc) · 5.55 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
# Production Docker Compose Configuration with Traefik Reverse Proxy
# Auto-generates environment variables from GitHub secrets during deployment
name: modernapi
services:
# Traefik Reverse Proxy with Automatic SSL
traefik:
image: traefik:v3.0
container_name: modernapi_traefik
restart: unless-stopped
command:
- --api.dashboard=true
- --api.debug=true
- --log.level=INFO
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=modernapi_modernapi_network
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --certificatesresolvers.letsencrypt.acme.tlschallenge=true
- --certificatesresolvers.letsencrypt.acme.email=${ACME_EMAIL}
- --certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json
- --entrypoints.web.http.redirections.entrypoint.to=websecure
- --entrypoints.web.http.redirections.entrypoint.scheme=https
- --entrypoints.web.http.redirections.entrypoint.permanent=true
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- traefik_data:/letsencrypt
networks:
- modernapi_network
labels:
- traefik.enable=true
- traefik.http.routers.traefik.rule=Host(`traefik.${DOMAIN}`)
- traefik.http.routers.traefik.tls=true
- traefik.http.routers.traefik.tls.certresolver=letsencrypt
- traefik.http.routers.traefik.service=api@internal
- traefik.http.routers.traefik.middlewares=auth
- traefik.http.middlewares.auth.basicauth.users=${TRAEFIK_AUTH}
deploy:
resources:
limits:
memory: 256M
reservations:
memory: 128M
# PostgreSQL Database
postgres:
image: postgres:16-alpine
container_name: modernapi_postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-modernapi_prod}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- modernapi_network
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-modernapi_prod}"]
interval: 30s
timeout: 10s
retries: 3
# Redis Cache
redis:
image: redis:7-alpine
container_name: modernapi_redis
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD} --maxmemory 512mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
networks:
- modernapi_network
deploy:
resources:
limits:
memory: 512M
reservations:
memory: 256M
healthcheck:
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
interval: 30s
timeout: 3s
retries: 5
# .NET API Backend
api:
build:
context: ./backend
dockerfile: Dockerfile
container_name: modernapi_api
restart: unless-stopped
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://+:5000
- ConnectionStrings__DefaultConnection=${DATABASE_CONNECTION}
- ConnectionStrings__Redis=redis:6379,password=${REDIS_PASSWORD}
- JWT_SECRET=${JWT_SECRET}
- JWT_ISSUER=${JWT_ISSUER:-ModernAPI}
- JWT_AUDIENCE=${JWT_AUDIENCE:-ModernAPI-Users}
- JWT__Secret=${JWT_SECRET}
- JWT__Issuer=${JWT_ISSUER:-ModernAPI}
- JWT__Audience=${JWT_AUDIENCE:-ModernAPI-Users}
- JWT__ExpiryMinutes=${JWT_EXPIRY_MINUTES:-60}
- CORS__AllowedOrigins=https://${DOMAIN},https://api.${DOMAIN}
expose:
- "5000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- modernapi_network
labels:
- traefik.enable=true
- traefik.http.routers.api.rule=Host(`api.${DOMAIN}`)
- traefik.http.routers.api.tls=true
- traefik.http.routers.api.tls.certresolver=letsencrypt
- traefik.http.services.api.loadbalancer.server.port=5000
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Frontend (TanStack Start with Bun SSR)
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
- VITE_API_BASE_URL=https://api.${DOMAIN}
container_name: modernapi_frontend
restart: unless-stopped
environment:
- NODE_ENV=production
- PORT=3000
- VITE_API_BASE_URL=https://api.${DOMAIN}
expose:
- "3000"
networks:
- modernapi_network
labels:
- traefik.enable=true
- traefik.http.routers.frontend.rule=Host(`${DOMAIN}`)
- traefik.http.routers.frontend.tls=true
- traefik.http.routers.frontend.tls.certresolver=letsencrypt
- traefik.http.services.frontend.loadbalancer.server.port=3000
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 512M
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/"]
interval: 30s
timeout: 5s
retries: 3
networks:
modernapi_network:
driver: bridge
volumes:
postgres_data:
driver: local
redis_data:
driver: local
traefik_data:
driver: local