coolify/app/Livewire/Server/ValidateAndInstall.php

168 lines
5.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Server;
use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
class ValidateAndInstall extends Component
{
use AuthorizesRequests;
public Server $server;
2024-06-10 20:43:34 +00:00
public int $number_of_tries = 0;
2024-06-10 20:43:34 +00:00
2024-04-16 13:42:38 +00:00
public int $max_tries = 3;
2024-06-10 20:43:34 +00:00
public bool $install = true;
2024-06-10 20:43:34 +00:00
public $uptime = null;
2024-06-10 20:43:34 +00:00
public $supported_os_type = null;
2024-06-10 20:43:34 +00:00
public $docker_installed = null;
2024-06-10 20:43:34 +00:00
public $docker_compose_installed = null;
2024-06-10 20:43:34 +00:00
public $docker_version = null;
2024-06-10 20:43:34 +00:00
public $error = null;
2024-06-10 20:43:34 +00:00
public bool $ask = false;
2024-02-22 10:28:45 +00:00
protected $listeners = [
'init',
'validateConnection',
'validateOS',
'validateDockerEngine',
'validateDockerVersion',
'refresh' => '$refresh',
];
2024-04-16 13:42:38 +00:00
public function init(int $data = 0)
{
$this->uptime = null;
$this->supported_os_type = null;
$this->docker_installed = null;
$this->docker_version = null;
$this->docker_compose_installed = null;
$this->error = null;
2024-04-16 13:42:38 +00:00
$this->number_of_tries = $data;
2024-06-10 20:43:34 +00:00
if (! $this->ask) {
2024-02-22 10:28:45 +00:00
$this->dispatch('validateConnection');
}
}
2024-06-10 20:43:34 +00:00
2024-02-22 10:28:45 +00:00
public function startValidatingAfterAsking()
{
$this->ask = false;
$this->init();
}
2024-06-10 20:43:34 +00:00
public function validateConnection()
{
$this->authorize('update', $this->server);
2024-04-16 13:42:38 +00:00
['uptime' => $this->uptime, 'error' => $error] = $this->server->validateConnection();
2024-06-10 20:43:34 +00:00
if (! $this->uptime) {
2024-07-23 12:20:53 +00:00
$this->error = 'Server is not reachable. Please validate your configuration and connection.<br>Check this <a target="_blank" class="text-black underline dark:text-white" href="https://coolify.io/docs/knowledge-base/server/openssh">documentation</a> for further help. <br><br><div class="text-error">Error: '.$error.'</div>';
$this->server->update([
'validation_logs' => $this->error,
]);
2024-06-10 20:43:34 +00:00
return;
}
2024-02-22 10:28:45 +00:00
$this->dispatch('validateOS');
}
2024-06-10 20:43:34 +00:00
public function validateOS()
{
$this->supported_os_type = $this->server->validateOS();
2024-06-10 20:43:34 +00:00
if (! $this->supported_os_type) {
$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>.';
2024-07-23 12:20:53 +00:00
$this->server->update([
'validation_logs' => $this->error,
]);
2024-06-10 20:43:34 +00:00
return;
}
2024-02-22 10:28:45 +00:00
$this->dispatch('validateDockerEngine');
}
2024-06-10 20:43:34 +00:00
public function validateDockerEngine()
{
$this->docker_installed = $this->server->validateDockerEngine();
$this->docker_compose_installed = $this->server->validateDockerCompose();
2024-06-10 20:43:34 +00:00
if (! $this->docker_installed || ! $this->docker_compose_installed) {
if ($this->install) {
if ($this->number_of_tries == $this->max_tries) {
$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>.';
2024-07-23 12:20:53 +00:00
$this->server->update([
'validation_logs' => $this->error,
]);
2024-06-10 20:43:34 +00:00
return;
} else {
2024-04-16 13:42:38 +00:00
if ($this->number_of_tries <= $this->max_tries) {
2024-02-22 10:28:45 +00:00
$activity = $this->server->installDocker();
$this->number_of_tries++;
$this->dispatch('activityMonitor', $activity->id, 'init', $this->number_of_tries);
2024-02-22 10:28:45 +00:00
}
2024-06-10 20:43:34 +00:00
return;
}
} 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>.';
2024-07-23 12:20:53 +00:00
$this->server->update([
'validation_logs' => $this->error,
]);
2024-06-10 20:43:34 +00:00
return;
}
}
2024-02-22 10:28:45 +00:00
$this->dispatch('validateDockerVersion');
}
2024-06-10 20:43:34 +00:00
public function validateDockerVersion()
{
2024-02-22 10:28:45 +00:00
if ($this->server->isSwarm()) {
$swarmInstalled = $this->server->validateDockerSwarm();
if ($swarmInstalled) {
$this->dispatch('success', 'Docker Swarm is initiated.');
}
} else {
2024-02-22 10:28:45 +00:00
$this->docker_version = $this->server->validateDockerEngineVersion();
if ($this->docker_version) {
2024-06-18 14:42:42 +00:00
$this->dispatch('refreshServerShow');
$this->dispatch('refreshBoardingIndex');
$this->dispatch('success', 'Server validated, proxy is starting in a moment.');
$proxyShouldRun = CheckProxy::run($this->server, true);
if (! $proxyShouldRun) {
return;
}
StartProxy::dispatch($this->server);
2024-02-22 10:28:45 +00:00
} else {
2024-11-12 12:27:26 +00:00
$requiredDockerVersion = str(config('constants.docker.minimum_required_version'))->before('.');
$this->error = 'Minimum Docker Engine version '.$requiredDockerVersion.' is not instaled. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
2024-07-23 12:20:53 +00:00
$this->server->update([
'validation_logs' => $this->error,
]);
2024-06-10 20:43:34 +00:00
2024-02-22 10:28:45 +00:00
return;
}
}
2024-02-22 10:28:45 +00:00
if ($this->server->isBuildServer()) {
return;
}
}
2024-06-10 20:43:34 +00:00
public function render()
{
return view('livewire.server.validate-and-install');
}
}