diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index cdb00c0a2..9794610fe 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -15,6 +15,7 @@ class Form extends Component public $dockerVersion; public string|null $wildcard_domain = null; public int $cleanup_after_percentage; + public bool $dockerInstallationStarted = false; protected $rules = [ 'server.name' => 'required|min:6', @@ -44,6 +45,7 @@ public function mount() public function installDocker() { + $this->dockerInstallationStarted = true; $activity = resolve(InstallDocker::class)($this->server); $this->emit('newMonitorActivity', $activity->id); } @@ -56,7 +58,10 @@ public function validateServer() $this->uptime = $uptime; $this->emit('success', 'Server is reachable.'); } else { + ray($this->uptime); + $this->emit('error', 'Server is not reachable.'); + return; } if ($dockerVersion) { diff --git a/app/Http/Livewire/Server/Proxy/Status.php b/app/Http/Livewire/Server/Proxy/Status.php index f808fdb81..061728049 100644 --- a/app/Http/Livewire/Server/Proxy/Status.php +++ b/app/Http/Livewire/Server/Proxy/Status.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\Server\Proxy; +use App\Jobs\ContainerStatusJob; use App\Models\Server; use Livewire\Component; @@ -18,9 +19,7 @@ public function getProxyStatus() { try { if ($this->server->isFunctional()) { - $container = getContainerStatus(server: $this->server, container_id: 'coolify-proxy'); - $this->server->proxy->status = $container; - $this->server->save(); + dispatch_sync(new ContainerStatusJob($this->server)); $this->emit('proxyStatusUpdated'); } } catch (\Throwable $e) { diff --git a/app/Http/Livewire/Server/ShowPrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php index c9054f7df..a0aa6e1e2 100644 --- a/app/Http/Livewire/Server/ShowPrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -37,14 +37,27 @@ public function checkConnection() try { ['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server, true); if ($uptime) { + $this->server->settings->update([ + 'is_reachable' => true + ]); $this->emit('success', 'Server is reachable with this private key.'); } else { + $this->server->settings->update([ + 'is_reachable' => false, + 'is_usable' => false + ]); $this->emit('error', 'Server is not reachable with this private key.'); return; } if ($dockerVersion) { + $this->server->settings->update([ + 'is_usable' => true + ]); $this->emit('success', 'Server is usable for Coolify.'); } else { + $this->server->settings->update([ + 'is_usable' => false + ]); $this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.'); } } catch (\Throwable $e) { diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 6d5feb5ce..1cfcdd18a 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -51,7 +51,7 @@ public function handle(): void try { // ray()->clearAll(); $serverUptimeCheckNumber = 0; - $serverUptimeCheckNumberMax = 5; + $serverUptimeCheckNumberMax = 3; while (true) { if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) { $this->server->settings()->update(['is_reachable' => false]); @@ -65,6 +65,10 @@ public function handle(): void $serverUptimeCheckNumber++; sleep(5); } + $containers = instant_remote_process(["docker container ls -q"], $this->server); + if (!$containers) { + return; + } $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this->server); $containers = format_docker_command_output_to_json($containers); $applications = $this->server->applications(); diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index ae16c7bc0..7017ead10 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -7,15 +7,13 @@ use App\Models\ApplicationDeploymentQueue; use App\Models\PrivateKey; use App\Models\Server; -use App\Notifications\Server\NotReachable; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Sleep; -use Spatie\Activitylog\Models\Activity; use Illuminate\Support\Str; +use Spatie\Activitylog\Contracts\Activity; function remote_process( array $command, @@ -110,11 +108,28 @@ function instant_remote_process(array $command, Server $server, $throwError = tr if (!$throwError) { return null; } - throw new \RuntimeException($process->errorOutput(), $exitCode); + return excludeCertainErrors($process->errorOutput(), $exitCode); } return $output; } - +function excludeCertainErrors(string $errorOutput, ?int $exitCode = null) { + $ignoredErrors = collect([ + 'Permission denied (publickey', + 'Could not resolve hostname', + ]); + $ignored = false; + foreach ($ignoredErrors as $ignoredError) { + if (Str::contains($errorOutput, $ignoredError)) { + $ignored = true; + break; + } + } + if ($ignored) { + // TODO: Create new exception and disable in sentry + throw new \RuntimeException($errorOutput, $exitCode); + } + throw new \RuntimeException($errorOutput, $exitCode); +} function decode_remote_command_output(?ApplicationDeploymentQueue $application_deployment_queue = null): Collection { $application = Application::find(data_get($application_deployment_queue, 'application_id')); diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index 5aaafead1..baac76ea4 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -1,5 +1,5 @@
- +

Server

@if ($server->settings->is_reachable) diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index ebb40f78f..4f3df85c2 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -48,10 +48,16 @@ @endif @if ($server->settings->is_reachable && !$server->settings->is_usable && $server->id !== 0) - - Install Docker Engine 24.0 - + @if ($dockerInstallationStarted) + + Validate Server + + @else + + Install Docker Engine 24.0 + + @endif @endif @if ($server->isFunctional())

Settings

diff --git a/resources/views/livewire/server/proxy/status.blade.php b/resources/views/livewire/server/proxy/status.blade.php index db496f561..a8eca1a2b 100644 --- a/resources/views/livewire/server/proxy/status.blade.php +++ b/resources/views/livewire/server/proxy/status.blade.php @@ -1,4 +1,3 @@ -
@if ($server->proxy->status === 'running') @@ -7,7 +6,8 @@ @else @endif -