mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
When "docker version --format json" did not return clean JSON (for example, text from a shell startup file), validation stored 0.0.0 and said that Docker was older than version 24. Validation now stores no version and tells the user to run the command on the server. When the version is too old, the message shows the detected version. Closes #11089 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
5.3 KiB
PHP
125 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Server;
|
|
|
|
use App\Models\Server;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class ValidateServer
|
|
{
|
|
use AsAction;
|
|
|
|
public string $jobQueue = 'high';
|
|
|
|
public ?string $uptime = null;
|
|
|
|
public ?string $error = null;
|
|
|
|
public ?string $supported_os_type = null;
|
|
|
|
public ?string $docker_installed = null;
|
|
|
|
public ?string $docker_compose_installed = null;
|
|
|
|
public ?string $docker_version = null;
|
|
|
|
public function handle(Server $server)
|
|
{
|
|
if (! $server->canBeValidated()) {
|
|
$this->error = 'This server was transferred to another Coolify instance and cannot be revalidated here.';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
'is_validating' => false,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
|
|
$server->update([
|
|
'validation_logs' => null,
|
|
]);
|
|
if ($server->vultr_instance_id) {
|
|
$status = $server->refreshVultrState();
|
|
if (in_array($status, ['stopped', 'suspended', 'deleted'], true)) {
|
|
$this->error = $status === 'deleted'
|
|
? 'Vultr instance is deleted or no longer accessible. Relink this server before validating.'
|
|
: 'Vultr instance is '.($status ?? 'not running').'. Power it on before validating.';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
}
|
|
|
|
if ($server->digitalocean_droplet_id) {
|
|
$status = $server->refreshDigitalOceanState();
|
|
if (in_array($status, ['off', 'archive', 'deleted'], true)) {
|
|
$this->error = $status === 'deleted'
|
|
? 'DigitalOcean droplet is deleted or no longer accessible. Relink this server before validating.'
|
|
: 'DigitalOcean droplet is '.($status ?? 'not running').'. Power it on before validating.';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
}
|
|
|
|
if ($server->hostinger_virtual_machine_id) {
|
|
$status = $server->refreshHostingerState();
|
|
if (in_array($status, ['stopping', 'stopped', 'suspending', 'suspended', 'destroying', 'destroyed', 'error'], true)) {
|
|
$this->error = 'Hostinger VPS is '.($status ?? 'not running').'. Power it on before validating.';
|
|
$server->update(['validation_logs' => $this->error]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
}
|
|
|
|
['uptime' => $this->uptime, 'error' => $error] = $server->validateConnection();
|
|
if (! $this->uptime) {
|
|
$sanitizedError = htmlspecialchars($error ?? '', ENT_QUOTES, 'UTF-8');
|
|
$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: '.$sanitizedError.'</div>';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
$this->supported_os_type = $server->validateOS();
|
|
if (! $this->supported_os_type) {
|
|
$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>.';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
|
|
$validationResult = $server->validatePrerequisites();
|
|
if (! $validationResult['success']) {
|
|
$missingCommands = implode(', ', $validationResult['missing']);
|
|
$this->error = "Prerequisites ({$missingCommands}) are not installed. Please install them before continuing or use the validation with installation endpoint.";
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
|
|
$this->docker_installed = $server->validateDockerEngine();
|
|
$this->docker_compose_installed = $server->validateDockerCompose();
|
|
if (! $this->docker_installed || ! $this->docker_compose_installed) {
|
|
$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>.';
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
$this->docker_version = $server->validateDockerEngineVersion();
|
|
|
|
if ($this->docker_version) {
|
|
return 'OK';
|
|
} else {
|
|
$this->error = $server->dockerEngineVersionError();
|
|
$server->update([
|
|
'validation_logs' => $this->error,
|
|
]);
|
|
throw new \Exception($this->error);
|
|
}
|
|
}
|
|
}
|