-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.prod.yaml
More file actions
275 lines (251 loc) · 9.65 KB
/
Copy pathcompose.prod.yaml
File metadata and controls
275 lines (251 loc) · 9.65 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Production stack for a single Ubuntu VPS.
#
# docker compose -f compose.prod.yaml --env-file .env.production up -d --build
#
# Use infrastructure/production/deploy.sh instead of calling this directly — it
# also runs the migration step, which is not part of container startup.
#
# Differences from the development compose.yaml: the application source is
# baked into the images instead of bind-mounted, Postgres and Redis are on named
# volumes and publish no host ports, and Caddy is the only thing listening on
# the public interface.
name: shopflow_prod
# A VPS disk fills up quietly. Cap every container's logs.
x-logging: &logging
driver: json-file
options:
max-size: "10m"
max-file: "5"
x-admin-image: &admin-image
build:
context: ./admin
dockerfile: docker/Dockerfile.prod
target: app
image: shopflow/admin-app:${IMAGE_TAG:-latest}
env_file: [admin/.env.production]
restart: unless-stopped
logging: *logging
networks: [net]
depends_on:
db: {condition: service_healthy}
redis: {condition: service_healthy}
x-shop-image: &shop-image
build:
context: ./shop
dockerfile: docker/Dockerfile.prod
target: app
image: shopflow/shop-app:${IMAGE_TAG:-latest}
env_file: [shop/.env.production]
restart: unless-stopped
logging: *logging
networks: [net]
depends_on:
db: {condition: service_healthy}
redis: {condition: service_healthy}
services:
# --- shared services ---------------------------------------------------
db:
image: postgres:16-alpine
restart: unless-stopped
logging: *logging
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
# Without this an initdb on a fresh volume uses trust auth.
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 6
start_period: 30s
networks: [net]
redis:
image: redis:7-alpine
restart: unless-stopped
logging: *logging
# The password is read from the environment inside the container rather
# than passed on the command line, where `docker inspect` would show it.
# Kept on one line deliberately: in a YAML folded scalar the flags would
# become separate lines after `exec`, i.e. never run at all.
command: ["sh", "-c", "exec redis-server --appendonly yes --maxmemory-policy noeviction --requirepass \"$$REDIS_PASSWORD\""]
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD}
volumes:
- redisdata:/data
healthcheck:
# Asserts the password is actually enforced. A plain authenticated
# PING is not enough: it also succeeds against a server with no
# password at all, which is the failure this is guarding against.
test:
- CMD-SHELL
- redis-cli ping 2>&1 | grep -q NOAUTH && redis-cli --no-auth-warning -a "$$REDIS_PASSWORD" ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 6
networks: [net]
# --- admin panel -------------------------------------------------------
admin_app:
<<: *admin-image
volumes:
# Uploads are the only state the app writes; everything else in
# storage/ is disposable.
- admin_storage:/var/www/html/storage/app/public
# Log files for the in-panel viewer. Shared with shop_app because
# the panel shows both apps' logs and cannot otherwise see into
# another container. stderr logging is unaffected — the apps write
# to both (LOG_STACK=stderr,shared).
- applogs:/var/log/shopflow
healthcheck:
test: ["CMD-SHELL", "bash -c '</dev/tcp/127.0.0.1/9000'"]
interval: 15s
timeout: 5s
retries: 4
start_period: 40s
admin_web:
build:
context: ./admin
dockerfile: docker/Dockerfile.prod
target: web
image: shopflow/admin-web:${IMAGE_TAG:-latest}
restart: unless-stopped
logging: *logging
volumes:
# public/storage is a symlink into this volume; nginx serves the
# files directly and never needs to write them.
- admin_storage:/var/www/html/storage/app/public:ro
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/up > /dev/null || exit 1"]
interval: 15s
timeout: 5s
retries: 4
start_period: 40s
depends_on:
admin_app: {condition: service_started}
networks: [net]
# --- storefront --------------------------------------------------------
shop_app:
<<: *shop-image
volumes:
# Writes its logs where the admin panel's viewer can read them.
- applogs:/var/log/shopflow
healthcheck:
test: ["CMD-SHELL", "bash -c '</dev/tcp/127.0.0.1/9000'"]
interval: 15s
timeout: 5s
retries: 4
start_period: 40s
shop_web:
build:
context: ./shop
dockerfile: docker/Dockerfile.prod
target: web
image: shopflow/shop-web:${IMAGE_TAG:-latest}
restart: unless-stopped
logging: *logging
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1/up > /dev/null || exit 1"]
interval: 15s
timeout: 5s
retries: 4
start_period: 40s
depends_on:
shop_app: {condition: service_started}
networks: [net]
# Its own container so a crashed renderer restarts instead of silently
# dropping the storefront back to client-side rendering.
shop_ssr:
build:
context: ./shop
dockerfile: docker/Dockerfile.prod
target: ssr
image: shopflow/shop-ssr:${IMAGE_TAG:-latest}
restart: unless-stopped
logging: *logging
healthcheck:
test:
- CMD
- node
- -e
- "require('net').connect(13714,'127.0.0.1').on('connect',()=>process.exit(0)).on('error',()=>process.exit(1))"
interval: 15s
timeout: 5s
retries: 4
start_period: 20s
networks: [net]
# --- observability -----------------------------------------------------
# Feeds Pulse's Servers card (CPU, memory, disk). Every other card is
# recorded by the apps themselves as they serve requests; this one needs a
# process that samples the machine, so without it that card stays empty.
#
# Note: `pulse:trim` prunes old samples and runs from the scheduler, which
# lives behind the `workers` profile. Until that profile is started the
# pulse_* tables only grow — see infrastructure/production/README.md.
pulse:
<<: *admin-image
command: ["php", "artisan", "pulse:check"]
# --- workers -----------------------------------------------------------
# Nothing in the codebase queues a job or registers a scheduled task yet,
# so these stay out of the default `up`. Start them with:
# docker compose -f compose.prod.yaml --profile workers up -d
# and set QUEUE_CONNECTION=redis in the app env files first.
admin_queue:
<<: *admin-image
profiles: [workers]
command: ["php", "artisan", "queue:work", "--tries=3", "--max-time=3600", "--sleep=1"]
admin_scheduler:
<<: *admin-image
profiles: [workers]
command: ["php", "artisan", "schedule:work"]
shop_queue:
<<: *shop-image
profiles: [workers]
command: ["php", "artisan", "queue:work", "--tries=3", "--max-time=3600", "--sleep=1"]
shop_scheduler:
<<: *shop-image
profiles: [workers]
command: ["php", "artisan", "schedule:work"]
# --- edge --------------------------------------------------------------
# The only container with published ports. Caddy terminates TLS and renews
# Let's Encrypt certificates on its own.
proxy:
image: caddy:2-alpine
restart: unless-stopped
logging: *logging
ports:
- "80:80"
- "443:443"
- "443:443/udp"
environment:
SHOP_DOMAIN: ${SHOP_DOMAIN}
ADMIN_DOMAIN: ${ADMIN_DOMAIN}
SHOP_LEGACY_DOMAINS: ${SHOP_LEGACY_DOMAINS:-legacy.invalid}
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-private_ranges}
# A certificate obtained off-box (see infrastructure/production/
# README.md) and mounted below — this host cannot reach Let's
# Encrypt's ACME API to get one on its own.
TLS_CERT_FILE: /etc/caddy/certs/fullchain.pem
TLS_KEY_FILE: /etc/caddy/certs/privkey.pem
volumes:
- ./infrastructure/production/Caddyfile:/etc/caddy/Caddyfile:ro
- ./infrastructure/production/certs:/etc/caddy/certs:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
admin_web: {condition: service_started}
shop_web: {condition: service_started}
networks: [net]
volumes:
pgdata:
redisdata:
admin_storage:
applogs:
caddy_data:
caddy_config:
networks:
net:
driver: bridge