2023-06-15 11:23:48 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Actions\Server;
|
|
|
|
|
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
use App\Models\Server;
|
2024-08-08 13:32:15 +02:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-06-10 22:43:34 +02:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
2023-06-15 11:23:48 +02:00
|
|
|
|
|
|
|
class UpdateCoolify
|
|
|
|
{
|
2023-10-12 08:56:29 +02:00
|
|
|
use AsAction;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-09-01 10:11:00 +02:00
|
|
|
public ?Server $server = null;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-09-01 10:11:00 +02:00
|
|
|
public ?string $latestVersion = null;
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-09-01 10:11:00 +02:00
|
|
|
public ?string $currentVersion = null;
|
2023-06-15 11:23:48 +02:00
|
|
|
|
2024-05-30 19:38:33 +02:00
|
|
|
public function handle($manual_update = false)
|
2023-06-15 11:23:48 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-06-23 13:13:02 +02:00
|
|
|
$settings = InstanceSettings::get();
|
2023-12-13 11:55:08 +01:00
|
|
|
$this->server = Server::find(0);
|
2024-06-10 22:43:34 +02:00
|
|
|
if (! $this->server) {
|
2023-08-28 18:02:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-06-25 12:48:56 +02:00
|
|
|
CleanupDocker::dispatch($this->server, false)->onQueue('high');
|
2024-08-08 13:32:15 +02:00
|
|
|
$response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');
|
|
|
|
if ($response->successful()) {
|
|
|
|
$versions = $response->json();
|
|
|
|
File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT));
|
|
|
|
}
|
2023-09-01 10:11:00 +02:00
|
|
|
$this->latestVersion = get_latest_version_of_coolify();
|
|
|
|
$this->currentVersion = config('version');
|
2024-06-10 22:43:34 +02:00
|
|
|
if (! $manual_update) {
|
|
|
|
if (! $settings->is_auto_update_enabled) {
|
2024-05-30 19:38:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($this->latestVersion === $this->currentVersion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (version_compare($this->latestVersion, $this->currentVersion, '<')) {
|
|
|
|
return;
|
|
|
|
}
|
2024-05-28 15:05:18 +02:00
|
|
|
}
|
|
|
|
$this->update();
|
2024-08-08 13:32:15 +02:00
|
|
|
$settings->new_version_available = false;
|
|
|
|
$settings->save();
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
throw $e;
|
2023-06-15 11:23:48 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-15 11:23:48 +02:00
|
|
|
private function update()
|
|
|
|
{
|
2023-08-27 15:23:47 +02:00
|
|
|
if (isDev()) {
|
2024-05-30 20:02:11 +02:00
|
|
|
remote_process([
|
2024-06-10 22:43:34 +02:00
|
|
|
'sleep 10',
|
2024-05-28 15:05:18 +02:00
|
|
|
], $this->server);
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-06-15 11:23:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-05-30 20:02:11 +02:00
|
|
|
remote_process([
|
2024-06-10 22:43:34 +02:00
|
|
|
'curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh',
|
|
|
|
"bash /data/coolify/source/upgrade.sh $this->latestVersion",
|
2024-05-28 15:05:18 +02:00
|
|
|
], $this->server);
|
2024-06-10 22:43:34 +02:00
|
|
|
|
2023-06-15 11:23:48 +02:00
|
|
|
}
|
|
|
|
}
|