diff --git a/app/Http/Livewire/Project/Shared/HealthChecks.php b/app/Http/Livewire/Project/Shared/HealthChecks.php new file mode 100644 index 000000000..62a0d8dc0 --- /dev/null +++ b/app/Http/Livewire/Project/Shared/HealthChecks.php @@ -0,0 +1,39 @@ + 'string', + 'resource.health_check_port' => 'nullable|string', + 'resource.health_check_host' => 'string', + 'resource.health_check_method' => 'string', + 'resource.health_check_return_code' => 'integer', + 'resource.health_check_scheme' => 'string', + 'resource.health_check_response_text' => 'nullable|string', + 'resource.health_check_interval' => 'integer', + 'resource.health_check_timeout' => 'integer', + 'resource.health_check_retries' => 'integer', + 'resource.health_check_start_period' => 'integer', + + ]; + public function submit() + { + try { + $this->validate(); + $this->resource->save(); + $this->emit('saved'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.project.shared.health-checks'); + } +} diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index ea8b43de2..f48c8cd1b 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -37,6 +37,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted private int $application_deployment_queue_id; + private bool $newVersionIsHealthy = false; private ApplicationDeploymentQueue $application_deployment_queue; private Application $application; private string $deployment_uuid; @@ -315,7 +316,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ], ); if (Str::of($this->saved_outputs->get('health_check'))->contains('healthy')) { + $this->newVersionIsHealthy = true; $this->execute_remote_command( + [ + "echo 'New version of your application is healthy.'" + ], [ "echo 'Rolling update completed.'" ], @@ -524,7 +529,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted 'restart' => RESTART_MODE, 'environment' => $environment_variables, 'labels' => generateLabelsApplication($this->application, $this->preview), - 'expose' => $ports, + // 'expose' => $ports, 'networks' => [ $this->destination->network, ], @@ -632,15 +637,17 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted return 'exit 0'; } if (!$this->application->health_check_port) { - $this->application->health_check_port = $this->application->ports_exposes_array[0]; + $health_check_port = $this->application->ports_exposes_array[0]; + } else { + $health_check_port = $this->application->health_check_port; } if ($this->application->health_check_path) { $generated_healthchecks_commands = [ - "curl -s -X {$this->application->health_check_method} -f {$this->application->health_check_scheme}://{$this->application->health_check_host}:{$this->application->health_check_port}{$this->application->health_check_path} > /dev/null" + "curl -s -X {$this->application->health_check_method} -f {$this->application->health_check_scheme}://{$this->application->health_check_host}:{$health_check_port}{$this->application->health_check_path} > /dev/null" ]; } else { $generated_healthchecks_commands = [ - "curl -s -X {$this->application->health_check_method} -f {$this->application->health_check_scheme}://{$this->application->health_check_host}:{$this->application->health_check_port}/" + "curl -s -X {$this->application->health_check_method} -f {$this->application->health_check_scheme}://{$this->application->health_check_host}:{$health_check_port}/" ]; } return implode(' ', $generated_healthchecks_commands); @@ -700,10 +707,17 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); private function stop_running_container() { if ($this->currently_running_container_name) { - $this->execute_remote_command( - ["echo -n 'Removing old version of your application.'"], - [executeInDocker($this->deployment_uuid, "docker rm -f $this->currently_running_container_name >/dev/null 2>&1"), "hidden" => true], - ); + if ($this->newVersionIsHealthy) { + $this->execute_remote_command( + ["echo -n 'Removing old version of your application.'"], + [executeInDocker($this->deployment_uuid, "docker rm -f $this->currently_running_container_name >/dev/null 2>&1"), "hidden" => true], + ); + } else { + $this->execute_remote_command( + ["echo -n 'New version is not healthy, rolling back to the old version.'"], + [executeInDocker($this->deployment_uuid, "docker rm -f $this->container_name >/dev/null 2>&1"), "hidden" => true], + ); + } } } diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 5b0ca1683..a351050d2 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -99,6 +99,8 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted foreach ($containers as $container) { $containerStatus = data_get($container, 'State.Status'); + $containerHealth = data_get($container, 'State.Health.Status','unhealthy'); + $containerStatus = "$containerStatus ($containerHealth)"; $labels = data_get($container, 'Config.Labels'); $labels = Arr::undot(format_docker_labels_to_json($labels)); $labelId = data_get($labels, 'coolify.applicationId'); @@ -145,6 +147,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted } $serviceLabelId = data_get($labels, 'coolify.serviceId'); if ($serviceLabelId) { + ray('Service label id: ' . $serviceLabelId); $coolifyName = data_get($labels, 'coolify.name'); $serviceName = Str::of($coolifyName)->before('-'); $serviceUuid = Str::of($coolifyName)->after('-'); diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php index d7275b2f6..6faaf348b 100644 --- a/bootstrap/helpers/services.php +++ b/bootstrap/helpers/services.php @@ -1,6 +1,7 @@ applications; $databases = $service->databases; foreach ($applications as $application) { - if ($application->status === 'running') { + if (Str::of($application->status)->startsWith('running')) { $foundRunning = true; } else { $isDegraded = true; } } foreach ($databases as $database) { - if ($database->status === 'running') { + if (Str::of($database->status)->startsWith('running')) { $foundRunning = true; } else { $isDegraded = true; diff --git a/resources/views/components/status/degraded.blade.php b/resources/views/components/status/degraded.blade.php index 2220a6d0e..2351ab683 100644 --- a/resources/views/components/status/degraded.blade.php +++ b/resources/views/components/status/degraded.blade.php @@ -1,8 +1,8 @@ @props([ - 'text' => 'Degraded', + 'status' => 'Degraded', ])
-
{{ $text }}
+
{{ Str::headline($status) }}
diff --git a/resources/views/components/status/index.blade.php b/resources/views/components/status/index.blade.php index 7848cee02..67fef1282 100644 --- a/resources/views/components/status/index.blade.php +++ b/resources/views/components/status/index.blade.php @@ -1,7 +1,7 @@ -@if ($status === 'running') - -@elseif($status === 'restarting') - +@if (Str::of($status)->startsWith('running')) + +@elseif(Str::of($status)->startsWith('restarting')) + @else - + @endif diff --git a/resources/views/components/status/restarting.blade.php b/resources/views/components/status/restarting.blade.php index 0cea8fd69..a9cb6a2b3 100644 --- a/resources/views/components/status/restarting.blade.php +++ b/resources/views/components/status/restarting.blade.php @@ -1,8 +1,8 @@ @props([ - 'text' => 'Restarting', + 'status' => 'Restarting', ])
-
{{ $text }}
+
{{ Str::headline($status) }}
diff --git a/resources/views/components/status/running.blade.php b/resources/views/components/status/running.blade.php index f3c059e01..5fffde9c0 100644 --- a/resources/views/components/status/running.blade.php +++ b/resources/views/components/status/running.blade.php @@ -1,8 +1,8 @@ @props([ - 'text' => 'Running', + 'status' => 'Running', ])
-
{{ $text }}
+
{{ Str::headline($status) }}
diff --git a/resources/views/components/status/services.blade.php b/resources/views/components/status/services.blade.php index bafa2954e..71ea08411 100644 --- a/resources/views/components/status/services.blade.php +++ b/resources/views/components/status/services.blade.php @@ -1,9 +1,9 @@ -@if ($complexStatus === 'running') - -@elseif($complexStatus === 'restarting') - -@elseif($complexStatus === 'degraded') - +@if (Str::of($complexStatus)->startsWith('running')) + +@elseif(Str::of($complexStatus)->startsWith('restarting')) + +@elseif(Str::of($complexStatus)->startsWith('degraded')) + @else - + @endif diff --git a/resources/views/components/status/stopped.blade.php b/resources/views/components/status/stopped.blade.php index 9867e22a1..de94fa074 100644 --- a/resources/views/components/status/stopped.blade.php +++ b/resources/views/components/status/stopped.blade.php @@ -1,8 +1,8 @@ @props([ - 'text' => 'Stopped', + 'status' => 'Stopped', ])
-
{{ $text }}
+
{{ Str::headline($status) }}
diff --git a/resources/views/livewire/project/application/previews.blade.php b/resources/views/livewire/project/application/previews.blade.php index 554e6606e..1c455b983 100644 --- a/resources/views/livewire/project/application/previews.blade.php +++ b/resources/views/livewire/project/application/previews.blade.php @@ -53,12 +53,12 @@ @foreach ($application->previews as $preview)