|
1 | | -# Docker Compose para Produção - ProStaff API |
2 | | -# Deploy com Kamal na Hetzner VPS |
3 | | -# |
4 | | -# IMPORTANTE: |
5 | | -# - PostgreSQL: DESABILITADO - Usa Supabase (configure DATABASE_URL no .env.production) |
6 | | -# - Redis: ESSENCIAL - Usado por Sidekiq, Rails Cache e Rack::Attack |
7 | | -# - Elasticsearch: ESSENCIAL - Usado para analytics avançados |
8 | | -# - Kibana: OPCIONAL - Interface para explorar dados do Elasticsearch |
9 | | -# |
10 | | -# Para deploy com Kamal: |
11 | | -# 1. Configure .env.production com DATABASE_URL do Supabase |
12 | | -# 2. Configure REDIS_PASSWORD para segurança |
13 | | -# 3. Execute: kamal deploy |
14 | | -# |
15 | | -# Para rodar local (teste de produção): |
16 | | -# docker-compose -f docker-compose.production.yml up -d |
17 | | - |
18 | 1 | services: |
19 | | - # Elasticsearch for analytics search |
20 | | - elasticsearch: |
21 | | - image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4 |
22 | | - container_name: prostaff-elasticsearch |
23 | | - restart: unless-stopped |
24 | | - environment: |
25 | | - - discovery.type=single-node |
26 | | - - xpack.security.enabled=false |
27 | | - - ES_JAVA_OPTS=-Xms1g -Xmx1g |
28 | | - volumes: |
29 | | - - es_data:/usr/share/elasticsearch/data |
30 | | - ports: |
31 | | - - "9200:9200" |
32 | | - healthcheck: |
33 | | - test: ["CMD-SHELL", "curl -s http://localhost:9200 >/dev/null || exit 1"] |
34 | | - interval: 10s |
35 | | - timeout: 5s |
36 | | - retries: 10 |
37 | | - networks: |
38 | | - - prostaff-net |
39 | | - |
40 | | - # Kibana for exploring ES indices |
41 | | - kibana: |
42 | | - image: docker.elastic.co/kibana/kibana:8.13.4 |
43 | | - container_name: prostaff-kibana |
44 | | - restart: unless-stopped |
45 | | - environment: |
46 | | - - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 |
47 | | - depends_on: |
48 | | - elasticsearch: |
49 | | - condition: service_healthy |
50 | | - ports: |
51 | | - - "5601:5601" |
52 | | - networks: |
53 | | - - prostaff-net |
54 | | - |
55 | | - # Nginx Reverse Proxy |
56 | | - nginx: |
57 | | - image: nginx:alpine |
58 | | - container_name: prostaff-nginx |
59 | | - restart: unless-stopped |
60 | | - ports: |
61 | | - - "80:80" |
62 | | - - "443:443" |
63 | | - volumes: |
64 | | - - ./deploy/nginx/nginx.conf:/etc/nginx/nginx.conf:ro |
65 | | - - ./deploy/nginx/conf.d:/etc/nginx/conf.d:ro |
66 | | - - ./deploy/ssl:/etc/nginx/ssl:ro |
67 | | - - ./public:/app/public:ro |
68 | | - - nginx_logs:/var/log/nginx |
69 | | - depends_on: |
70 | | - - api |
71 | | - - kibana |
72 | | - networks: |
73 | | - - prostaff-net |
74 | | - healthcheck: |
75 | | - test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"] |
76 | | - interval: 30s |
77 | | - timeout: 10s |
78 | | - retries: 3 |
79 | | - |
80 | | - # PostgreSQL Database - DESABILITADO testar como fallback depois |
81 | | - # Para habilitar PostgreSQL local, descomente este bloco e ajuste depends_on nos outros serviços |
82 | | - # postgres: |
83 | | - # image: postgres:15-alpine |
84 | | - # container_name: prostaff-postgres |
85 | | - # restart: unless-stopped |
86 | | - # environment: |
87 | | - # POSTGRES_DB: ${POSTGRES_DB} |
88 | | - # POSTGRES_USER: ${POSTGRES_USER} |
89 | | - # POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} |
90 | | - # PGDATA: /var/lib/postgresql/data/pgdata |
91 | | - # volumes: |
92 | | - # - postgres_data:/var/lib/postgresql/data |
93 | | - # - ./deploy/postgres/init:/docker-entrypoint-initdb.d:ro |
94 | | - # - ./backups:/backups |
95 | | - # networks: |
96 | | - # - prostaff-net |
97 | | - # healthcheck: |
98 | | - # test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"] |
99 | | - # interval: 10s |
100 | | - # timeout: 5s |
101 | | - # retries: 5 |
102 | | - # deploy: |
103 | | - # resources: |
104 | | - # limits: |
105 | | - # memory: 2G |
106 | | - # reservations: |
107 | | - # memory: 1G |
108 | | - |
109 | | - # Redis para Sidekiq, Rails Cache e Rate Limiting (Rack::Attack) |
110 | | - redis: |
111 | | - image: redis:7-alpine |
112 | | - container_name: prostaff-redis |
113 | | - restart: unless-stopped |
114 | | - # Use redis.production.conf for better durability and monitoring |
115 | | - command: redis-server /etc/redis/redis.conf --requirepass ${REDIS_PASSWORD:-prostaff_redis_2026} |
116 | | - volumes: |
117 | | - - redis_data:/data |
118 | | - - ./redis.production.conf:/etc/redis/redis.conf:ro |
119 | | - networks: |
120 | | - - prostaff-net |
121 | | - ports: |
122 | | - - "6379:6379" |
123 | | - healthcheck: |
124 | | - test: ["CMD", "redis-cli", "--pass", "${REDIS_PASSWORD:-prostaff_redis_2026}", "ping"] |
125 | | - interval: 10s |
126 | | - timeout: 5s |
127 | | - retries: 5 |
128 | | - deploy: |
129 | | - resources: |
130 | | - limits: |
131 | | - memory: 512M # Reduzido para otimizar recursos |
132 | | - reservations: |
133 | | - memory: 256M |
134 | | - |
135 | | - # Rails API |
| 2 | + # --- Aplicação Principal --- |
136 | 3 | api: |
137 | 4 | build: |
138 | 5 | context: . |
139 | 6 | dockerfile: Dockerfile.production |
140 | | - args: |
141 | | - RAILS_ENV: ${RAILS_ENV} |
142 | 7 | container_name: prostaff-api |
143 | 8 | restart: unless-stopped |
144 | 9 | environment: |
145 | | - RAILS_ENV: ${RAILS_ENV} |
146 | | - DATABASE_URL: ${DATABASE_URL} |
147 | | - REDIS_URL: ${REDIS_URL} |
148 | | - SECRET_KEY_BASE: ${SECRET_KEY_BASE} |
149 | | - JWT_SECRET_KEY: ${JWT_SECRET_KEY} |
150 | | - CORS_ORIGINS: ${CORS_ORIGINS} |
151 | | - RIOT_API_KEY: ${RIOT_API_KEY} |
152 | | - SENTRY_DSN: ${SENTRY_DSN} |
153 | | - volumes: |
154 | | - - ./log:/app/log |
155 | | - - ./tmp:/app/tmp |
156 | | - - ./public:/app/public |
| 10 | + RAILS_ENV: production |
| 11 | + # O Coolify preenche as variáveis se você definir na UI, |
| 12 | + # mas aqui garantimos a conexão interna: |
| 13 | + DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} |
| 14 | + REDIS_URL: redis://redis:6379/1 |
| 15 | + ELASTICSEARCH_URL: http://elasticsearch:9200 |
| 16 | + RAILS_LOG_TO_STDOUT: "true" |
| 17 | + PORT: 3000 |
| 18 | + ports: |
| 19 | + - "3000" # O Coolify vai detectar essa porta e criar o domínio automaticamente |
157 | 20 | depends_on: |
| 21 | + postgres: |
| 22 | + condition: service_healthy |
158 | 23 | redis: |
159 | 24 | condition: service_healthy |
160 | | - # postgres: # DESABILITADO - Usa Supabase |
161 | | - # condition: service_healthy |
162 | | - networks: |
163 | | - - prostaff-net |
| 25 | + elasticsearch: |
| 26 | + condition: service_healthy |
164 | 27 | healthcheck: |
165 | 28 | test: ["CMD", "curl", "-f", "http://localhost:3000/up"] |
166 | 29 | interval: 30s |
167 | 30 | timeout: 10s |
168 | 31 | retries: 3 |
169 | | - start_period: 40s |
170 | | - deploy: |
171 | | - replicas: 2 |
172 | | - resources: |
173 | | - limits: |
174 | | - memory: 2G |
175 | | - cpus: '1.0' |
176 | | - reservations: |
177 | | - memory: 512M |
178 | | - cpus: '0.25' |
179 | 32 |
|
180 | | - # Sidekiq Background Jobs |
| 33 | + # --- Worker (Sidekiq) --- |
181 | 34 | sidekiq: |
182 | 35 | build: |
183 | 36 | context: . |
184 | 37 | dockerfile: Dockerfile.production |
185 | | - args: |
186 | | - RAILS_ENV: ${RAILS_ENV} |
187 | 38 | container_name: prostaff-sidekiq |
188 | | - restart: unless-stopped |
189 | 39 | command: bundle exec sidekiq -C config/sidekiq.yml |
190 | 40 | environment: |
191 | | - RAILS_ENV: ${RAILS_ENV} |
192 | | - DATABASE_URL: ${DATABASE_URL} |
193 | | - REDIS_URL: ${SIDEKIQ_REDIS_URL} |
194 | | - SECRET_KEY_BASE: ${SECRET_KEY_BASE} |
195 | | - RIOT_API_KEY: ${RIOT_API_KEY} |
196 | | - SENTRY_DSN: ${SENTRY_DSN} |
197 | | - volumes: |
198 | | - - ./log:/app/log |
199 | | - - ./tmp:/app/tmp |
| 41 | + RAILS_ENV: production |
| 42 | + DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB} |
| 43 | + REDIS_URL: redis://redis:6379/1 |
| 44 | + ELASTICSEARCH_URL: http://elasticsearch:9200 |
200 | 45 | depends_on: |
201 | | - redis: |
202 | | - condition: service_healthy |
203 | | - # postgres: # DESABILITADO - Usa Supabase |
204 | | - # condition: service_healthy |
205 | | - networks: |
206 | | - - prostaff-net |
207 | | - deploy: |
208 | | - resources: |
209 | | - limits: |
210 | | - memory: 1G |
211 | | - cpus: '0.5' |
212 | | - reservations: |
213 | | - memory: 256M |
214 | | - cpus: '0.1' |
| 46 | + - api |
| 47 | + - redis |
215 | 48 |
|
216 | | - # Scraper service (optional runner) |
217 | | - scraper: |
218 | | - build: |
219 | | - context: ./League-Data-Scraping-And-Analytics-master/ProStaff-Scraper |
220 | | - container_name: prostaff-scraper |
221 | | - env_file: |
222 | | - - ./League-Data-Scraping-And-Analytics-master/ProStaff-Scraper/.env |
| 49 | + # --- Banco de Dados (Local na VPS) --- |
| 50 | + postgres: |
| 51 | + image: postgres:15-alpine |
| 52 | + container_name: prostaff-postgres |
| 53 | + restart: always |
| 54 | + environment: |
| 55 | + POSTGRES_DB: ${POSTGRES_DB:-prostaff_production} |
| 56 | + POSTGRES_USER: ${POSTGRES_USER:-postgres} |
| 57 | + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe123!} |
223 | 58 | volumes: |
224 | | - - ./League-Data-Scraping-And-Analytics-master/ProStaff-Scraper:/app |
225 | | - depends_on: |
226 | | - elasticsearch: |
227 | | - condition: service_healthy |
228 | | - command: ["tail", "-f", "/dev/null"] |
229 | | - networks: |
230 | | - - prostaff-net |
231 | | - profiles: |
232 | | - - scraper |
| 59 | + - prostaff_pg_data:/var/lib/postgresql/data |
| 60 | + healthcheck: |
| 61 | + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"] |
| 62 | + interval: 10s |
| 63 | + timeout: 5s |
| 64 | + retries: 5 |
233 | 65 |
|
234 | | - # Backup Service (runs daily) |
235 | | - backup: |
236 | | - image: postgres:15-alpine |
237 | | - container_name: prostaff-backup |
238 | | - restart: "no" |
| 66 | + # --- Cache & Job Queue --- |
| 67 | + redis: |
| 68 | + image: redis:7-alpine |
| 69 | + container_name: prostaff-redis |
| 70 | + restart: always |
| 71 | + volumes: |
| 72 | + - prostaff_redis_data:/data |
| 73 | + healthcheck: |
| 74 | + test: ["CMD", "redis-cli", "ping"] |
| 75 | + interval: 10s |
| 76 | + timeout: 5s |
| 77 | + retries: 5 |
| 78 | + |
| 79 | + # --- Analytics (Memória Reduzida) --- |
| 80 | + elasticsearch: |
| 81 | + image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4 |
| 82 | + container_name: prostaff-elasticsearch |
| 83 | + restart: unless-stopped |
239 | 84 | environment: |
240 | | - PGHOST: postgres |
241 | | - PGDATABASE: ${POSTGRES_DB} |
242 | | - PGUSER: ${POSTGRES_USER} |
243 | | - PGPASSWORD: ${POSTGRES_PASSWORD} |
| 85 | + - discovery.type=single-node |
| 86 | + - xpack.security.enabled=false |
| 87 | + # IMPORTANTE: Reduzido para caber na KVM 1 (4GB total) |
| 88 | + - ES_JAVA_OPTS=-Xms512m -Xmx512m |
244 | 89 | volumes: |
245 | | - - ./backups:/backups |
246 | | - - ./deploy/scripts/backup.sh:/backup.sh:ro |
247 | | - networks: |
248 | | - - prostaff-net |
249 | | - entrypoint: ["/backup.sh"] |
250 | | - profiles: |
251 | | - - backup |
| 90 | + - prostaff_es_data:/usr/share/elasticsearch/data |
| 91 | + healthcheck: |
| 92 | + test: ["CMD-SHELL", "curl -s http://localhost:9200 >/dev/null || exit 1"] |
| 93 | + interval: 30s |
| 94 | + timeout: 10s |
| 95 | + retries: 5 |
252 | 96 |
|
253 | 97 | volumes: |
254 | | - # postgres_data: # DESABILITADO - Usa Supabase PostgreSQL |
255 | | - # driver: local |
256 | | - redis_data: |
257 | | - driver: local |
258 | | - nginx_logs: |
259 | | - driver: local |
260 | | - es_data: |
261 | | - driver: local |
262 | | - |
263 | | -networks: |
264 | | - prostaff-net: |
265 | | - driver: bridge |
266 | | - ipam: |
267 | | - config: |
268 | | - - subnet: 172.20.0.0/16 |
| 98 | + prostaff_pg_data: |
| 99 | + prostaff_redis_data: |
| 100 | + prostaff_es_data: |
0 commit comments