Skip to content

Commit fbe23a3

Browse files
authored
Merge pull request #767 from utopia-php/task/improvements-to-docker-compose-and-pipeline
feat: add health checks to docker-compose and remove sleep from pipeline
2 parents e2248ed + c8de1a2 commit fbe23a3

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 5 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,9 +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
109-

docker-compose.yml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ 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+
condition: service_healthy
25+
postgres-mirror:
26+
condition: service_healthy
27+
mariadb:
28+
condition: service_healthy
29+
mariadb-mirror:
30+
condition: service_healthy
31+
mysql:
32+
condition: service_healthy
33+
mysql-mirror:
34+
condition: service_healthy
35+
redis:
36+
condition: service_healthy
37+
redis-mirror:
38+
condition: service_healthy
39+
mongo:
40+
condition: service_healthy
2241

2342
adminer:
2443
image: adminer
@@ -44,6 +63,12 @@ services:
4463
POSTGRES_USER: root
4564
POSTGRES_PASSWORD: password
4665
POSTGRES_DB: root
66+
healthcheck:
67+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
68+
interval: 10s
69+
timeout: 5s
70+
retries: 5
71+
start_period: 5s
4772

4873
postgres-mirror:
4974
build:
@@ -60,6 +85,12 @@ services:
6085
POSTGRES_USER: root
6186
POSTGRES_PASSWORD: password
6287
POSTGRES_DB: root
88+
healthcheck:
89+
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
90+
interval: 10s
91+
timeout: 5s
92+
retries: 10
93+
start_period: 5s
6394

6495
mariadb:
6596
image: mariadb:10.11
@@ -71,6 +102,12 @@ services:
71102
- "8703:3306"
72103
environment:
73104
- MYSQL_ROOT_PASSWORD=password
105+
healthcheck:
106+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
107+
start_period: 10s
108+
interval: 10s
109+
timeout: 5s
110+
retries: 3
74111

75112
mariadb-mirror:
76113
image: mariadb:10.11
@@ -82,6 +119,12 @@ services:
82119
- "8704:3306"
83120
environment:
84121
- MYSQL_ROOT_PASSWORD=password
122+
healthcheck:
123+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
124+
start_period: 10s
125+
interval: 10s
126+
timeout: 5s
127+
retries: 3
85128

86129
mongo:
87130
image: mongo:8.0.14
@@ -110,10 +153,10 @@ services:
110153
\" 2>/dev/null || exit 1
111154
fi
112155
"
113-
interval: 10s
156+
interval: 5s
114157
timeout: 10s
115158
retries: 10
116-
start_period: 30s
159+
start_period: 10s
117160

118161
mongo-express:
119162
image: mongo-express
@@ -145,6 +188,12 @@ services:
145188
MYSQL_TCP_PORT: 3307
146189
cap_add:
147190
- SYS_NICE
191+
healthcheck:
192+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u $$MYSQL_USER", "-p $$MYSQL_PASSWORD"]
193+
interval: 10s
194+
timeout: 5s
195+
retries: 5
196+
start_period: 30s
148197

149198
mysql-mirror:
150199
image: mysql:8.0.43
@@ -161,6 +210,12 @@ services:
161210
MYSQL_TCP_PORT: 3307
162211
cap_add:
163212
- SYS_NICE
213+
healthcheck:
214+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u $$MYSQL_USER", "-p $$MYSQL_PASSWORD"]
215+
interval: 10s
216+
timeout: 5s
217+
retries: 5
218+
start_period: 30s
164219

165220
redis:
166221
image: redis:8.2.1-alpine3.22
@@ -169,6 +224,12 @@ services:
169224
- "8708:6379"
170225
networks:
171226
- database
227+
healthcheck:
228+
test: ["CMD", "redis-cli", "ping"]
229+
interval: 10s
230+
timeout: 5s
231+
retries: 5
232+
start_period: 5s
172233

173234
redis-mirror:
174235
image: redis:8.2.1-alpine3.22
@@ -177,6 +238,12 @@ services:
177238
- "8709:6379"
178239
networks:
179240
- database
241+
healthcheck:
242+
test: ["CMD", "redis-cli", "ping"]
243+
interval: 10s
244+
timeout: 5s
245+
retries: 5
246+
start_period: 5s
180247

181248
volumes:
182249
mongo-data:

0 commit comments

Comments
 (0)