forked from GeovaneSchmitz/sigaa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-stack.yml
More file actions
155 lines (134 loc) · 8.31 KB
/
Copy pathdocker-stack.yml
File metadata and controls
155 lines (134 loc) · 8.31 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
version: "3.9"
# ─────────────────────────────────────────────────────────────────────────────
# SIGAA API — Docker Swarm Stack com Traefik
# Deploy: docker stack deploy -c docker-stack.yml sigaa
# Domínio: sigaa-api.meudominio.com.br
# SSL: Let's Encrypt automático via certresolver=letsencrypt
# ─────────────────────────────────────────────────────────────────────────────
services:
sigaa-api:
image: justbrunasso/sigaa-api:latest
deploy:
# ── Réplicas e política de atualização ────────────────────────────────
replicas: 1 # 1 réplica por padrão (Chromium é pesado)
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
update_config:
parallelism: 1 # atualiza 1 réplica por vez
delay: 15s
failure_action: rollback # reverte automaticamente em falha
monitor: 30s
max_failure_ratio: 0
order: start-first # sobe novo container antes de matar o velho
rollback_config:
parallelism: 1
delay: 10s
failure_action: pause
monitor: 30s
resources:
limits:
cpus: "2.0"
memory: 2G # ~400MB/sessão Chromium; 5 sessões = ~2GB
reservations:
cpus: "0.5"
memory: 512M
placement:
constraints:
- "node.role == worker" # rode em workers, não no manager
# - "node.labels.sigaa == true" # descomente para fixar em nó específico
# ── Labels do Traefik (DEVEM ficar dentro de deploy em Swarm mode) ─────
labels:
# Habilita o Traefik para este serviço
- "traefik.enable=true"
# Indica ao Traefik qual rede usar para alcançar o container
- "traefik.docker.network=network_public"
# ── Router HTTPS ────────────────────────────────────────────────────
- "traefik.http.routers.sigaa-api.rule=Host(`sigaa-api.meudominio.com.br`)"
- "traefik.http.routers.sigaa-api.entrypoints=websecure"
- "traefik.http.routers.sigaa-api.tls=true"
- "traefik.http.routers.sigaa-api.tls.certresolver=letsencrypt"
# ── Router HTTP → redireciona para HTTPS automaticamente ─────────────
- "traefik.http.routers.sigaa-api-http.rule=Host(`sigaa-api.meudominio.com.br`)"
- "traefik.http.routers.sigaa-api-http.entrypoints=web"
- "traefik.http.routers.sigaa-api-http.middlewares=redirect-to-https@docker"
# ── Middleware de redirecionamento HTTP → HTTPS ───────────────────────
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.permanent=true"
# ── Service: porta interna do container ───────────────────────────────
- "traefik.http.services.sigaa-api.loadbalancer.server.port=3000"
# ── Healthcheck do loadbalancer via /status ───────────────────────────
- "traefik.http.services.sigaa-api.loadbalancer.healthcheck.path=/status"
- "traefik.http.services.sigaa-api.loadbalancer.healthcheck.interval=30s"
- "traefik.http.services.sigaa-api.loadbalancer.healthcheck.timeout=10s"
# ── Variáveis de ambiente ────────────────────────────────────────────────
environment:
- NODE_ENV=production
- PORT=3000
- DISPLAY=:99
- PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
- PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
- MAX_SESSIONS=5
- SESSION_TIMEOUT_MIN=15
# ── Segredos (alternativa segura a variáveis plaintext) ──────────────────
# secrets:
# - sigaa_credentials # descomente se usar docker secret
# ── Portas ───────────────────────────────────────────────────────────────
# Com Traefik NÃO publicamos a porta diretamente no host.
# O Traefik roteia o tráfego internamente pela rede network_public.
# Descomente apenas para debug local sem Traefik:
# ports:
# - target: 3000
# published: 3000
# protocol: tcp
# mode: ingress
# ── Volumes ─────────────────────────────────────────────────────────────
volumes:
- sigaa-tmp:/tmp # tmp compartilhado entre reinicializações
# - /etc/localtime:/etc/localtime:ro # sincroniza timezone com o host
# ── Healthcheck do container (Docker nativo) ─────────────────────────────
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
# ── Redes ────────────────────────────────────────────────────────────────
# network_public: rede externa onde o Traefik opera (já existente no Swarm)
# sigaa-net: rede interna isolada para comunicação entre serviços futuros
networks:
- network_public
- sigaa-net
# ── Logging ──────────────────────────────────────────────────────────────
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
# ─────────────────────────────────────────────────────────────────────────────
# Volumes
# ─────────────────────────────────────────────────────────────────────────────
volumes:
sigaa-tmp:
driver: local
# ─────────────────────────────────────────────────────────────────────────────
# Redes
# ─────────────────────────────────────────────────────────────────────────────
networks:
# Rede externa do Traefik — deve existir antes do deploy
# Se ainda não existir, crie com:
# docker network create --driver overlay --attachable network_public
network_public:
external: true
# Rede interna isolada do stack
sigaa-net:
driver: overlay
attachable: true
# ─────────────────────────────────────────────────────────────────────────────
# Segredos (descomente se necessário)
# ─────────────────────────────────────────────────────────────────────────────
# secrets:
# sigaa_credentials:
# external: true # crie com: docker secret create sigaa_credentials -