Repository navigation
Expand file tree
/
Copy pathcompose.yaml
More file actions
170 lines (159 loc) · 3.8 KB
/
Copy pathcompose.yaml
File metadata and controls
170 lines (159 loc) · 3.8 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
name: la-fruteria
# Por defecto, Docker no rota la bitácora y puede llenar el disco.
# Con este tope, cada caja guarda a lo sumo 3 archivos de 10 MB.
x-bitacora: &bitacora
driver: json-file
options:
max-size: "10m"
max-file: "3"
# Servicios propios sin privilegios y en solo lectura.
x-endurecido: &endurecido
logging: *bitacora
read_only: true
tmpfs:
- /tmp
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
restart: unless-stopped
x-salud: &salud
interval: 10s
timeout: 3s
retries: 3
start_period: 15s
start_interval: 2s
services:
web:
<<: *endurecido
build: ./web
image: la-fruteria-web
ports:
- "127.0.0.1:8080:8080"
networks:
- frente
depends_on:
api:
condition: service_healthy
healthcheck:
<<: *salud
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:8080/"]
deploy:
resources:
limits:
cpus: "0.25"
memory: 64M
pids: 100
api:
<<: *endurecido
build: ./api
image: la-fruteria-api
environment:
BD_CLAVE_ARCHIVO: /run/secrets/bd_clave
secrets:
- bd_clave
networks:
- frente
- fondo
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
<<: *salud
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:3000/salud/listo').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
deploy:
resources:
limits:
cpus: "0.5"
memory: 256M
pids: 100
despachador:
<<: *endurecido
build: ./api
image: la-fruteria-api
command: ["node", "src/despachador.js"]
environment:
BD_CLAVE_ARCHIVO: /run/secrets/bd_clave
secrets:
- bd_clave
networks:
- fondo
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
<<: *salud
test: ["CMD", "node", "-e", "process.exit(Date.now() - require('node:fs').statSync('/tmp/latido').mtimeMs < 30000 ? 0 : 1)"]
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
pids: 100
postgres:
image: postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873
environment:
POSTGRES_DB: fruteria
POSTGRES_USER: fruteria
POSTGRES_PASSWORD_FILE: /run/secrets/bd_clave
secrets:
- bd_clave
volumes:
- datos-postgres:/var/lib/postgresql
- ./base-de-datos:/docker-entrypoint-initdb.d:ro
networks:
- fondo
# PostgreSQL escribe sus datos en el volumen y su socket en memoria.
read_only: true
tmpfs:
- /tmp
- /var/run/postgresql
security_opt:
- no-new-privileges:true
logging: *bitacora
restart: unless-stopped
healthcheck:
<<: *salud
test: ["CMD", "pg_isready", "-U", "fruteria", "-d", "fruteria"]
deploy:
resources:
limits:
cpus: "1"
memory: 512M
pids: 100
redis:
image: redis:8-alpine@sha256:3811787313eba226a2ef38658c6ccb91cd5e110edc89c37767de373120a0e5a0
command: ["redis-server", "--appendonly", "yes"]
volumes:
- datos-redis:/data
networks:
- fondo
read_only: true
security_opt:
- no-new-privileges:true
logging: *bitacora
restart: unless-stopped
healthcheck:
<<: *salud
test: ["CMD", "redis-cli", "ping"]
deploy:
resources:
limits:
cpus: "0.25"
memory: 128M
pids: 100
networks:
frente: {}
# Sin salida a internet. De las cajas del frente, solo la API entra aquí.
fondo:
internal: true
volumes:
datos-postgres: {}
datos-redis: {}
secrets:
bd_clave:
file: ./secretos/bd_clave.txt