mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 20:17:05 +00:00
feat(v5): add coolify CLI version check
This commit is contained in:
1 parent
d92c6a8dab
commit
c884aaaeea
15 files changed
+365
-117
No files matched your search
@@ -5,7 +5,9 @@ namespace App\Http\Controllers\V5;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use App\Services\Coold\CoolifyCliVersion;
|
||||
use App\Services\Flux\FluxHealth;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
@@ -43,6 +45,11 @@ class HomeController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function coolifyCliVersion(CoolifyCliVersion $coolifyCliVersion): JsonResponse
|
||||
{
|
||||
return response()->json($coolifyCliVersion->check());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: string, wireguardIp: string|null, capabilities: array<int, string>, builderEnabled: bool, builderCapacity: int}>
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Coold;
|
||||
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Throwable;
|
||||
|
||||
class CoolifyCliVersion
|
||||
{
|
||||
/**
|
||||
* @return array{available: bool, label: string, version: string|null, message: string, binary: string|null}
|
||||
*/
|
||||
public function check(): array
|
||||
{
|
||||
$binary = config('coold.coolify_cli_bin', '/usr/local/bin/coolify');
|
||||
|
||||
if (! is_string($binary) || $binary === '') {
|
||||
return $this->unavailable(null, 'coolify binary is not configured.');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = Process::timeout(5)->run(escapeshellarg($binary).' --version');
|
||||
} catch (Throwable $exception) {
|
||||
return $this->unavailable($binary, $exception->getMessage());
|
||||
}
|
||||
|
||||
if (! $result->successful()) {
|
||||
return $this->unavailable($binary, trim($result->errorOutput()) ?: 'coolify version check failed.');
|
||||
}
|
||||
|
||||
$version = trim($result->output());
|
||||
|
||||
return [
|
||||
'available' => true,
|
||||
'label' => 'Installed',
|
||||
'version' => $version !== '' ? $version : null,
|
||||
'message' => $version !== '' ? "Installed version: {$version}." : 'coolify is installed.',
|
||||
'binary' => $binary,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{available: false, label: string, version: null, message: string, binary: string|null}
|
||||
*/
|
||||
private function unavailable(?string $binary, string $message): array
|
||||
{
|
||||
return [
|
||||
'available' => false,
|
||||
'label' => 'Unavailable',
|
||||
'version' => null,
|
||||
'message' => $message,
|
||||
'binary' => $binary,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user