-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.api-test.yml
More file actions
124 lines (116 loc) · 3.65 KB
/
Copy pathdocker-compose.api-test.yml
File metadata and controls
124 lines (116 loc) · 3.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
# Docker Compose for running the k6 API test suite against a live backend.
#
# Usage:
# docker compose -f docker-compose.api-test.yml up \
# --exit-code-from k6 --abort-on-container-exit
#
# The k6 container exits with code 0 on success, non-zero on failure.
# MySQL data is ephemeral (no named volume) so the schema is always fresh.
version: "3.8"
services:
# ---------------------------------------------------------------------------
# MySQL – schema is initialised from migration SQL + test seed data.
# No persistent volume: each run starts with a clean database.
# ---------------------------------------------------------------------------
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: miniapp
volumes:
- ./migrations/000001_init_schema.up.sql:/docker-entrypoint-initdb.d/01_schema.sql:ro
- ./tests/api/seed.sql:/docker-entrypoint-initdb.d/02_seed.sql:ro
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-u", "root", "-psecret"]
interval: 5s
timeout: 3s
retries: 20
networks:
- api-test-network
redis:
image: redis:7-alpine
command: ["redis-server", "--save", "", "--appendonly", "no"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 20
networks:
- api-test-network
cos:
build:
context: .
dockerfile: tests/mock-server/cos/Dockerfile
environment:
COS_PORT: 9000
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:9000/health"]
interval: 5s
timeout: 3s
retries: 20
networks:
- api-test-network
# ---------------------------------------------------------------------------
# Backend application
# ---------------------------------------------------------------------------
app:
build:
context: .
dockerfile: Dockerfile
environment:
APP_SERVER_PORT: 8080
APP_SERVER_MODE: debug
APP_DATABASE_HOST: mysql
APP_DATABASE_PORT: 3306
APP_DATABASE_USER: root
APP_DATABASE_PASSWORD: secret
APP_DATABASE_NAME: miniapp
APP_JWT_SECRET: test-jwt-secret-for-api-tests
APP_JWT_EXPIRY: 7200
APP_LOG_LEVEL: debug
APP_WECHAT_APP_ID: test-wechat-app-id
APP_WECHAT_APP_SECRET: test-wechat-app-secret
APP_UPLOAD_DIR: storage/uploads
APP_UPLOAD_BASE_URL: http://cos:9000
APP_UPLOAD_PROVIDER: cos
APP_UPLOAD_COS_ENDPOINT: http://cos:9000
APP_UPLOAD_COS_BUCKET: miniapp-test
APP_REDIS_HOST: redis
APP_REDIS_PORT: 6379
APP_RATE_LIMIT_ENABLED: "true"
APP_RATE_LIMIT_REQUESTS: 5000
APP_RATE_LIMIT_WINDOW_SECONDS: 60
APP_DEBUG_ENABLE_TEST_TOKEN: "true"
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080/health"]
interval: 5s
timeout: 3s
start_period: 10s
retries: 12
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
cos:
condition: service_healthy
networks:
- api-test-network
# ---------------------------------------------------------------------------
# k6 – runs the API test suite and exits with its result code.
# ---------------------------------------------------------------------------
k6:
image: grafana/k6:latest
volumes:
- ./tests/api:/scripts:ro
command: run /scripts/api_test.js
environment:
BASE_URL: "http://app:8080"
depends_on:
app:
condition: service_healthy
networks:
- api-test-network
networks:
api-test-network:
driver: bridge