Skip to content

Commit 97f046e

Browse files
MCLOUD-5856: Added the Healthcheck for DB and redis (#203)
1 parent 1b95ace commit 97f046e

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

src/Compose/BuilderInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface BuilderInterface
3333
public const SERVICE_NODE = 'node';
3434
public const SERVICE_CRON = 'cron';
3535
public const SERVICE_TEST = 'test';
36+
public const SERVICE_HEALTHCHECK = 'healthcheck';
3637

3738
public const NETWORK_MAGENTO = 'magento';
3839
public const NETWORK_MAGENTO_BUILD = 'magento-build';

src/Compose/ProductionBuilder.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class ProductionBuilder implements BuilderInterface
3232
*/
3333
private static $cliDepends = [
3434
self::SERVICE_DB => [
35-
'condition' => 'service_started'
35+
'condition' => 'service_healthy'
3636
],
3737
self::SERVICE_REDIS => [
38-
'condition' => 'service_started'
38+
'condition' => 'service_healthy'
3939
],
4040
self::SERVICE_ELASTICSEARCH => [
4141
'condition' => 'service_healthy'
@@ -231,6 +231,13 @@ public function build(Config $config): Manager
231231
(string)$config->getServiceVersion($service),
232232
self::SERVICE_ELASTICSEARCH === $service && !empty($esEnvVars)
233233
? ['environment' => $esEnvVars]
234+
: self::SERVICE_REDIS === $service
235+
? [self::SERVICE_HEALTHCHECK => [
236+
'test'=> 'redis-cli ping || exit 1',
237+
'interval'=> '30s',
238+
'timeout'=> '30s',
239+
'retries'=> 3
240+
] ]
234241
: []
235242
),
236243
[self::NETWORK_MAGENTO],
@@ -255,7 +262,7 @@ public function build(Config $config): Manager
255262
self::SERVICE_FPM,
256263
$this->serviceFactory->create(ServiceInterface::SERVICE_PHP_FPM, $phpVersion, ['volumes' => $volumesRo]),
257264
[self::NETWORK_MAGENTO],
258-
[self::SERVICE_DB => []]
265+
[self::SERVICE_DB => ['condition' => 'service_healthy']]
259266
);
260267
$manager->addService(
261268
self::SERVICE_WEB,
@@ -524,6 +531,12 @@ private function addDbService(
524531
$dbConfig = [
525532
'ports' => [$port ? "$port:3306" : '3306'],
526533
'volumes' => $mounts,
534+
self::SERVICE_HEALTHCHECK => [
535+
'test'=> 'mysqladmin ping -h localhost',
536+
'interval'=> '30s',
537+
'timeout'=> '30s',
538+
'retries'=> 3
539+
],
527540
];
528541

529542
if ($commands) {

src/Test/Integration/_files/cloud_base/docker-compose.exp.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ services:
1515
- 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1616
- 'mymagento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
18+
healthcheck:
19+
test: 'mysqladmin ping -h localhost'
20+
interval: 30s
21+
timeout: 30s
22+
retries: 3
1823
networks:
1924
magento:
2025
aliases:
@@ -26,6 +31,11 @@ services:
2631
- /data
2732
ports:
2833
- 6379
34+
healthcheck:
35+
test: 'redis-cli ping || exit 1'
36+
interval: 30s
37+
timeout: 30s
38+
retries: 3
2939
networks:
3040
magento:
3141
aliases:
@@ -56,7 +66,7 @@ services:
5666
- fpm.magento2.docker
5767
depends_on:
5868
db:
59-
condition: service_started
69+
condition: service_healthy
6070
web:
6171
hostname: web.magento2.docker
6272
image: 'magento/magento-cloud-docker-nginx:latest-1.1'
@@ -129,9 +139,9 @@ services:
129139
- build.magento2.docker
130140
depends_on:
131141
db:
132-
condition: service_started
142+
condition: service_healthy
133143
redis:
134-
condition: service_started
144+
condition: service_healthy
135145
elasticsearch:
136146
condition: service_healthy
137147
deploy:
@@ -153,9 +163,9 @@ services:
153163
- deploy.magento2.docker
154164
depends_on:
155165
db:
156-
condition: service_started
166+
condition: service_healthy
157167
redis:
158-
condition: service_started
168+
condition: service_healthy
159169
elasticsearch:
160170
condition: service_healthy
161171
volumes:

src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ services:
1515
- 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1616
- 'mymagento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
18+
healthcheck:
19+
test: 'mysqladmin ping -h localhost'
20+
interval: 30s
21+
timeout: 30s
22+
retries: 3
1823
command: '--auto_increment_increment=3 --auto_increment_offset=2'
1924
networks:
2025
magento:
@@ -27,6 +32,11 @@ services:
2732
- /data
2833
ports:
2934
- 6379
35+
healthcheck:
36+
test: 'redis-cli ping || exit 1'
37+
interval: 30s
38+
timeout: 30s
39+
retries: 3
3040
networks:
3141
magento:
3242
aliases:
@@ -51,7 +61,7 @@ services:
5161
- fpm.magento2.docker
5262
depends_on:
5363
db:
54-
condition: service_started
64+
condition: service_healthy
5565
web:
5666
hostname: web.magento2.docker
5767
image: 'magento/magento-cloud-docker-nginx:latest-1.1'
@@ -138,9 +148,9 @@ services:
138148
- test.magento2.docker
139149
depends_on:
140150
db:
141-
condition: service_started
151+
condition: service_healthy
142152
redis:
143-
condition: service_started
153+
condition: service_healthy
144154
fpm_xdebug:
145155
hostname: fpm_xdebug.magento2.docker
146156
image: 'magento/magento-cloud-docker-php:7.3-fpm-1.1'
@@ -187,9 +197,9 @@ services:
187197
- build.magento2.docker
188198
depends_on:
189199
db:
190-
condition: service_started
200+
condition: service_healthy
191201
redis:
192-
condition: service_started
202+
condition: service_healthy
193203
deploy:
194204
hostname: deploy.magento2.docker
195205
image: 'magento/magento-cloud-docker-php:7.3-cli-1.1'
@@ -210,9 +220,9 @@ services:
210220
- deploy.magento2.docker
211221
depends_on:
212222
db:
213-
condition: service_started
223+
condition: service_healthy
214224
redis:
215-
condition: service_started
225+
condition: service_healthy
216226
cron:
217227
hostname: cron.magento2.docker
218228
image: 'magento/magento-cloud-docker-php:7.3-cli-1.1'
@@ -236,9 +246,9 @@ services:
236246
- cron.magento2.docker
237247
depends_on:
238248
db:
239-
condition: service_started
249+
condition: service_healthy
240250
redis:
241-
condition: service_started
251+
condition: service_healthy
242252
volumes:
243253
magento:
244254
driver_opts:

src/Test/Integration/_files/custom_cloud_base/docker-compose.exp.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ services:
1515
- 'magento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1616
- 'magento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
18+
healthcheck:
19+
test: 'mysqladmin ping -h localhost'
20+
interval: 30s
21+
timeout: 30s
22+
retries: 3
1823
command: '--auto_increment_increment=3 --auto_increment_offset=2'
1924
networks:
2025
magento:
@@ -39,7 +44,7 @@ services:
3944
- fpm.magento2.test
4045
depends_on:
4146
db:
42-
condition: service_started
47+
condition: service_healthy
4348
web:
4449
hostname: web.magento2.test
4550
image: 'magento/magento-cloud-docker-nginx:latest-1.1'
@@ -112,7 +117,7 @@ services:
112117
- build.magento2.test
113118
depends_on:
114119
db:
115-
condition: service_started
120+
condition: service_healthy
116121
deploy:
117122
hostname: deploy.magento2.test
118123
image: 'magento/magento-cloud-docker-php:7.2-cli-1.1'
@@ -132,7 +137,7 @@ services:
132137
- deploy.magento2.test
133138
depends_on:
134139
db:
135-
condition: service_started
140+
condition: service_healthy
136141
volumes:
137142
magento:
138143
driver_opts:

0 commit comments

Comments
 (0)