Skip to content

Commit 2ee4c32

Browse files
committed
feat: add health checks to docker-compose and remove sleep from pipeline
1 parent 5e634a7 commit 2ee4c32

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

.github/workflows/tests.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ jobs:
5757
- name: Load and Start Services
5858
run: |
5959
docker load --input /tmp/${{ env.IMAGE }}.tar
60-
docker compose up -d
61-
sleep 10
60+
docker compose up -d --wait
6261
6362
- name: Run Unit Tests
6463
run: docker compose exec tests vendor/bin/phpunit /usr/src/code/tests/unit
@@ -101,8 +100,7 @@ jobs:
101100
- name: Load and Start Services
102101
run: |
103102
docker load --input /tmp/${{ env.IMAGE }}.tar
104-
docker compose up -d
105-
sleep 10
103+
docker compose up -d --wait
106104
107105
- name: Run Tests
108106
run: docker compose exec -T tests vendor/bin/phpunit /usr/src/code/tests/e2e/Adapter/${{matrix.adapter}}Test.php --debug

docker-compose.yml

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ services:
1919
- ./docker-compose.yml:/usr/src/code/docker-compose.yml
2020
environment:
2121
PHP_IDE_CONFIG: serverName=tests
22+
depends_on:
23+
- postgres
24+
- postgres-mirror
25+
- mariadb
26+
- mariadb-mirror
27+
- mysql
28+
- mysql-mirror
29+
- redis
30+
- redis-mirror
31+
- mongo
2232

2333
adminer:
2434
image: adminer
@@ -44,6 +54,12 @@ services:
4454
POSTGRES_USER: root
4555
POSTGRES_PASSWORD: password
4656
POSTGRES_DB: root
57+
healthcheck:
58+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
59+
interval: 10s
60+
timeout: 5s
61+
retries: 5
62+
start_period: 5s
4763

4864
postgres-mirror:
4965
build:
@@ -60,6 +76,12 @@ services:
6076
POSTGRES_USER: root
6177
POSTGRES_PASSWORD: password
6278
POSTGRES_DB: root
79+
healthcheck:
80+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
81+
interval: 10s
82+
timeout: 5s
83+
retries: 10
84+
start_period: 5s
6385

6486
mariadb:
6587
image: mariadb:10.11
@@ -71,6 +93,12 @@ services:
7193
- "8703:3306"
7294
environment:
7395
- MYSQL_ROOT_PASSWORD=password
96+
healthcheck:
97+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
98+
start_period: 10s
99+
interval: 10s
100+
timeout: 5s
101+
retries: 3
74102

75103
mariadb-mirror:
76104
image: mariadb:10.11
@@ -82,6 +110,12 @@ services:
82110
- "8704:3306"
83111
environment:
84112
- MYSQL_ROOT_PASSWORD=password
113+
healthcheck:
114+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
115+
start_period: 10s
116+
interval: 10s
117+
timeout: 5s
118+
retries: 3
85119

86120
mongo:
87121
image: mongo:8.0.14
@@ -110,10 +144,10 @@ services:
110144
\" 2>/dev/null || exit 1
111145
fi
112146
"
113-
interval: 10s
147+
interval: 5s
114148
timeout: 10s
115149
retries: 10
116-
start_period: 30s
150+
start_period: 10s
117151

118152
mongo-express:
119153
image: mongo-express
@@ -145,6 +179,12 @@ services:
145179
MYSQL_TCP_PORT: 3307
146180
cap_add:
147181
- SYS_NICE
182+
healthcheck:
183+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u $$MYSQL_USER", "-p $$MYSQL_PASSWORD"]
184+
interval: 10s
185+
timeout: 5s
186+
retries: 5
187+
start_period: 30s
148188

149189
mysql-mirror:
150190
image: mysql:8.0.43
@@ -161,6 +201,12 @@ services:
161201
MYSQL_TCP_PORT: 3307
162202
cap_add:
163203
- SYS_NICE
204+
healthcheck:
205+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u $$MYSQL_USER", "-p $$MYSQL_PASSWORD"]
206+
interval: 10s
207+
timeout: 5s
208+
retries: 5
209+
start_period: 30s
164210

165211
redis:
166212
image: redis:8.2.1-alpine3.22
@@ -169,6 +215,12 @@ services:
169215
- "8708:6379"
170216
networks:
171217
- database
218+
healthcheck:
219+
test: ["CMD", "redis-cli", "ping"]
220+
interval: 10s
221+
timeout: 5s
222+
retries: 5
223+
start_period: 5s
172224

173225
redis-mirror:
174226
image: redis:8.2.1-alpine3.22
@@ -177,6 +229,12 @@ services:
177229
- "8709:6379"
178230
networks:
179231
- database
232+
healthcheck:
233+
test: ["CMD", "redis-cli", "ping"]
234+
interval: 10s
235+
timeout: 5s
236+
retries: 5
237+
start_period: 5s
180238

181239
volumes:
182240
mongo-data:

0 commit comments

Comments
 (0)