From 829e17ef2bad88fa5d7cf9aac3e189416a5f744e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 8 May 2024 15:19:12 +0200 Subject: [PATCH] Refactor GetContainersStatus.php for improved readability and maintainability --- app/Actions/Docker/GetContainersStatus.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php index a56c20c85..881e7de8d 100644 --- a/app/Actions/Docker/GetContainersStatus.php +++ b/app/Actions/Docker/GetContainersStatus.php @@ -13,6 +13,7 @@ use App\Notifications\Container\ContainerRestarted; use App\Notifications\Container\ContainerStopped; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Log; use Lorisleiva\Actions\Concerns\AsAction; class GetContainersStatus @@ -119,7 +120,6 @@ private function sentinel() } else { $uuid = data_get($labels, 'com.docker.compose.service'); $type = data_get($labels, 'coolify.type'); - if ($uuid) { if ($type === 'service') { $database_id = data_get($labels, 'coolify.service.subId'); @@ -131,9 +131,10 @@ private function sentinel() if ($isPublic) { $foundTcpProxy = $containers->filter(function ($value, $key) use ($uuid) { if ($this->server->isSwarm()) { + // TODO: fix this with sentinel return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid"; } else { - return data_get($value, 'Name') === "/$uuid-proxy"; + return data_get($value, 'name') === "$uuid-proxy"; } })->first(); if (!$foundTcpProxy) { @@ -155,9 +156,10 @@ private function sentinel() if ($isPublic) { $foundTcpProxy = $containers->filter(function ($value, $key) use ($uuid) { if ($this->server->isSwarm()) { + // TODO: fix this with sentinel return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid"; } else { - return data_get($value, 'Name') === "/$uuid-proxy"; + return data_get($value, 'name') === "$uuid-proxy"; } })->first(); if (!$foundTcpProxy) { @@ -170,7 +172,7 @@ private function sentinel() } } } - if (data_get($container, 'Name') === '/coolify-db') { + if (data_get($container, 'name') === 'coolify-db') { $foundDatabases[] = 0; } } @@ -316,9 +318,10 @@ private function sentinel() $this->server->proxyType(); $foundProxyContainer = $containers->filter(function ($value, $key) { if ($this->server->isSwarm()) { + // TODO: fix this with sentinel return data_get($value, 'Spec.Name') === 'coolify-proxy_traefik'; } else { - return data_get($value, 'Name') === '/coolify-proxy'; + return data_get($value, 'name') === 'coolify-proxy'; } })->first(); if (!$foundProxyContainer) { @@ -332,7 +335,7 @@ private function sentinel() ray($e); } } else { - $this->server->proxy->status = data_get($foundProxyContainer, 'State.Status'); + $this->server->proxy->status = data_get($foundProxyContainer, 'state'); $this->server->save(); $connectProxyToDockerNetworks = connectProxyToNetworks($this->server); instant_remote_process($connectProxyToDockerNetworks, $this->server, false); @@ -448,7 +451,7 @@ private function old_way() if ($this->server->isSwarm()) { return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid"; } else { - return data_get($value, 'Name') === "/$uuid-proxy"; + return data_get($value, 'Name') === "$uuid-proxy"; } })->first(); if (!$foundTcpProxy) { @@ -472,7 +475,7 @@ private function old_way() if ($this->server->isSwarm()) { return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid"; } else { - return data_get($value, 'Name') === "/$uuid-proxy"; + return data_get($value, 'Name') === "$uuid-proxy"; } })->first(); if (!$foundTcpProxy) {