update bunny sync command
This commit is contained in:
parent
7721bc6dce
commit
be6c415a4e
@ -28,7 +28,7 @@ class SyncBunny extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$bunny_cdn = "https://coolify-cdn.b-cdn.net/";
|
$bunny_cdn = "https://coolify-cdn.b-cdn.net";
|
||||||
$bunny_cdn_path = "files";
|
$bunny_cdn_path = "files";
|
||||||
$bunny_cdn_storage_name = "coolify-cdn";
|
$bunny_cdn_storage_name = "coolify-cdn";
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ class SyncBunny extends Command
|
|||||||
|
|
||||||
$compose_file = "docker-compose.yml";
|
$compose_file = "docker-compose.yml";
|
||||||
$compose_file_prod = "docker-compose.prod.yml";
|
$compose_file_prod = "docker-compose.prod.yml";
|
||||||
|
$install_script = "install.sh";
|
||||||
$upgrade_script = "upgrade.sh";
|
$upgrade_script = "upgrade.sh";
|
||||||
$docker_install_script = "install-docker.sh";
|
$docker_install_script = "install-docker.sh";
|
||||||
$production_env = ".env.production";
|
$production_env = ".env.production";
|
||||||
@ -50,29 +51,34 @@ class SyncBunny extends Command
|
|||||||
$file = fread($fileStream, filesize($file));
|
$file = fread($fileStream, filesize($file));
|
||||||
return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw();
|
return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw();
|
||||||
});
|
});
|
||||||
|
PendingRequest::macro('purge', function ($url) {
|
||||||
|
$headers = [
|
||||||
|
'AccessKey' => env('BUNNY_API_KEY'),
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
];
|
||||||
|
return PendingRequest::withHeaders($headers)->post('https://api.bunny.net/purge', [
|
||||||
|
"urls" => [$url],
|
||||||
|
]);
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
Http::pool(fn (Pool $pool) => [
|
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")->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/$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/$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/$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/scripts/$docker_install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$docker_install_script"),
|
$pool->storage(file: "$parent_dir/scripts/$docker_install_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$docker_install_script"),
|
||||||
]);
|
]);
|
||||||
|
Http::pool(fn (Pool $pool) => [
|
||||||
$res = Http::withHeaders([
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$compose_file"),
|
||||||
'AccessKey' => env('BUNNY_API_KEY'),
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$compose_file_prod"),
|
||||||
'Accept' => 'application/json',
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$production_env"),
|
||||||
])->get('https://api.bunny.net/purge', [
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$upgrade_script"),
|
||||||
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file",
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$install_script"),
|
||||||
"url" => "$bunny_cdn/$bunny_cdn_path/$compose_file_prod",
|
$pool->purge(url: "$bunny_cdn/$bunny_cdn_path/$docker_install_script"),
|
||||||
"url" => "$bunny_cdn/$bunny_cdn_path/$upgrade_script",
|
|
||||||
"url" => "$bunny_cdn/$bunny_cdn_path/$production_env",
|
|
||||||
"url" => "$bunny_cdn/$bunny_cdn_path/$docker_install_script"
|
|
||||||
]);
|
]);
|
||||||
if ($res->ok()) {
|
|
||||||
echo "All files uploaded & purged...\n";
|
echo "All files uploaded & purged...\n";
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
throw new \Exception("Something went wrong.");
|
throw new \Exception("Something went wrong.");
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user