From 43fed96af139cc2101728ef31fa21a77b437d250 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 27 Mar 2024 11:35:57 +0100 Subject: [PATCH] fix: autoupdater --- app/Actions/Server/UpdateCoolify.php | 32 +++++++++++++++++++++------- app/Jobs/InstanceAutoUpdateJob.php | 2 +- app/Livewire/Upgrade.php | 4 ++-- bootstrap/helpers/shared.php | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php index 09efb848e..6c01f75c9 100644 --- a/app/Actions/Server/UpdateCoolify.php +++ b/app/Actions/Server/UpdateCoolify.php @@ -12,10 +12,12 @@ class UpdateCoolify public ?Server $server = null; public ?string $latestVersion = null; public ?string $currentVersion = null; + public bool $async = false; - public function handle(bool $force) + public function handle(bool $force = false, bool $async = false) { try { + $this->async = $async; $settings = InstanceSettings::get(); ray('Running InstanceAutoUpdateJob'); $this->server = Server::find(0); @@ -56,17 +58,31 @@ class UpdateCoolify { if (isDev()) { ray("Running update on local docker container. Updating to $this->latestVersion"); - remote_process([ - "sleep 10" - ], $this->server); + if ($this->async) { + ray('Running async update'); + remote_process([ + "sleep 10" + ], $this->server); + } else { + instant_remote_process([ + "sleep 10" + ], $this->server); + } ray('Update done'); return; } else { ray('Running update on production server'); - remote_process([ - "curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh", - "bash /data/coolify/source/upgrade.sh $this->latestVersion" - ], $this->server); + if ($this->async) { + remote_process([ + "curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh", + "bash /data/coolify/source/upgrade.sh $this->latestVersion" + ], $this->server); + } else { + instant_remote_process([ + "curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh", + "bash /data/coolify/source/upgrade.sh $this->latestVersion" + ], $this->server); + } return; } } diff --git a/app/Jobs/InstanceAutoUpdateJob.php b/app/Jobs/InstanceAutoUpdateJob.php index 99e0a34f3..fa5c29421 100644 --- a/app/Jobs/InstanceAutoUpdateJob.php +++ b/app/Jobs/InstanceAutoUpdateJob.php @@ -23,6 +23,6 @@ class InstanceAutoUpdateJob implements ShouldQueue, ShouldBeUnique, ShouldBeEncr public function handle(): void { - UpdateCoolify::run($this->force); + UpdateCoolify::run(force: $this->force, async: false); } } diff --git a/app/Livewire/Upgrade.php b/app/Livewire/Upgrade.php index 0c6541d8f..37c2a64ef 100644 --- a/app/Livewire/Upgrade.php +++ b/app/Livewire/Upgrade.php @@ -37,8 +37,8 @@ class Upgrade extends Component return; } $this->showProgress = true; - UpdateCoolify::run(true); - $this->dispatch('success', "Upgrading to {$this->latestVersion} version..."); + UpdateCoolify::run(force: true, async: true); + $this->dispatch('success', "Updating Coolify to {$this->latestVersion} version..."); } catch (\Throwable $e) { return handleError($e, $this); } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index bfff8098a..5892715ca 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -110,7 +110,7 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n ray($error); if ($error instanceof TooManyRequestsException) { if (isset($livewire)) { - return $livewire->dispatch('error', 'Too many requests. Please try again in {$error->secondsUntilAvailable} seconds.'); + return $livewire->dispatch('error', "Too many requests. Please try again in {$error->secondsUntilAvailable} seconds."); } return "Too many requests. Please try again in {$error->secondsUntilAvailable} seconds."; }