coolify/app/Actions/Server/UpdateCoolify.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2023-06-15 09:23:48 +00:00
<?php
namespace App\Actions\Server;
use App\Jobs\PullHelperImageJob;
2023-06-15 09:23:48 +00:00
use App\Models\Server;
use Illuminate\Support\Sleep;
2024-06-10 20:43:34 +00:00
use Lorisleiva\Actions\Concerns\AsAction;
2023-06-15 09:23:48 +00:00
class UpdateCoolify
{
2023-10-12 06:56:29 +00:00
use AsAction;
2024-06-10 20:43:34 +00:00
public ?Server $server = null;
2024-06-10 20:43:34 +00:00
public ?string $latestVersion = null;
2024-06-10 20:43:34 +00:00
public ?string $currentVersion = null;
2023-06-15 09:23:48 +00:00
public function handle($manual_update = false)
2023-06-15 09:23:48 +00:00
{
if (isDev()) {
Sleep::for(10)->seconds();
return;
}
2024-10-28 13:37:00 +00:00
$settings = instanceSettings();
2025-01-07 13:52:08 +00:00
$this->server = Server::query()->find(0);
2024-10-28 13:37:00 +00:00
if (! $this->server) {
return;
}
CleanupDocker::dispatch($this->server);
2024-10-28 13:37:00 +00:00
$this->latestVersion = get_latest_version_of_coolify();
$this->currentVersion = config('constants.coolify.version');
2024-10-28 13:37:00 +00:00
if (! $manual_update) {
if (! $settings->is_auto_update_enabled) {
2023-08-28 16:02:31 +00:00
return;
}
2024-10-28 13:37:00 +00:00
if ($this->latestVersion === $this->currentVersion) {
return;
}
if (version_compare($this->latestVersion, $this->currentVersion, '<')) {
return;
2024-05-28 13:05:18 +00:00
}
2023-06-15 09:23:48 +00:00
}
2024-10-28 13:37:00 +00:00
$this->update();
$settings->new_version_available = false;
$settings->save();
2023-06-15 09:23:48 +00:00
}
2023-06-15 09:23:48 +00:00
private function update()
{
PullHelperImageJob::dispatch($this->server);
instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$this->latestVersion}"], $this->server, false);
2024-05-30 18:02:11 +00:00
remote_process([
2024-06-10 20:43:34 +00:00
'curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh',
2024-11-10 21:07:41 +00:00
"bash /data/coolify/source/upgrade.sh $this->latestVersion",
2024-05-28 13:05:18 +00:00
], $this->server);
2023-06-15 09:23:48 +00:00
}
}