From df4ecd47a7744b0c4996b9fcb06d8e6ff9c1e0f1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 11:54:20 +0200 Subject: [PATCH] fix: sync command --- app/Console/Commands/SyncBunny.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SyncBunny.php b/app/Console/Commands/SyncBunny.php index 1be47ba8a..85c29d243 100644 --- a/app/Console/Commands/SyncBunny.php +++ b/app/Console/Commands/SyncBunny.php @@ -30,6 +30,7 @@ class SyncBunny extends Command */ public function handle() { + $that = $this; $only_template = $this->option('only-template'); $bunny_cdn = "https://cdn.coollabs.io"; $bunny_cdn_path = "coolify"; @@ -46,22 +47,23 @@ class SyncBunny extends Command $versions = "versions.json"; - PendingRequest::macro('storage', function ($file) { + PendingRequest::macro('storage', function ($fileName) use($that) { $headers = [ 'AccessKey' => env('BUNNY_STORAGE_API_KEY'), 'Accept' => 'application/json', 'Content-Type' => 'application/octet-stream' ]; - $fileStream = fopen($file, "r"); - $file = fread($fileStream, filesize($file)); + $fileStream = fopen($fileName, "r"); + $file = fread($fileStream, filesize($fileName)); + $that->info('Uploading: ' . $fileName); return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw(); }); - PendingRequest::macro('purge', function ($url) { + PendingRequest::macro('purge', function ($url) use ($that) { $headers = [ 'AccessKey' => env('BUNNY_API_KEY'), 'Accept' => 'application/json', ]; - ray('Purging: ' . $url); + $that->info('Purging: ' . $url); return PendingRequest::withHeaders($headers)->get('https://api.bunny.net/purge', [ "url" => $url, "async" => false @@ -82,14 +84,13 @@ class SyncBunny extends Command } Http::pool(fn (Pool $pool) => [ - $pool->storage(file: "$parent_dir/$compose_file")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file"), - $pool->storage(file: "$parent_dir/$compose_file_prod")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file_prod"), - $pool->storage(file: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"), - $pool->storage(file: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"), - $pool->storage(file: "$parent_dir/scripts/$install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$install_script"), - $pool->storage(file: "$parent_dir/$versions")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$versions"), + $pool->storage(fileName: "$parent_dir/$compose_file")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file"), + $pool->storage(fileName: "$parent_dir/$compose_file_prod")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$compose_file_prod"), + $pool->storage(fileName: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"), + $pool->storage(fileName: "$parent_dir/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"), + $pool->storage(fileName: "$parent_dir/scripts/$install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$install_script"), + $pool->storage(fileName: "$parent_dir/$versions")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$versions"), ]); - $this->info("{$bunny_cdn}/{$bunny_cdn_path}"); Http::pool(fn (Pool $pool) => [ $pool->purge("$bunny_cdn/$bunny_cdn_path/$compose_file"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$compose_file_prod"),