lasthourcloud/app/Http/Livewire/CheckUpdate.php

51 lines
1.7 KiB
PHP
Raw Normal View History

2023-04-14 10:00:42 +02:00
<?php
namespace App\Http\Livewire;
use App\Models\Server;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
class CheckUpdate extends Component
{
public $updateAvailable = false;
2023-04-27 13:02:24 +02:00
public $latestVersion = 'latest';
2023-04-14 10:00:42 +02:00
protected $currentVersion;
protected $image = 'ghcr.io/coollabsio/coolify';
2023-04-27 12:52:13 +02:00
protected function upgrade()
{
2023-04-28 13:50:27 +02:00
$cdn = "https://coolify-cdn.b-cdn.net/files";
2023-04-27 14:35:28 +02:00
$server = Server::where('ip', 'host.docker.internal')->first();
2023-04-27 12:52:13 +02:00
if (!$server) {
return;
}
2023-04-28 11:54:01 +02:00
runRemoteCommandSync($server, [
2023-04-28 13:50:27 +02:00
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
2023-04-28 11:54:01 +02:00
"nohup bash /data/coolify/source/upgrade.sh $this->latestVersion &"
]);
$this->emit('updateInitiated');
2023-04-27 12:52:13 +02:00
}
public function forceUpgrade()
{
2023-04-27 13:52:00 +02:00
$this->checkUpdate();
2023-04-27 12:52:13 +02:00
$this->upgrade();
}
2023-04-14 10:00:42 +02:00
public function checkUpdate()
{
$response = Http::get('https://get.coollabs.io/versions.json');
$versions = $response->json();
2023-04-27 13:02:24 +02:00
$this->latestVersion = data_get($versions, 'coolify.v4.version');
2023-04-14 10:00:42 +02:00
$this->currentVersion = config('coolify.version');
2023-04-27 13:02:24 +02:00
if ($this->latestVersion === 'latest') {
$this->updateAvailable = true;
return;
}
2023-04-14 10:00:42 +02:00
version_compare($this->currentVersion, $this->latestVersion, '<') ? $this->updateAvailable = true : $this->updateAvailable = false;
}
}