sync confs to bunnycdn
This commit is contained in:
parent
3673117580
commit
19137ad705
6
.env.secrets.example
Normal file
6
.env.secrets.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Secrets related to pushing to GH, Sync files to BunnyCDN etc.
|
||||||
|
# Not related to Coolify, but to how we publish new versions.
|
||||||
|
|
||||||
|
GITHUB_TOKEN=
|
||||||
|
BUNNY_API_KEY=
|
||||||
|
BUNNY_STORAGE_API_KEY=
|
11
.github/workflows/production-build.yml
vendored
11
.github/workflows/production-build.yml
vendored
@ -19,6 +19,9 @@ jobs:
|
|||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Sync configuration files to BunnyCDN
|
||||||
|
run: |
|
||||||
|
docker run --rm -v "$(pwd):/app" -w /app php:8.2-alpine3.16 php artisan app:sync-to-bunny-cdn --env=secrets
|
||||||
- name: Get Version
|
- name: Get Version
|
||||||
id: version
|
id: version
|
||||||
run: |
|
run: |
|
||||||
@ -31,7 +34,7 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
|
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
|
||||||
- uses: sarisia/actions-status-discord@v1
|
# - uses: sarisia/actions-status-discord@v1
|
||||||
if: always()
|
# if: always()
|
||||||
with:
|
# with:
|
||||||
webhook: ${{ secrets.DISCORD_WEBHOOK_DEV_RELEASE_CHANNEL }}
|
# webhook: ${{ secrets.DISCORD_WEBHOOK_DEV_RELEASE_CHANNEL }}
|
||||||
|
77
app/Console/Commands/SyncToBunnyCDN.php
Normal file
77
app/Console/Commands/SyncToBunnyCDN.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Http\Client\PendingRequest;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Http\Client\Pool;
|
||||||
|
|
||||||
|
class SyncToBunnyCDN extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:sync-to-bunny-cdn';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$bunny_cdn = "https://coolify-cdn.b-cdn.net/";
|
||||||
|
$bunny_cdn_path = "files";
|
||||||
|
$bunny_cdn_storage_name = "coolify-cdn";
|
||||||
|
|
||||||
|
$parent_dir = realpath(dirname(__FILE__) . '/../../..');
|
||||||
|
|
||||||
|
$compose_file = "docker-compose.yml";
|
||||||
|
$compose_file_prod = "docker-compose.prod.yml";
|
||||||
|
$upgrade_script = "upgrade.sh";
|
||||||
|
$production_env = ".env.production";
|
||||||
|
|
||||||
|
PendingRequest::macro('storage', function ($file) {
|
||||||
|
$headers = [
|
||||||
|
'AccessKey' => env('BUNNY_STORAGE_API_KEY'),
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Content-Type' => 'application/octet-stream'
|
||||||
|
];
|
||||||
|
$fileStream = fopen($file, "r");
|
||||||
|
$file = fread($fileStream, filesize($file));
|
||||||
|
return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw();
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
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/scripts/$upgrade_script")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$upgrade_script"),
|
||||||
|
$pool->storage(file: "$parent_dir/$production_env")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$production_env"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = Http::withHeaders([
|
||||||
|
'AccessKey' => env('BUNNY_API_KEY'),
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
])->get('https://api.bunny.net/purge', [
|
||||||
|
"url" => e("$bunny_cdn/$bunny_cdn_path/$compose_file"),
|
||||||
|
"url" => e("$bunny_cdn/$bunny_cdn_path/$compose_file_prod"),
|
||||||
|
"url" => e("$bunny_cdn/$bunny_cdn_path/$upgrade_script"),
|
||||||
|
"url" => e("$bunny_cdn/$bunny_cdn_path/$production_env")
|
||||||
|
]);
|
||||||
|
if ($res->ok()) {
|
||||||
|
echo 'All files uploaded & purged...';
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo 'Something went wrong.';
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,19 +15,17 @@ class CheckUpdate extends Component
|
|||||||
|
|
||||||
protected function upgrade()
|
protected function upgrade()
|
||||||
{
|
{
|
||||||
$branch = 'v4';
|
$cdn = "https://coolify-cdn.b-cdn.net/files";
|
||||||
$location = "https://raw.githubusercontent.com/coollabsio/coolify/$branch";
|
|
||||||
|
|
||||||
$server = Server::where('ip', 'host.docker.internal')->first();
|
$server = Server::where('ip', 'host.docker.internal')->first();
|
||||||
if (!$server) {
|
if (!$server) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runRemoteCommandSync($server, [
|
runRemoteCommandSync($server, [
|
||||||
"curl -fsSL $location/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
"curl -fsSL $cdn/docker-compose.yml -o /data/coolify/source/docker-compose.yml",
|
||||||
"curl -fsSL $location/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
|
"curl -fsSL $cdn/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml",
|
||||||
"curl -fsSL $location/.env.production -o /data/coolify/source/.env.production",
|
"curl -fsSL $cdn/.env.production -o /data/coolify/source/.env.production",
|
||||||
"curl -fsSL $location/scripts/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
"curl -fsSL $cdn/upgrade.sh -o /data/coolify/source/upgrade.sh",
|
||||||
"nohup bash /data/coolify/source/upgrade.sh $this->latestVersion &"
|
"nohup bash /data/coolify/source/upgrade.sh $this->latestVersion &"
|
||||||
]);
|
]);
|
||||||
$this->emit('updateInitiated');
|
$this->emit('updateInitiated');
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
"pestphp/pest": "^v2.4.0",
|
"pestphp/pest": "^v2.4.0",
|
||||||
"phpunit/phpunit": "^10.0.19",
|
"phpunit/phpunit": "^10.0.19",
|
||||||
"serversideup/spin": "^v1.1.0",
|
"serversideup/spin": "^v1.1.0",
|
||||||
"spatie/laravel-ignition": "^2.1.0"
|
"spatie/laravel-ignition": "^2.1.0",
|
||||||
|
"symfony/http-client": "^6.2",
|
||||||
|
"toshy/bunnynet-php": "^3.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
|
815
composer.lock
generated
815
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## Do not modify this file. You will lost the ability to installation and autoupdate!
|
## Do not modify this file. You will lost the ability to installation and autoupdate!
|
||||||
VERSION="0.1.0"
|
VERSION="0.1.0"
|
||||||
|
CDN="https://coolify-cdn.b-cdn.net/files"
|
||||||
|
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" -ne 0 ]; then
|
||||||
echo "Please run as root"
|
echo "Please run as root"
|
||||||
@ -27,10 +28,10 @@ chown -R 9999:root /data
|
|||||||
chmod -R 700 /data
|
chmod -R 700 /data
|
||||||
|
|
||||||
echo "Downloading required files from GitHub..."
|
echo "Downloading required files from GitHub..."
|
||||||
curl -fsSL https://raw.githubusercontent.com/coollabsio/coolify/${COOLIFY_VERSION_BRANCH}/docker-compose.yml -o /data/coolify/source/docker-compose.yml
|
curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml
|
||||||
curl -fsSL https://raw.githubusercontent.com/coollabsio/coolify/${COOLIFY_VERSION_BRANCH}/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
|
curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
|
||||||
curl -fsSL https://raw.githubusercontent.com/coollabsio/coolify/${COOLIFY_VERSION_BRANCH}/.env.production -o /data/coolify/source/.env.production
|
curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production
|
||||||
curl -fsSL https://raw.githubusercontent.com/coollabsio/coolify/v4/scripts/upgrade.sh -o /data/coolify/source/upgrade.sh
|
curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh
|
||||||
|
|
||||||
# Copy .env.example if .env does not exist
|
# Copy .env.example if .env does not exist
|
||||||
if [ ! -f /data/coolify/source/.env ]; then
|
if [ ! -f /data/coolify/source/.env ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user