fix: server validation

This commit is contained in:
Andras Bacsai 2024-02-22 11:28:45 +01:00
parent 5179129a6b
commit 4ae2087c2e
4 changed files with 81 additions and 51 deletions

View File

@ -88,7 +88,7 @@ class Form extends Component
} }
public function validateServer($install = true) public function validateServer($install = true)
{ {
$this->dispatch('validateServer', $install); $this->dispatch('init', $install);
} }
public function submit() public function submit()

View File

@ -2,6 +2,7 @@
namespace App\Livewire\Server; namespace App\Livewire\Server;
use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy; use App\Actions\Proxy\StartProxy;
use App\Models\Server; use App\Models\Server;
use Livewire\Component; use Livewire\Component;
@ -10,7 +11,7 @@ class ValidateAndInstall extends Component
{ {
public Server $server; public Server $server;
public int $number_of_tries = 0; public int $number_of_tries = 0;
public int $max_tries = 1; public int $max_tries = 2;
public bool $install = true; public bool $install = true;
public $uptime = null; public $uptime = null;
public $supported_os_type = null; public $supported_os_type = null;
@ -21,7 +22,15 @@ class ValidateAndInstall extends Component
public $error = null; public $error = null;
public bool $ask = false; public bool $ask = false;
protected $listeners = ['validateServer' => 'init', 'validateDockerEngine', 'validateServerNow' => 'validateServer']; protected $listeners = [
'init',
'validateConnection',
'validateOS',
'validateDockerEngine',
'validateDockerVersion',
'startProxy',
'refresh' => '$refresh',
];
public function init(bool $install = true) public function init(bool $install = true)
{ {
@ -35,31 +44,29 @@ class ValidateAndInstall extends Component
$this->error = null; $this->error = null;
$this->number_of_tries = 0; $this->number_of_tries = 0;
if (!$this->ask) { if (!$this->ask) {
$this->dispatch('validateServerNow'); $this->dispatch('validateConnection');
} }
} }
public function startValidatingAfterAsking() { public function startValidatingAfterAsking()
{
$this->ask = false; $this->ask = false;
$this->init(); $this->init();
} }
public function validateServer() public function startProxy()
{ {
try { try {
$this->validateConnection(); $shouldStart = CheckProxy::run($this->server);
$this->validateOS(); if ($shouldStart) {
$this->validateDockerEngine(); $proxy = StartProxy::run($this->server, false);
if ($proxy === 'OK') {
if ($this->server->isSwarm()) { $this->proxy_started = true;
$swarmInstalled = $this->server->validateDockerSwarm(); } else {
if ($swarmInstalled) { throw new \Exception("Proxy could not be started.");
$this->dispatch('success', 'Docker Swarm is initiated.');
} }
} else { } else {
$proxy = StartProxy::run($this->server); $this->proxy_started = true;
if ($proxy) {
$this->proxy_started = true;
}
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
return handleError($e, $this); return handleError($e, $this);
} }
@ -71,6 +78,7 @@ class ValidateAndInstall extends Component
$this->error = 'Server is not reachable. Please validate your configuration and connection.<br><br>Check this <a target="_blank" class="underline" href="https://coolify.io/docs/server/openssh">documentation</a> for further help.'; $this->error = 'Server is not reachable. Please validate your configuration and connection.<br><br>Check this <a target="_blank" class="underline" href="https://coolify.io/docs/server/openssh">documentation</a> for further help.';
return; return;
} }
$this->dispatch('validateOS');
} }
public function validateOS() public function validateOS()
{ {
@ -79,6 +87,7 @@ class ValidateAndInstall extends Component
$this->error = 'Server OS type is not supported. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; $this->error = 'Server OS type is not supported. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
return; return;
} }
$this->dispatch('validateDockerEngine');
} }
public function validateDockerEngine() public function validateDockerEngine()
{ {
@ -90,29 +99,39 @@ class ValidateAndInstall extends Component
$this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; $this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
return; return;
} else { } else {
$activity = $this->server->installDocker(); if ($this->number_of_tries == 0 ) {
$this->number_of_tries++; $activity = $this->server->installDocker();
$this->dispatch('newActivityMonitor', $activity->id, 'validateDockerEngine'); $this->number_of_tries++;
$this->dispatch('newActivityMonitor', $activity->id, 'init');
}
return; return;
} }
} else { } else {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; $this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
return; return;
} }
} else {
$this->validateDockerVersion();
} }
$this->dispatch('validateDockerVersion');
} }
public function validateDockerVersion() public function validateDockerVersion()
{ {
$this->docker_version = $this->server->validateDockerEngineVersion(); if ($this->server->isSwarm()) {
if ($this->docker_version) { $swarmInstalled = $this->server->validateDockerSwarm();
$this->dispatch('serverInstalled'); if ($swarmInstalled) {
$this->dispatch('success', 'Server validated successfully.'); $this->dispatch('success', 'Docker Swarm is initiated.');
}
} else { } else {
$this->error = 'Docker Engine version is not 22+. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; $this->docker_version = $this->server->validateDockerEngineVersion();
return; if ($this->docker_version) {
$this->dispatch('serverInstalled');
$this->dispatch('success', 'Server validated successfully.');
} else {
$this->error = 'Docker Engine version is not 22+. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
return;
}
} }
$this->dispatch('startProxy');
} }
public function render() public function render()
{ {

View File

@ -398,10 +398,10 @@ class Server extends BaseModel
} }
}); });
if ($supported->count() === 1) { if ($supported->count() === 1) {
ray('supported'); // ray('supported');
return str($supported->first()); return str($supported->first());
} else { } else {
ray('not supported'); // ray('not supported');
return false; return false;
} }
} }
@ -468,6 +468,16 @@ class Server extends BaseModel
} }
return false; return false;
} }
try {
$dockerRunning = instant_remote_process(["docker version"], $this);
} catch (\Throwable $e) {
$this->settings->is_usable = false;
$this->settings->save();
if ($throwError) {
throw new \Exception('Server is not usable. Docker Engine is not running.');
}
return false;
}
$this->settings->is_usable = true; $this->settings->is_usable = true;
$this->settings->save(); $this->settings->save();
$this->validateCoolifyNetwork(isSwarm: false, isBuildServer: $this->settings->is_build_server); $this->validateCoolifyNetwork(isSwarm: false, isBuildServer: $this->settings->is_build_server);

View File

@ -3,7 +3,7 @@
This will revalidate the server, install / update Docker Engine, Docker Compose and all related This will revalidate the server, install / update Docker Engine, Docker Compose and all related
configuration. It will also restart Docker Engine, so your running containers will be unreachable configuration. It will also restart Docker Engine, so your running containers will be unreachable
for the time being. for the time being.
<x-forms.button isHighlighted wire:click='startValidatingAfterAsking '>Continue</x-forms.button> <x-forms.button isHighlighted wire:click='startValidatingAfterAsking'>Continue</x-forms.button>
@else @else
@if ($uptime) @if ($uptime)
<div class="flex w-64 gap-2">Server is reachable: <svg class="w-5 h-5 text-success" viewBox="0 0 256 256" <div class="flex w-64 gap-2">Server is reachable: <svg class="w-5 h-5 text-success" viewBox="0 0 256 256"
@ -41,13 +41,13 @@
</svg></div> </svg></div>
@else @else
@if ($error) @if ($error)
<div class="flex w-64 gap-2">Server is reachable: <svg class="w-5 h-5 text-error" <div class="flex w-64 gap-2">Supported OS type: <svg class="w-5 h-5 text-error"
viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"> viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<path fill="currentColor" <path fill="currentColor"
d="M208.49 191.51a12 12 0 0 1-17 17L128 145l-63.51 63.49a12 12 0 0 1-17-17L111 128L47.51 64.49a12 12 0 0 1 17-17L128 111l63.51-63.52a12 12 0 0 1 17 17L145 128Z" /> d="M208.49 191.51a12 12 0 0 1-17 17L128 145l-63.51 63.49a12 12 0 0 1-17-17L111 128L47.51 64.49a12 12 0 0 1 17-17L128 111l63.51-63.52a12 12 0 0 1 17 17L145 128Z" />
</svg></div> </svg></div>
@else @else
<div class="w-64"><x-loading text="Server is reachable:" /></div> <div class="w-64"><x-loading text="Supported OS type:" /></div>
@endif @endif
@endif @endif
@endif @endif
@ -85,8 +85,22 @@
d="m243.28 68.24l-24-23.56a16 16 0 0 0-22.58 0L104 136l-.11-.11l-36.64-35.27a16 16 0 0 0-22.57.06l-24 24a16 16 0 0 0 0 22.61l71.62 72a16 16 0 0 0 22.63 0l128.4-128.38a16 16 0 0 0-.05-22.67M103.62 208L32 136l24-24l.11.11l36.64 35.27a16 16 0 0 0 22.52 0L208.06 56L232 79.6Z" /> d="m243.28 68.24l-24-23.56a16 16 0 0 0-22.58 0L104 136l-.11-.11l-36.64-35.27a16 16 0 0 0-22.57.06l-24 24a16 16 0 0 0 0 22.61l71.62 72a16 16 0 0 0 22.63 0l128.4-128.38a16 16 0 0 0-.05-22.67M103.62 208L32 136l24-24l.11.11l36.64 35.27a16 16 0 0 0 22.52 0L208.06 56L232 79.6Z" />
</g> </g>
</svg></div> </svg></div>
@isset($docker_version)
<div class="flex w-64 gap-2">Minimum Docker version: <svg class="w-5 h-5 text-success"
viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<g fill="currentColor">
<path
d="m237.66 85.26l-128.4 128.4a8 8 0 0 1-11.32 0l-71.6-72a8 8 0 0 1 0-11.31l24-24a8 8 0 0 1 11.32 0l36.68 35.32a8 8 0 0 0 11.32 0l92.68-91.32a8 8 0 0 1 11.32 0l24 23.6a8 8 0 0 1 0 11.31"
opacity=".2" />
<path
d="m243.28 68.24l-24-23.56a16 16 0 0 0-22.58 0L104 136l-.11-.11l-36.64-35.27a16 16 0 0 0-22.57.06l-24 24a16 16 0 0 0 0 22.61l71.62 72a16 16 0 0 0 22.63 0l128.4-128.38a16 16 0 0 0-.05-22.67M103.62 208L32 136l24-24l.11.11l36.64 35.27a16 16 0 0 0 22.52 0L208.06 56L232 79.6Z" />
</g>
</svg></div>
@else
<div class="w-64"><x-loading text="Minimum Docker version:" /></div>
@endisset
@if ($proxy_started) @if ($proxy_started)
<div class="flex w-64 gap-2">Proxy Started: <svg class="w-5 h-5 text-success" viewBox="0 0 256 256" <div class="flex w-64 gap-2">Proxy started: <svg class="w-5 h-5 text-success" viewBox="0 0 256 256"
xmlns="http://www.w3.org/2000/svg"> xmlns="http://www.w3.org/2000/svg">
<g fill="currentColor"> <g fill="currentColor">
<path <path
@ -98,13 +112,13 @@
</svg></div> </svg></div>
@else @else
@if ($error) @if ($error)
<div class="flex w-64 gap-2">Proxy Started: <svg class="w-5 h-5 text-error" <div class="flex w-64 gap-2">Proxy started: <svg class="w-5 h-5 text-error"
viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"> viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<path fill="currentColor" <path fill="currentColor"
d="M208.49 191.51a12 12 0 0 1-17 17L128 145l-63.51 63.49a12 12 0 0 1-17-17L111 128L47.51 64.49a12 12 0 0 1 17-17L128 111l63.51-63.52a12 12 0 0 1 17 17L145 128Z" /> d="M208.49 191.51a12 12 0 0 1-17 17L128 145l-63.51 63.49a12 12 0 0 1-17-17L111 128L47.51 64.49a12 12 0 0 1 17-17L128 111l63.51-63.52a12 12 0 0 1 17 17L145 128Z" />
</svg></div> </svg></div>
@else @else
<div class="w-64"><x-loading text="Proxy Started:" /></div> <div class="w-64"><x-loading text="Proxy started:" /></div>
@endif @endif
@endif @endif
@else @else
@ -120,20 +134,7 @@
@endif @endif
@endif @endif
@isset($docker_version) <livewire:new-activity-monitor header="Docker Installation Logs" />
<div class="flex w-64 gap-2">Minimum Docker version installed: <svg class="w-5 h-5 text-success"
viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<g fill="currentColor">
<path
d="m237.66 85.26l-128.4 128.4a8 8 0 0 1-11.32 0l-71.6-72a8 8 0 0 1 0-11.31l24-24a8 8 0 0 1 11.32 0l36.68 35.32a8 8 0 0 0 11.32 0l92.68-91.32a8 8 0 0 1 11.32 0l24 23.6a8 8 0 0 1 0 11.31"
opacity=".2" />
<path
d="m243.28 68.24l-24-23.56a16 16 0 0 0-22.58 0L104 136l-.11-.11l-36.64-35.27a16 16 0 0 0-22.57.06l-24 24a16 16 0 0 0 0 22.61l71.62 72a16 16 0 0 0 22.63 0l128.4-128.38a16 16 0 0 0-.05-22.67M103.62 208L32 136l24-24l.11.11l36.64 35.27a16 16 0 0 0 22.52 0L208.06 56L232 79.6Z" />
</g>
</svg></div>
@endisset
<livewire:new-activity-monitor header="Logs" />
@isset($error) @isset($error)
<pre class="font-bold whitespace-pre-line text-error">{!! $error !!}</pre> <pre class="font-bold whitespace-pre-line text-error">{!! $error !!}</pre>
@endisset @endisset