2023-05-22 10:00:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Bus\Queueable;
|
2023-05-26 06:16:39 +00:00
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
2023-05-22 10:00:59 +00:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2023-05-25 12:40:47 +00:00
|
|
|
use Log;
|
2023-05-22 10:00:59 +00:00
|
|
|
|
2023-05-26 06:16:39 +00:00
|
|
|
class InstanceAutoUpdateJob implements ShouldQueue, ShouldBeUnique
|
2023-05-22 10:00:59 +00:00
|
|
|
{
|
2023-05-22 10:47:15 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2023-05-22 10:00:59 +00:00
|
|
|
|
2023-05-26 06:16:39 +00:00
|
|
|
public $tries = 1;
|
|
|
|
public $timeout = 120;
|
|
|
|
public function uniqueId(): int
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2023-05-25 20:59:33 +00:00
|
|
|
public function __construct(private bool $force = false)
|
2023-05-26 06:58:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(): void
|
2023-05-22 10:00:59 +00:00
|
|
|
{
|
2023-05-26 06:28:39 +00:00
|
|
|
try {
|
2023-05-26 06:58:58 +00:00
|
|
|
$localhost_name = 'localhost';
|
2023-05-26 06:28:39 +00:00
|
|
|
if (config('app.env') === 'local') {
|
|
|
|
$localhost_name = 'testing-local-docker-container';
|
2023-05-25 20:10:21 +00:00
|
|
|
}
|
2023-05-26 06:58:58 +00:00
|
|
|
$server = Server::where('name', $localhost_name)->firstOrFail();
|
|
|
|
$latest_version = get_latest_version_of_coolify();
|
|
|
|
$current_version = config('version');
|
2023-05-26 06:28:39 +00:00
|
|
|
|
2023-05-25 12:40:47 +00:00
|
|
|
if (config('app.env') === 'local') {
|
|
|
|
instant_remote_process([
|
|
|
|
"sleep 10"
|
2023-05-26 06:58:58 +00:00
|
|
|
], $server);
|
|
|
|
return;
|
2023-05-25 12:40:47 +00:00
|
|
|
} else {
|
2023-05-26 06:58:58 +00:00
|
|
|
if (!$this->force) {
|
|
|
|
$instance_settings = InstanceSettings::get();
|
|
|
|
if (!$instance_settings->is_auto_update_enabled) {
|
|
|
|
$this->fail('Auto update is disabled');
|
2023-05-26 11:52:40 +00:00
|
|
|
return;
|
2023-05-26 06:58:58 +00:00
|
|
|
}
|
|
|
|
if ($latest_version === $current_version) {
|
|
|
|
$this->fail("Already on latest version");
|
2023-05-26 11:52:40 +00:00
|
|
|
return;
|
2023-05-26 06:58:58 +00:00
|
|
|
}
|
|
|
|
if (version_compare($latest_version, $current_version, '<')) {
|
|
|
|
$this->fail("Latest version is lower than current version?!");
|
2023-05-26 11:52:40 +00:00
|
|
|
return;
|
2023-05-26 06:58:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-25 12:40:47 +00:00
|
|
|
instant_remote_process([
|
2023-05-25 19:58:59 +00:00
|
|
|
"curl -fsSL https://coolify-cdn.b-cdn.net/files/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
2023-05-26 06:58:58 +00:00
|
|
|
"bash /data/coolify/source/upgrade.sh $latest_version"
|
|
|
|
], $server);
|
|
|
|
return;
|
2023-05-22 10:00:59 +00:00
|
|
|
}
|
2023-05-25 12:40:47 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e->getMessage());
|
2023-05-26 06:28:39 +00:00
|
|
|
$this->fail($e->getMessage());
|
2023-05-26 11:52:40 +00:00
|
|
|
return;
|
2023-05-22 10:00:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|