|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Actions\Server; |
| 4 | + |
| 5 | +use App\Models\Server; |
| 6 | +use Lorisleiva\Actions\Concerns\AsAction; |
| 7 | + |
| 8 | +class ValidateServer |
| 9 | +{ |
| 10 | + use AsAction; |
| 11 | + |
| 12 | + public ?string $uptime = null; |
| 13 | + |
| 14 | + public ?string $error = null; |
| 15 | + |
| 16 | + public ?string $supported_os_type = null; |
| 17 | + |
| 18 | + public ?string $docker_installed = null; |
| 19 | + |
| 20 | + public ?string $docker_compose_installed = null; |
| 21 | + |
| 22 | + public ?string $docker_version = null; |
| 23 | + |
| 24 | + public function handle(Server $server) |
| 25 | + { |
| 26 | + $server->update([ |
| 27 | + 'validation_logs' => null, |
| 28 | + ]); |
| 29 | + ['uptime' => $this->uptime, 'error' => $error] = $server->validateConnection(); |
| 30 | + if (! $this->uptime) { |
| 31 | + $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>'; |
| 32 | + $server->update([ |
| 33 | + 'validation_logs' => $this->error, |
| 34 | + ]); |
| 35 | + throw new \Exception($this->error); |
| 36 | + } |
| 37 | + $this->supported_os_type = $server->validateOS(); |
| 38 | + if (! $this->supported_os_type) { |
| 39 | + $this->error = 'Server OS type is not supported. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; |
| 40 | + $server->update([ |
| 41 | + 'validation_logs' => $this->error, |
| 42 | + ]); |
| 43 | + throw new \Exception($this->error); |
| 44 | + } |
| 45 | + |
| 46 | + $this->docker_installed = $server->validateDockerEngine(); |
| 47 | + $this->docker_compose_installed = $server->validateDockerCompose(); |
| 48 | + if (! $this->docker_installed || ! $this->docker_compose_installed) { |
| 49 | + $this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; |
| 50 | + $server->update([ |
| 51 | + 'validation_logs' => $this->error, |
| 52 | + ]); |
| 53 | + throw new \Exception($this->error); |
| 54 | + } |
| 55 | + $this->docker_version = $server->validateDockerEngineVersion(); |
| 56 | + |
| 57 | + if ($this->docker_version) { |
| 58 | + return 'OK'; |
| 59 | + } else { |
| 60 | + $this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="text-black underline dark:text-white" href="https://docs.docker.com/engine/install/#server">documentation</a>.'; |
| 61 | + $server->update([ |
| 62 | + 'validation_logs' => $this->error, |
| 63 | + ]); |
| 64 | + throw new \Exception($this->error); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments