From 1d2b5d5b1550d68d571d23830fa06ad9ef36c75f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 28 Apr 2023 15:22:36 +0200 Subject: [PATCH] fix update script --- .../Commands/{SyncToBunnyCDN.php => SyncBunny.php} | 10 +++++----- app/Http/Livewire/CheckUpdate.php | 4 +--- app/Http/Livewire/ForceUpgrade.php | 5 ++++- bootstrap/helpers.php | 10 ++++++++++ scripts/run | 14 ++++---------- 5 files changed, 24 insertions(+), 19 deletions(-) rename app/Console/Commands/{SyncToBunnyCDN.php => SyncBunny.php} (91%) diff --git a/app/Console/Commands/SyncToBunnyCDN.php b/app/Console/Commands/SyncBunny.php similarity index 91% rename from app/Console/Commands/SyncToBunnyCDN.php rename to app/Console/Commands/SyncBunny.php index 2333a8d8c..7757a7e6c 100644 --- a/app/Console/Commands/SyncToBunnyCDN.php +++ b/app/Console/Commands/SyncBunny.php @@ -7,21 +7,21 @@ use Illuminate\Support\Facades\Http; use Illuminate\Http\Client\Pool; -class SyncToBunnyCDN extends Command +class SyncBunny extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'app:sync-to-bunny-cdn'; + protected $signature = 'sync:bunny'; /** * The console command description. * * @var string */ - protected $description = 'Command description'; + protected $description = 'Sync files to BunnyCDN'; /** * Execute the console command. @@ -67,10 +67,10 @@ public function handle() "url" => "$bunny_cdn/$bunny_cdn_path/$production_env" ]); if ($res->ok()) { - echo 'All files uploaded & purged...'; + echo "All files uploaded & purged...\n"; } } catch (\Exception $e) { - echo 'Something went wrong.'; + echo "Something went wrong.\n"; echo $e->getMessage(); } } diff --git a/app/Http/Livewire/CheckUpdate.php b/app/Http/Livewire/CheckUpdate.php index 9d56700de..fac16e3e2 100644 --- a/app/Http/Livewire/CheckUpdate.php +++ b/app/Http/Livewire/CheckUpdate.php @@ -15,9 +15,7 @@ class CheckUpdate extends Component public function checkUpdate() { - $response = Http::get('https://get.coollabs.io/versions.json'); - $versions = $response->json(); - $this->latestVersion = data_get($versions, 'coolify.v4.version'); + $this->latestVersion = getLatestVersionOfCoolify(); $this->currentVersion = config('coolify.version'); if ($this->latestVersion === 'latest') { $this->updateAvailable = true; diff --git a/app/Http/Livewire/ForceUpgrade.php b/app/Http/Livewire/ForceUpgrade.php index 0af7c690e..ad6dd2ba4 100644 --- a/app/Http/Livewire/ForceUpgrade.php +++ b/app/Http/Livewire/ForceUpgrade.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire; use App\Models\Server; +use Illuminate\Support\Facades\Http; use Livewire\Component; class ForceUpgrade extends Component @@ -22,6 +23,8 @@ public function upgrade() ], $server); $this->emit('updateInitiated'); } else { + $latestVersion = getLatestVersionOfCoolify(); + $cdn = "https://coolify-cdn.b-cdn.net/files"; $server = Server::where('ip', 'host.docker.internal')->first(); if (!$server) { @@ -39,7 +42,7 @@ public function upgrade() ]); remoteProcess([ - "bash /data/coolify/source/upgrade.sh $this->latestVersion" + "bash /data/coolify/source/upgrade.sh $latestVersion" ], $server); $this->emit('updateInitiated'); diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 46028e545..8afc290e4 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -6,6 +6,7 @@ use App\Models\Server; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Storage; @@ -133,3 +134,12 @@ function runRemoteCommandSync($server, array $command) return $output; } } + +if (!function_exists('getLatestVersionOfCoolify')) { + function getLatestVersionOfCoolify() + { + $response = Http::get('https://get.coollabs.io/versions.json'); + $versions = $response->json(); + return data_get($versions, 'coolify.v4.version'); + } +} diff --git a/scripts/run b/scripts/run index e0b42e035..fca172e01 100755 --- a/scripts/run +++ b/scripts/run @@ -20,6 +20,10 @@ function help { echo "Tasks:" compgen -A function | cat -n } +function sync-bunny { + bash vendor/bin/spin exec -u webuser coolify php artisan sync:bunny --env=secret || + php artisan sync:bunny --env=secrets +} function queue { bash vendor/bin/spin exec -u webuser coolify php artisan queue:listen } @@ -42,16 +46,6 @@ function vite { bash vendor/bin/spin exec vite bash } -function build-prod { - if [ "$1" ]; then - echo "Building version $1" - docker build -t ghcr.io/coollabsio/coolify:$1 -f docker/prod-ssu/Dockerfile . - else - echo "Building version 4.0.0-nightly.1" - docker build -t ghcr.io/coollabsio/coolify:4.0.0-nightly.1 -f docker/prod-ssu/Dockerfile . - fi -} - function default { help }