From ba40f93386f5430ac98422ce4293b43952eb05e8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 8 May 2024 20:59:58 +0200 Subject: [PATCH] do not use sentinel for container details for now --- app/Actions/Docker/GetContainersStatus.php | 44 +++++++++---------- app/Models/Server.php | 38 ++++++++++++++-- docker-compose.dev.yml | 6 --- .../views/livewire/server/resources.blade.php | 4 +- 4 files changed, 58 insertions(+), 34 deletions(-) diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php index 881e7de8d..f2715fe85 100644 --- a/app/Actions/Docker/GetContainersStatus.php +++ b/app/Actions/Docker/GetContainersStatus.php @@ -45,36 +45,34 @@ public function handle(Server $server) $this->applications = $this->applications->filter(function ($value, $key) use ($skip_these_applications) { return !$skip_these_applications->pluck('id')->contains($value->id); }); - if ($this->server->isSwarm()) { - $this->old_way(); - } else { - if (!$this->server->is_metrics_enabled) { - $this->old_way(); - return; - } - $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this->server, false); - $sentinel_found = json_decode($sentinel_found, true); - $status = data_get($sentinel_found, '0.State.Status', 'exited'); - if ($status === 'running') { - ray('Checking with Sentinel'); - $this->sentinel(); - } else { - ray('Checking the Old way'); - $this->old_way(); - } - } + $this->old_way(); + // if ($this->server->isSwarm()) { + // $this->old_way(); + // } else { + // if (!$this->server->is_metrics_enabled) { + // $this->old_way(); + // return; + // } + // $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this->server, false); + // $sentinel_found = json_decode($sentinel_found, true); + // $status = data_get($sentinel_found, '0.State.Status', 'exited'); + // if ($status === 'running') { + // ray('Checking with Sentinel'); + // $this->sentinel(); + // } else { + // ray('Checking the Old way'); + // $this->old_way(); + // } + // } } private function sentinel() { try { - $containers = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/containers"'], $this->server, false); - if (is_null($containers)) { + $containers = $this->server->getContainers(); + if ($containers->count() === 0) { return; } - $containers = data_get(json_decode($containers, true), 'containers', []); - $containers = collect($containers); - $databases = $this->server->databases(); $services = $this->server->services()->get(); $previews = $this->server->previews(); diff --git a/app/Models/Server.php b/app/Models/Server.php index 16659e2b8..4d201bba3 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -5,10 +5,12 @@ use App\Actions\Server\InstallDocker; use App\Actions\Server\StartSentinel; use App\Enums\ProxyTypes; +use App\Jobs\PullSentinelImageJob; use App\Notifications\Server\Revived; use App\Notifications\Server\Unreachable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; @@ -463,7 +465,8 @@ public function forceDisableServer() Storage::disk('ssh-keys')->delete($sshKeyFileLocation); Storage::disk('ssh-mux')->delete($this->muxFilename()); } - public function checkSentinel() { + public function checkSentinel() + { ray("Checking sentinel on server: {$this->name}"); if ($this->is_metrics_enabled) { $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this, false); @@ -471,7 +474,7 @@ public function checkSentinel() { $status = data_get($sentinel_found, '0.State.Status', 'exited'); if ($status !== 'running') { ray('Sentinel is not running, starting it...'); - StartSentinel::dispatch($this); + PullSentinelImageJob::dispatch($this); } else { ray('Sentinel is running'); } @@ -563,7 +566,36 @@ public function startUnmanaged($id) { return instant_remote_process(["docker start $id"], $this); } - public function loadUnmanagedContainers() + public function getContainers(): Collection + { + $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this, false); + $sentinel_found = json_decode($sentinel_found, true); + $status = data_get($sentinel_found, '0.State.Status', 'exited'); + if ($status === 'running') { + $containers = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/containers"'], $this, false); + if (is_null($containers)) { + return collect([]); + } + $containers = data_get(json_decode($containers, true), 'containers', []); + return collect($containers); + } else { + if ($this->isSwarm()) { + $containers = instant_remote_process(["docker service inspect $(docker service ls -q) --format '{{json .}}'"], $this, false); + } else { + $containers = instant_remote_process(["docker container ls -q"], $this, false); + if (!$containers) { + return collect([]); + } + $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this, false); + } + if (is_null($containers)) { + return collect([]); + } + + return format_docker_command_output_to_json($containers); + } + } + public function loadUnmanagedContainers(): Collection { if ($this->isFunctional()) { $containers = instant_remote_process(["docker ps -a --format '{{json .}}'"], $this); diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 2594822ce..91e90b989 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -19,12 +19,6 @@ services: PUSHER_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}" volumes: - .:/var/www/html/:cached - sentinel: - ports: - - "127.0.0.1:8888:8888" - volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - - .:/var/www/html/:cached postgres: pull_policy: always ports: diff --git a/resources/views/livewire/server/resources.blade.php b/resources/views/livewire/server/resources.blade.php index a5ff69ea1..29648cafe 100644 --- a/resources/views/livewire/server/resources.blade.php +++ b/resources/views/livewire/server/resources.blade.php @@ -1,7 +1,7 @@
-
-
+