mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-16 20:14:08 +00:00
feat: enhance prerequisite validation to return detailed results
This commit is contained in:
1 parent
01957f2752
commit
29135e00ba
7 files changed
+95
-21
No files matched your search
@@ -11,17 +11,30 @@ class ValidatePrerequisites
|
||||
|
||||
public string $jobQueue = 'high';
|
||||
|
||||
public function handle(Server $server): bool
|
||||
/**
|
||||
* Validate that required commands are available on the server.
|
||||
*
|
||||
* @return array{success: bool, missing: array<string>, found: array<string>}
|
||||
*/
|
||||
public function handle(Server $server): array
|
||||
{
|
||||
$requiredCommands = ['git', 'curl', 'jq'];
|
||||
$missing = [];
|
||||
$found = [];
|
||||
|
||||
foreach ($requiredCommands as $cmd) {
|
||||
$found = instant_remote_process(["command -v {$cmd}"], $server, false);
|
||||
if (! $found) {
|
||||
return false;
|
||||
$result = instant_remote_process(["command -v {$cmd}"], $server, false);
|
||||
if (! $result) {
|
||||
$missing[] = $cmd;
|
||||
} else {
|
||||
$found[] = $cmd;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return [
|
||||
'success' => empty($missing),
|
||||
'missing' => $missing,
|
||||
'found' => $found,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,10 @@ class ValidateServer
|
||||
throw new \Exception($this->error);
|
||||
}
|
||||
|
||||
$prerequisitesInstalled = $server->validatePrerequisites();
|
||||
if (! $prerequisitesInstalled) {
|
||||
$this->error = 'Prerequisites (git, curl, jq) are not installed. Please install them before continuing or use the validation with installation endpoint.';
|
||||
$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,
|
||||
]);
|
||||
|
||||
@@ -73,10 +73,11 @@ class ValidateAndInstallServerJob implements ShouldQueue
|
||||
}
|
||||
|
||||
// Check and install prerequisites
|
||||
$prerequisitesInstalled = $this->server->validatePrerequisites();
|
||||
if (! $prerequisitesInstalled) {
|
||||
$validationResult = $this->server->validatePrerequisites();
|
||||
if (! $validationResult['success']) {
|
||||
if ($this->numberOfTries >= $this->maxTries) {
|
||||
$errorMessage = 'Prerequisites (git, curl, jq) could not be installed after '.$this->maxTries.' attempts. Please install them manually before continuing.';
|
||||
$missingCommands = implode(', ', $validationResult['missing']);
|
||||
$errorMessage = "Prerequisites ({$missingCommands}) could not be installed after {$this->maxTries} attempts. Please install them manually before continuing.";
|
||||
$this->server->update([
|
||||
'validation_logs' => $errorMessage,
|
||||
'is_validating' => false,
|
||||
@@ -84,6 +85,8 @@ class ValidateAndInstallServerJob implements ShouldQueue
|
||||
Log::error('ValidateAndInstallServer: Prerequisites installation failed after max tries', [
|
||||
'server_id' => $this->server->id,
|
||||
'attempts' => $this->numberOfTries,
|
||||
'missing_commands' => $validationResult['missing'],
|
||||
'found_commands' => $validationResult['found'],
|
||||
]);
|
||||
|
||||
return;
|
||||
@@ -92,6 +95,8 @@ class ValidateAndInstallServerJob implements ShouldQueue
|
||||
Log::info('ValidateAndInstallServer: Installing prerequisites', [
|
||||
'server_id' => $this->server->id,
|
||||
'attempt' => $this->numberOfTries + 1,
|
||||
'missing_commands' => $validationResult['missing'],
|
||||
'found_commands' => $validationResult['found'],
|
||||
]);
|
||||
|
||||
// Install prerequisites
|
||||
|
||||
@@ -322,13 +322,14 @@ class Index extends Component
|
||||
|
||||
try {
|
||||
// Check prerequisites
|
||||
$prerequisitesInstalled = $this->createdServer->validatePrerequisites();
|
||||
if (! $prerequisitesInstalled) {
|
||||
$validationResult = $this->createdServer->validatePrerequisites();
|
||||
if (! $validationResult['success']) {
|
||||
$this->createdServer->installPrerequisites();
|
||||
// Recheck after installation
|
||||
$prerequisitesInstalled = $this->createdServer->validatePrerequisites();
|
||||
if (! $prerequisitesInstalled) {
|
||||
throw new \Exception('Prerequisites (git, curl, jq) could not be installed. Please install them manually.');
|
||||
$validationResult = $this->createdServer->validatePrerequisites();
|
||||
if (! $validationResult['success']) {
|
||||
$missingCommands = implode(', ', $validationResult['missing']);
|
||||
throw new \Exception("Prerequisites ({$missingCommands}) could not be installed. Please install them manually.");
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
@@ -115,11 +115,13 @@ class ValidateAndInstall extends Component
|
||||
|
||||
public function validatePrerequisites()
|
||||
{
|
||||
$this->prerequisites_installed = $this->server->validatePrerequisites();
|
||||
if (! $this->prerequisites_installed) {
|
||||
$validationResult = $this->server->validatePrerequisites();
|
||||
$this->prerequisites_installed = $validationResult['success'];
|
||||
if (! $validationResult['success']) {
|
||||
if ($this->install) {
|
||||
if ($this->number_of_tries == $this->max_tries) {
|
||||
$this->error = 'Prerequisites (git, curl, jq) could not be installed. Please install them manually before continuing.';
|
||||
$missingCommands = implode(', ', $validationResult['missing']);
|
||||
$this->error = "Prerequisites ({$missingCommands}) could not be installed. Please install them manually before continuing.";
|
||||
$this->server->update([
|
||||
'validation_logs' => $this->error,
|
||||
]);
|
||||
@@ -136,7 +138,8 @@ class ValidateAndInstall extends Component
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$this->error = 'Prerequisites (git, curl, jq) are not installed. Please install them before continuing.';
|
||||
$missingCommands = implode(', ', $validationResult['missing']);
|
||||
$this->error = "Prerequisites ({$missingCommands}) are not installed. Please install them before continuing.";
|
||||
$this->server->update([
|
||||
'validation_logs' => $this->error,
|
||||
]);
|
||||
|
||||
@@ -1186,7 +1186,12 @@ $schema://$host {
|
||||
return InstallDocker::run($this);
|
||||
}
|
||||
|
||||
public function validatePrerequisites(): bool
|
||||
/**
|
||||
* Validate that required commands are available on the server.
|
||||
*
|
||||
* @return array{success: bool, missing: array<string>, found: array<string>}
|
||||
*/
|
||||
public function validatePrerequisites(): array
|
||||
{
|
||||
return ValidatePrerequisites::run($this);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user