1
0
Fork 0

build: add service healthchecks

This commit is contained in:
thibaud-leclere 2026-05-05 11:54:59 +02:00
parent 3b322c9ee0
commit 645d8af22d
2 changed files with 59 additions and 1 deletions

View file

@ -13,6 +13,12 @@ services:
volumes:
- app-data:/app/var/data
- app-cache:/app/var/bootstrap-cache
healthcheck:
test: ["CMD-SHELL", "php -r 'exit(@fsockopen(\"127.0.0.1\", 9000) ? 0 : 1);'"]
interval: 10s
timeout: 3s
retries: 3
start_period: 20s
nginx:
build:
@ -20,9 +26,16 @@ services:
dockerfile: docker/Dockerfile
target: web
depends_on:
- app
app:
condition: service_healthy
ports:
- "${HTTP_PORT:-8080}:80"
healthcheck:
test: ["CMD-SHELL", "wget -q --spider http://127.0.0.1/ || exit 1"]
interval: 10s
timeout: 3s
retries: 3
start_period: 20s
volumes:
app-data:

View file

@ -0,0 +1,45 @@
<?php
namespace App\Tests\Docker;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;
final class ComposeHealthcheckTest extends TestCase
{
public function testServicesDeclareHealthchecks(): void
{
$compose = Yaml::parseFile(__DIR__.'/../../compose.yaml');
self::assertSame(
[
'CMD-SHELL',
'php -r \'exit(@fsockopen("127.0.0.1", 9000) ? 0 : 1);\'',
],
$compose['services']['app']['healthcheck']['test'] ?? null
);
self::assertSame('10s', $compose['services']['app']['healthcheck']['interval'] ?? null);
self::assertSame('3s', $compose['services']['app']['healthcheck']['timeout'] ?? null);
self::assertSame(3, $compose['services']['app']['healthcheck']['retries'] ?? null);
self::assertSame('20s', $compose['services']['app']['healthcheck']['start_period'] ?? null);
self::assertSame(
['CMD-SHELL', 'wget -q --spider http://127.0.0.1/ || exit 1'],
$compose['services']['nginx']['healthcheck']['test'] ?? null
);
self::assertSame('10s', $compose['services']['nginx']['healthcheck']['interval'] ?? null);
self::assertSame('3s', $compose['services']['nginx']['healthcheck']['timeout'] ?? null);
self::assertSame(3, $compose['services']['nginx']['healthcheck']['retries'] ?? null);
self::assertSame('20s', $compose['services']['nginx']['healthcheck']['start_period'] ?? null);
}
public function testNginxWaitsForHealthyApp(): void
{
$compose = Yaml::parseFile(__DIR__.'/../../compose.yaml');
self::assertSame(
['app' => ['condition' => 'service_healthy']],
$compose['services']['nginx']['depends_on'] ?? null
);
}
}