From afe8fc05ea8a83f0300018189ce7072a1a507825 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:16:22 +0100 Subject: [PATCH] fix(healthcheck): keep the Dockerfile HEALTHCHECK of existing applications Co-Authored-By: Claude Opus 5.5 --- ..._healthcheck_for_existing_applications.php | 25 +++++++ .../project/shared/health-checks.blade.php | 13 +++- ...KeepDockerfileHealthcheckMigrationTest.php | 69 +++++++++++++++++++ 3 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2026_10_28_124421_keep_dockerfile_healthcheck_for_existing_applications.php create mode 100644 tests/Feature/KeepDockerfileHealthcheckMigrationTest.php diff --git a/database/migrations/2026_10_28_124421_keep_dockerfile_healthcheck_for_existing_applications.php b/database/migrations/2026_10_28_124421_keep_dockerfile_healthcheck_for_existing_applications.php new file mode 100644 index 0000000000..e9c3d8f13b --- /dev/null +++ b/database/migrations/2026_10_28_124421_keep_dockerfile_healthcheck_for_existing_applications.php @@ -0,0 +1,25 @@ +where('custom_healthcheck_found', true) + ->where('health_check_enabled', true) + ->update(['health_check_enabled' => false]); + } + + public function down(): void + { + // This data migration cannot identify which applications had the Coolify healthcheck enabled. + } +}; diff --git a/resources/views/livewire/project/shared/health-checks.blade.php b/resources/views/livewire/project/shared/health-checks.blade.php index 6b02c0bf31..0a0cba98d1 100644 --- a/resources/views/livewire/project/shared/health-checks.blade.php +++ b/resources/views/livewire/project/shared/health-checks.blade.php @@ -26,9 +26,16 @@ @if ($customHealthcheckFound)
- - Enabling this configuration replaces the custom healthcheck currently defined by the application. - + @if ($healthCheckEnabled) + + This healthcheck replaces the HEALTHCHECK from the Dockerfile. Disable it to use the + Dockerfile HEALTHCHECK again. + + @else + + The application uses the HEALTHCHECK from its Dockerfile. Enabling this healthcheck replaces it. + + @endif
@endif diff --git a/tests/Feature/KeepDockerfileHealthcheckMigrationTest.php b/tests/Feature/KeepDockerfileHealthcheckMigrationTest.php new file mode 100644 index 0000000000..d994272c16 --- /dev/null +++ b/tests/Feature/KeepDockerfileHealthcheckMigrationTest.php @@ -0,0 +1,69 @@ + 0]); + + $team = Team::factory()->create(); + $this->healthcheckMigrationOwner = User::factory()->create(); + $team->members()->attach($this->healthcheckMigrationOwner->id, ['role' => 'owner']); + $project = Project::factory()->create(['team_id' => $team->id]); + $server = Server::factory()->create(['team_id' => $team->id]); + $this->healthcheckMigrationEnvironment = $project->environments()->firstOrFail(); + $this->healthcheckMigrationDestination = StandaloneDocker::query()->where('server_id', $server->id)->firstOrFail(); +}); + +function keepDockerfileHealthcheckApplication(bool $healthCheckEnabled, bool $customHealthcheckFound): Application +{ + return Application::factory()->create([ + 'environment_id' => test()->healthcheckMigrationEnvironment->id, + 'destination_id' => test()->healthcheckMigrationDestination->id, + 'destination_type' => StandaloneDocker::class, + 'build_pack' => 'dockerfile', + 'health_check_enabled' => $healthCheckEnabled, + 'custom_healthcheck_found' => $customHealthcheckFound, + ])->fresh(); +} + +test('disables the Coolify healthcheck only for applications with a Dockerfile HEALTHCHECK', function () { + $dockerfileAndCoolify = keepDockerfileHealthcheckApplication(healthCheckEnabled: true, customHealthcheckFound: true); + $dockerfileOnly = keepDockerfileHealthcheckApplication(healthCheckEnabled: false, customHealthcheckFound: true); + $coolifyOnly = keepDockerfileHealthcheckApplication(healthCheckEnabled: true, customHealthcheckFound: false); + $none = keepDockerfileHealthcheckApplication(healthCheckEnabled: false, customHealthcheckFound: false); + + (require database_path('migrations/2026_10_28_124421_keep_dockerfile_healthcheck_for_existing_applications.php'))->up(); + + expect($dockerfileAndCoolify->fresh()->health_check_enabled)->toBeFalse() + ->and($dockerfileAndCoolify->fresh()->custom_healthcheck_found)->toBeTrue() + ->and($dockerfileOnly->fresh()->health_check_enabled)->toBeFalse() + ->and($coolifyOnly->fresh()->health_check_enabled)->toBeTrue() + ->and($none->fresh()->health_check_enabled)->toBeFalse(); +}); + +test('the healthcheck page says whether the Dockerfile HEALTHCHECK is in use or replaced', function () { + $this->actingAs($this->healthcheckMigrationOwner); + + Livewire::test(HealthChecks::class, ['resource' => keepDockerfileHealthcheckApplication(healthCheckEnabled: false, customHealthcheckFound: true)]) + ->assertSee('Dockerfile HEALTHCHECK in use') + ->assertDontSee('Dockerfile HEALTHCHECK replaced'); + + Livewire::test(HealthChecks::class, ['resource' => keepDockerfileHealthcheckApplication(healthCheckEnabled: true, customHealthcheckFound: true)]) + ->assertSee('Dockerfile HEALTHCHECK replaced') + ->assertDontSee('Dockerfile HEALTHCHECK in use'); + + Livewire::test(HealthChecks::class, ['resource' => keepDockerfileHealthcheckApplication(healthCheckEnabled: true, customHealthcheckFound: false)]) + ->assertDontSee('Dockerfile HEALTHCHECK'); +});