-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.test.yaml
More file actions
247 lines (238 loc) · 7.97 KB
/
Copy pathdocker-compose.test.yaml
File metadata and controls
247 lines (238 loc) · 7.97 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
# =============================================================================
# Notetify — test stack
# -----------------------------------------------------------------------------
# Ephemeral environment for running PHPUnit/Pest and Cypress against a clean
# Postgres + Redis. Designed to be brought up, run a test suite, and torn
# down. Data lives in tmpfs (RAM) — every `up` starts from a blank schema.
#
# Bring up: docker compose -p notetify-test -f docker-compose.test.yaml up -d --build
# Run backend tests: docker compose -p notetify-test -f docker-compose.test.yaml run --rm test
# Run e2e tests: docker compose -p notetify-test -f docker-compose.test.yaml --profile e2e up
# Tear down: docker compose -p notetify-test -f docker-compose.test.yaml down -v
#
# Notes:
# - Always pass `-p notetify-test` so this stack doesn't collide with dev's
# containers, networks, or volumes when both are running.
# - Ports are offset by +1 (5433/6380/8001/3001) for the same reason.
# - No Mailpit — Laravel uses MAIL_MAILER=array in tests (mails are
# captured in memory and asserted via Mail::fake() / assertSent()).
# - No Pulse, RustFS, Seq — none are needed for unit/feature
# tests. Add them only if a specific test exercises them.
# =============================================================================
services:
# ---------------------------------------------------------------------------
# db — Postgres 18.1 (tmpfs)
# Throwaway test database. Data is in RAM via tmpfs so each `up` is clean
# and migrations run fast. Database name: notetify_test.
# ---------------------------------------------------------------------------
db:
image: postgres:18.1-alpine
container_name: notetify-db-test
networks:
- notetify-net
restart: "no"
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-postgres}", "-d", "${POSTGRES_DB:-notetify_test}"]
interval: 5s
timeout: 3s
retries: 10
start_period: 5s
user: postgres
tmpfs:
- /var/lib/postgresql/data
environment:
- POSTGRES_DB=notetify_test
- POSTGRES_USER=${DB_USERNAME:-postgres}
- POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}
ports:
- "5433:5432"
deploy:
resources:
limits:
cpus: "1.0"
memory: 512m
# ---------------------------------------------------------------------------
# redis — Redis 8 (no persistence)
# Cache + session backend for tests. Persistence disabled, runs on a
# separate logical DB (15) to keep test state isolated.
# ---------------------------------------------------------------------------
redis:
image: redis:8.0.1-alpine
container_name: notetify-redis-test
networks:
- notetify-net
restart: "no"
command: ["redis-server", "--save", "", "--appendonly", "no"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
start_period: 3s
ports:
- "6380:6379"
deploy:
resources:
limits:
cpus: "0.25"
memory: 128m
# ---------------------------------------------------------------------------
# api — Laravel API booted in testing mode
# Same image as dev. APP_ENV=testing flips Laravel into the test config:
# MAIL_MAILER=array, CACHE_STORE=array, etc. Used both as the target for
# feature tests run inside the container and as the backend for Cypress.
# ---------------------------------------------------------------------------
api:
build:
context: ./api
dockerfile: docker/Dockerfile
target: development
container_name: notetify-api-test
networks:
- notetify-net
restart: "no"
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80/api/up"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
ports:
- "8001:80"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
environment:
- APP_ENV=testing
- APP_DEBUG=true
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=notetify_test
- DB_USERNAME=${DB_USERNAME:-postgres}
- DB_PASSWORD=${DB_PASSWORD:-postgres}
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_DB=15
- CACHE_STORE=array
- SESSION_DRIVER=array
- QUEUE_CONNECTION=sync
- MAIL_MAILER=array
- FILESYSTEM_DISK=local
- TELESCOPE_ENABLED=false
- PULSE_ENABLED=false
volumes:
- ./api:/app
- api_vendor:/app/vendor
deploy:
resources:
limits:
cpus: "2.0"
memory: 1g
# ---------------------------------------------------------------------------
# test — one-shot PHPUnit/Pest runner
# Runs `php artisan test` once and exits. Use:
# docker compose -p notetify-test -f docker-compose.test.yaml run --rm test
# Reuses the api image. Does NOT start automatically with `up` — must be
# invoked via `run`. Inherits env from api so DB/redis/queue match.
# ---------------------------------------------------------------------------
test:
build:
context: ./api
dockerfile: docker/Dockerfile
target: development
container_name: notetify-test-runner
networks:
- notetify-net
profiles:
- tools
command: ["php", "artisan", "test", "--parallel"]
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
environment:
- APP_ENV=testing
- DB_HOST=db
- DB_PORT=5432
- DB_DATABASE=notetify_test
- DB_USERNAME=${DB_USERNAME:-postgres}
- DB_PASSWORD=${DB_PASSWORD:-postgres}
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_DB=15
- CACHE_STORE=array
- SESSION_DRIVER=array
- QUEUE_CONNECTION=sync
- MAIL_MAILER=array
- FILESYSTEM_DISK=local
volumes:
- ./api:/app
- api_vendor:/app/vendor
# ---------------------------------------------------------------------------
# client — Vite SPA (e2e profile only)
# Only started for end-to-end tests. Backend-only test runs skip this to
# save resources. Activate with `--profile e2e`.
# ---------------------------------------------------------------------------
client:
build:
context: ./client
dockerfile: docker/Dockerfile
target: development
args:
- VITE_BASE_URL=http://localhost:8001/api/
- VITE_WS_ORIGIN=ws://localhost:8001
- VITE_APP_NAME=Notetify
- VITE_CLIENT_URL=http://localhost:3001/
container_name: notetify-client-test
networks:
- notetify-net
profiles:
- e2e
restart: "no"
command: ["pnpm", "test"]
ports:
- "3001:3000"
depends_on:
api:
condition: service_healthy
volumes:
- ./client:/app
- node_modules:/app/node_modules
environment:
- VITE_BASE_URL=http://localhost:8001/api/
- VITE_WS_ORIGIN=ws://localhost:8001
- VITE_APP_NAME=Notetify
- VITE_CLIENT_URL=http://localhost:3001/
# ---------------------------------------------------------------------------
# cypress — headless e2e runner (e2e profile only)
# Runs the Cypress suite against the test client. Exits when the suite
# finishes. Activate with `--profile e2e`.
# ---------------------------------------------------------------------------
cypress:
image: cypress/included:13.13.0
container_name: notetify-cypress
networks:
- notetify-net
profiles:
- e2e
depends_on:
client:
condition: service_started
api:
condition: service_healthy
working_dir: /e2e
environment:
- CYPRESS_baseUrl=http://client:3000
volumes:
- ./client:/e2e
networks:
notetify-net:
driver: bridge
# Note: vendor volume is the only persistent piece — caches composer install
# between runs so `up` is fast. Everything else is tmpfs or unmounted.
volumes:
api_vendor:
node_modules: