option('only-template'); $bunny_cdn = "https://cdn.coollabs.io"; $bunny_cdn_path = "coolify"; $bunny_cdn_storage_name = "coolcdn"; $parent_dir = realpath(dirname(__FILE__) . '/../../..'); $compose_file = "docker-compose.yml"; $compose_file_prod = "docker-compose.prod.yml"; $install_script = "install.sh"; $upgrade_script = "upgrade.sh"; $production_env = ".env.production"; $service_template = "service-templates.json"; $versions = "versions.json"; PendingRequest::macro('storage', function ($fileName) use($that) { $headers = [ 'AccessKey' => env('BUNNY_STORAGE_API_KEY'), 'Accept' => 'application/json', 'Content-Type' => 'application/octet-stream' ]; $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) use ($that) { $headers = [ 'AccessKey' => env('BUNNY_API_KEY'), 'Accept' => 'application/json', ]; $that->info('Purging: ' . $url); return PendingRequest::withHeaders($headers)->get('https://api.bunny.net/purge', [ "url" => $url, "async" => false ]); }); try { $confirmed = confirm('Are you sure?'); if (!$confirmed) { return; } if ($only_template) { Http::pool(fn (Pool $pool) => [ $pool->storage(file: "$parent_dir/templates/$service_template")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$service_template"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$service_template"), ]); $this->info('Service template uploaded & purged...'); return; } Http::pool(fn (Pool $pool) => [ $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"), ]); Http::pool(fn (Pool $pool) => [ $pool->purge("$bunny_cdn/$bunny_cdn_path/$compose_file"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$compose_file_prod"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$production_env"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$upgrade_script"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$install_script"), $pool->purge("$bunny_cdn/$bunny_cdn_path/$versions"), ]); $this->info("All files uploaded & purged..."); } catch (\Throwable $e) { $this->error("Error: " . $e->getMessage()); } } }