do not use sentinel for container details for now

This commit is contained in:
Andras Bacsai 2024-05-08 20:59:58 +02:00
parent 781bf52a8e
commit ba40f93386
4 changed files with 58 additions and 34 deletions

View File

@ -45,36 +45,34 @@ class GetContainersStatus
$this->applications = $this->applications->filter(function ($value, $key) use ($skip_these_applications) { $this->applications = $this->applications->filter(function ($value, $key) use ($skip_these_applications) {
return !$skip_these_applications->pluck('id')->contains($value->id); return !$skip_these_applications->pluck('id')->contains($value->id);
}); });
if ($this->server->isSwarm()) { $this->old_way();
$this->old_way(); // if ($this->server->isSwarm()) {
} else { // $this->old_way();
if (!$this->server->is_metrics_enabled) { // } else {
$this->old_way(); // if (!$this->server->is_metrics_enabled) {
return; // $this->old_way();
} // return;
$sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this->server, false); // }
$sentinel_found = json_decode($sentinel_found, true); // $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this->server, false);
$status = data_get($sentinel_found, '0.State.Status', 'exited'); // $sentinel_found = json_decode($sentinel_found, true);
if ($status === 'running') { // $status = data_get($sentinel_found, '0.State.Status', 'exited');
ray('Checking with Sentinel'); // if ($status === 'running') {
$this->sentinel(); // ray('Checking with Sentinel');
} else { // $this->sentinel();
ray('Checking the Old way'); // } else {
$this->old_way(); // ray('Checking the Old way');
} // $this->old_way();
} // }
// }
} }
private function sentinel() private function sentinel()
{ {
try { try {
$containers = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/containers"'], $this->server, false); $containers = $this->server->getContainers();
if (is_null($containers)) { if ($containers->count() === 0) {
return; return;
} }
$containers = data_get(json_decode($containers, true), 'containers', []);
$containers = collect($containers);
$databases = $this->server->databases(); $databases = $this->server->databases();
$services = $this->server->services()->get(); $services = $this->server->services()->get();
$previews = $this->server->previews(); $previews = $this->server->previews();

View File

@ -5,10 +5,12 @@ namespace App\Models;
use App\Actions\Server\InstallDocker; use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel; use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes; use App\Enums\ProxyTypes;
use App\Jobs\PullSentinelImageJob;
use App\Notifications\Server\Revived; use App\Notifications\Server\Revived;
use App\Notifications\Server\Unreachable; use App\Notifications\Server\Unreachable;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
@ -463,7 +465,8 @@ $schema://$host {
Storage::disk('ssh-keys')->delete($sshKeyFileLocation); Storage::disk('ssh-keys')->delete($sshKeyFileLocation);
Storage::disk('ssh-mux')->delete($this->muxFilename()); Storage::disk('ssh-mux')->delete($this->muxFilename());
} }
public function checkSentinel() { public function checkSentinel()
{
ray("Checking sentinel on server: {$this->name}"); ray("Checking sentinel on server: {$this->name}");
if ($this->is_metrics_enabled) { if ($this->is_metrics_enabled) {
$sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this, false); $sentinel_found = instant_remote_process(["docker inspect coolify-sentinel"], $this, false);
@ -471,7 +474,7 @@ $schema://$host {
$status = data_get($sentinel_found, '0.State.Status', 'exited'); $status = data_get($sentinel_found, '0.State.Status', 'exited');
if ($status !== 'running') { if ($status !== 'running') {
ray('Sentinel is not running, starting it...'); ray('Sentinel is not running, starting it...');
StartSentinel::dispatch($this); PullSentinelImageJob::dispatch($this);
} else { } else {
ray('Sentinel is running'); ray('Sentinel is running');
} }
@ -563,7 +566,36 @@ $schema://$host {
{ {
return instant_remote_process(["docker start $id"], $this); 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()) { if ($this->isFunctional()) {
$containers = instant_remote_process(["docker ps -a --format '{{json .}}'"], $this); $containers = instant_remote_process(["docker ps -a --format '{{json .}}'"], $this);

View File

@ -19,12 +19,6 @@ services:
PUSHER_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}" PUSHER_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}"
volumes: volumes:
- .:/var/www/html/:cached - .:/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: postgres:
pull_policy: always pull_policy: always
ports: ports:

View File

@ -1,7 +1,7 @@
<div> <div>
<x-server.navbar :server="$server" :parameters="$parameters" /> <x-server.navbar :server="$server" :parameters="$parameters" />
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'managed' }" class="flex h-full flex-col md:flex-row gap-8"> <div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'managed' }" class="flex flex-col h-full gap-8 md:flex-row">
<div class="flex md:flex-col gap-4 flex-row"> <div class="flex flex-row gap-4 md:flex-col">
<a :class="activeTab === 'managed' && 'dark:text-white'" <a :class="activeTab === 'managed' && 'dark:text-white'"
@click.prevent="activeTab = 'managed'; window.location.hash = 'managed'" href="#">Managed</a> @click.prevent="activeTab = 'managed'; window.location.hash = 'managed'" href="#">Managed</a>
<a :class="activeTab === 'unmanaged' && 'dark:text-white'" <a :class="activeTab === 'unmanaged' && 'dark:text-white'"