From ebd8e2ce40ab15456c37cf1392ba61b29f87f72b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 9 Oct 2023 15:08:28 +0200 Subject: [PATCH] fix: check connection --- .../Livewire/Project/Application/Heading.php | 12 +++++----- app/Http/Livewire/Project/Shared/Danger.php | 4 +++- app/Http/Livewire/Server/PrivateKey/Show.php | 2 +- app/Http/Livewire/Server/ShowPrivateKey.php | 22 +++---------------- app/Models/Application.php | 12 +++++----- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/app/Http/Livewire/Project/Application/Heading.php b/app/Http/Livewire/Project/Application/Heading.php index fabc43aca..bf4c96cdd 100644 --- a/app/Http/Livewire/Project/Application/Heading.php +++ b/app/Http/Livewire/Project/Application/Heading.php @@ -21,11 +21,13 @@ public function mount() public function check_status() { - dispatch(new ContainerStatusJob($this->application->destination->server)); - $this->application->refresh(); - $this->application->previews->each(function ($preview) { - $preview->refresh(); - }); + if ($this->application->destination->server->isFunctional()) { + dispatch(new ContainerStatusJob($this->application->destination->server)); + $this->application->refresh(); + $this->application->previews->each(function ($preview) { + $preview->refresh(); + }); + } } public function force_deploy_without_cache() diff --git a/app/Http/Livewire/Project/Shared/Danger.php b/app/Http/Livewire/Project/Shared/Danger.php index b3288fe60..7b6dcab3b 100644 --- a/app/Http/Livewire/Project/Shared/Danger.php +++ b/app/Http/Livewire/Project/Shared/Danger.php @@ -31,7 +31,9 @@ public function delete() $destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first(); $server = $destination->server; } - instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server); + if ($this->resource->destination->server->isFunctional()) { + instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server); + } } $this->resource->delete(); return redirect()->route('project.resources', [ diff --git a/app/Http/Livewire/Server/PrivateKey/Show.php b/app/Http/Livewire/Server/PrivateKey/Show.php index 51c91350e..22c52218a 100644 --- a/app/Http/Livewire/Server/PrivateKey/Show.php +++ b/app/Http/Livewire/Server/PrivateKey/Show.php @@ -15,7 +15,7 @@ public function mount() { $this->parameters = get_route_parameters(); try { - $this->server = Server::ownedByCurrentTeam(['name', 'proxy'])->whereUuid(request()->server_uuid)->first(); + $this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first(); if (is_null($this->server)) { return redirect()->route('server.all'); } diff --git a/app/Http/Livewire/Server/ShowPrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php index 1974226fc..98035fa7c 100644 --- a/app/Http/Livewire/Server/ShowPrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -32,34 +32,18 @@ public function setPrivateKey($newPrivateKeyId) } } - public function checkConnection($install = false) + public function checkConnection() { try { $uptime = $this->server->validateConnection(); if ($uptime) { - $install && $this->emit('success', 'Server is reachable.'); + $this->emit('success', 'Server is reachable.'); } else { - $install && $this->emit('error', 'Server is not reachable. Please check your connection and private key configuration.'); - return; - } - $dockerInstalled = $this->server->validateDockerEngine(); - if ($dockerInstalled) { - $install && $this->emit('success', 'Docker Engine is installed.
Checking version.'); - } else { - $install && $this->installDocker(); - return; - } - $dockerVersion = $this->server->validateDockerEngineVersion(); - if ($dockerVersion) { - $install && $this->emit('success', 'Docker Engine version is 23+.'); - } else { - $install && $this->installDocker(); + $this->emit('error', 'Server is not reachable. Please check your connection and private key configuration.'); return; } } catch (\Throwable $e) { return handleError($e, $this); - } finally { - $this->emit('proxyStatusUpdated'); } } diff --git a/app/Models/Application.php b/app/Models/Application.php index 69f4abe22..32eb227ca 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -33,11 +33,13 @@ protected static function booted() }); static::deleting(function ($application) { // Stop Container - instant_remote_process( - ["docker rm -f {$application->uuid}"], - $application->destination->server, - false - ); + if ($application->destination->server->isFunctional()) { + instant_remote_process( + ["docker rm -f {$application->uuid}"], + $application->destination->server, + false + ); + } $application->settings()->delete(); $storages = $application->persistentStorages()->get(); foreach ($storages as $storage) {