From 2b3057e1b4dcc67e13200471ecd6af681a81a5bb Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 11:50:50 +0200 Subject: [PATCH 01/12] version++ --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index 592553a39..16e57890d 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.46', + 'release' => '4.0.0-beta.47', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 548f25cb6..67a77dc1f 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 28 Sep 2023 11:51:01 +0200 Subject: [PATCH 02/12] fix: cannot delete env with available services --- app/Models/Environment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Environment.php b/app/Models/Environment.php index 470ad5e6c..624787ba6 100644 --- a/app/Models/Environment.php +++ b/app/Models/Environment.php @@ -14,7 +14,7 @@ class Environment extends Model public function can_delete_environment() { - return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0; + return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0 && $this->services()->count() == 0; } public function applications() From df4ecd47a7744b0c4996b9fcb06d8e6ff9c1e0f1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 11:54:20 +0200 Subject: [PATCH 03/12] 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"), From cdb6964b0b5814053df70bcb13de405d8a0bfeb7 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:05:17 +0200 Subject: [PATCH 04/12] fix: install script drops an error --- scripts/install.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index e7d7b02b7..c6f702c9b 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -72,14 +72,21 @@ cat >/etc/docker/daemon.json.coolify </etc/docker/daemon.json.coolify cat <<<$(jq -s '.[0] * .[1]' /etc/docker/daemon.json /etc/docker/daemon.json.coolify) >/etc/docker/daemon.json -DIFF=$(diff <(jq --sort-keys . /etc/docker/daemon.json) <(jq --sort-keys . /etc/docker/daemon.json.original-$DATE)) -if [ "$DIFF" != "" ]; then + +if [ -s /etc/docker/daemon.json.original-$DATE ]; then + DIFF=$(diff <(jq --sort-keys . /etc/docker/daemon.json) <(jq --sort-keys . /etc/docker/daemon.json.original-$DATE)) + if [ "$DIFF" != "" ]; then + echo "Docker configuration updated, restart docker daemon..." + systemctl restart docker + else + echo "Docker configuration is up to date." + fi +else echo "Docker configuration updated, restart docker daemon..." systemctl restart docker -else - echo "Docker configuration is up to date." fi + echo -e "-------------" mkdir -p /data/coolify/ssh/keys From 84e5b39830521655e401ce1bb95a6c6dc4124194 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:07:52 +0200 Subject: [PATCH 05/12] fix: prevent sync version (it needs an option) --- app/Console/Commands/SyncBunny.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/SyncBunny.php b/app/Console/Commands/SyncBunny.php index 85c29d243..6b68a6519 100644 --- a/app/Console/Commands/SyncBunny.php +++ b/app/Console/Commands/SyncBunny.php @@ -16,7 +16,7 @@ class SyncBunny extends Command * * @var string */ - protected $signature = 'sync:bunny {--only-template}'; + protected $signature = 'sync:bunny {--only-template} {--only-version}'; /** * The console command description. @@ -32,6 +32,7 @@ class SyncBunny extends Command { $that = $this; $only_template = $this->option('only-template'); + $only_version = $this->option('only-version'); $bunny_cdn = "https://cdn.coollabs.io"; $bunny_cdn_path = "coolify"; $bunny_cdn_storage_name = "coolcdn"; @@ -70,7 +71,7 @@ class SyncBunny extends Command ]); }); try { - $confirmed = confirm('Are you sure?'); + $confirmed = confirm('Are you sure you want to sync?'); if (!$confirmed) { return; } @@ -82,6 +83,14 @@ class SyncBunny extends Command $this->info('Service template uploaded & purged...'); return; } + if ($only_version) { + Http::pool(fn (Pool $pool) => [ + $pool->storage(fileName: "$parent_dir/$versions")->put("/$bunny_cdn_storage_name/$bunny_cdn_path/$versions"), + $pool->purge("$bunny_cdn/$bunny_cdn_path/$versions"), + ]); + $this->info('versions.json 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"), @@ -89,7 +98,6 @@ class SyncBunny extends Command $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"), @@ -97,7 +105,6 @@ class SyncBunny extends Command $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) { From e22c5d22f58961ed839185063d43669acee33451 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:13:21 +0200 Subject: [PATCH 06/12] fix: instance fqdn setting --- app/Http/Livewire/Settings/Configuration.php | 5 ++--- resources/views/livewire/settings/configuration.blade.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Settings/Configuration.php b/app/Http/Livewire/Settings/Configuration.php index 6f5fd3475..668c3d5c4 100644 --- a/app/Http/Livewire/Settings/Configuration.php +++ b/app/Http/Livewire/Settings/Configuration.php @@ -73,7 +73,7 @@ class Configuration extends Component { $file = "$this->dynamic_config_path/coolify.yaml"; if (empty($this->settings->fqdn)) { - remote_process([ + instant_remote_process([ "rm -f $file", ], $this->server); } else { @@ -129,7 +129,6 @@ class Configuration extends Component ]; } $this->save_configuration_to_disk($traefik_dynamic_conf, $file); - dispatch(new ContainerStatusJob($this->server)); } } @@ -142,7 +141,7 @@ class Configuration extends Component $yaml; $base64 = base64_encode($yaml); - remote_process([ + instant_remote_process([ "mkdir -p $this->dynamic_config_path", "echo '$base64' | base64 -d > $file", ], $this->server); diff --git a/resources/views/livewire/settings/configuration.blade.php b/resources/views/livewire/settings/configuration.blade.php index a5a0a60ef..752c8efb2 100644 --- a/resources/views/livewire/settings/configuration.blade.php +++ b/resources/views/livewire/settings/configuration.blade.php @@ -6,7 +6,7 @@ Save -
General configuration for your Coolify instance.
+
General configuration for your Coolify instance.
From 9b6c16222499e7fbcd707f7e955d3c6837e357e6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:15:14 +0200 Subject: [PATCH 07/12] fix: sentry 4510197209 --- app/Http/Livewire/Project/Service/Show.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/Project/Service/Show.php b/app/Http/Livewire/Project/Service/Show.php index 7a9e62df2..656adff0a 100644 --- a/app/Http/Livewire/Project/Service/Show.php +++ b/app/Http/Livewire/Project/Service/Show.php @@ -11,8 +11,8 @@ use Livewire\Component; class Show extends Component { public Service $service; - public ServiceApplication $serviceApplication; - public ServiceDatabase $serviceDatabase; + public ?ServiceApplication $serviceApplication = null; + public ?ServiceDatabase $serviceDatabase = null; public array $parameters; public array $query; public Collection $services; From 1a04a57c0186470ba314e136d3fdec48177110a6 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:40:58 +0200 Subject: [PATCH 08/12] fix: sentry 4504136641 --- app/Http/Livewire/Server/ShowPrivateKey.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/Server/ShowPrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php index a0aa6e1e2..c9c11becb 100644 --- a/app/Http/Livewire/Server/ShowPrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -14,8 +14,8 @@ class ShowPrivateKey extends Component public function setPrivateKey($newPrivateKeyId) { try { - refresh_server_connection($this->server->privateKey); $oldPrivateKeyId = $this->server->private_key_id; + refresh_server_connection($this->server->privateKey); $this->server->update([ 'private_key_id' => $newPrivateKeyId ]); From 5040ddea288b6bc94603a624c546511a186598c7 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 13:46:53 +0200 Subject: [PATCH 09/12] fix: sentry 4502634789 --- app/Http/Livewire/Boarding/Index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index c1ec202cf..d124e6a89 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -129,6 +129,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== public function selectExistingPrivateKey() { $this->createdPrivateKey = PrivateKey::find($this->selectedExistingPrivateKey); + $this->privateKey = $this->createdPrivateKey->private_key; $this->currentState = 'create-server'; } public function createNewServer() From c7946e7551c822048ec256eedafd21e6ed6e38fb Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 21:52:50 +0200 Subject: [PATCH 10/12] fix: next helper image --- .github/workflows/coolify-helper-next.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coolify-helper-next.yml b/.github/workflows/coolify-helper-next.yml index ef7f5b217..fe14ba759 100644 --- a/.github/workflows/coolify-helper-next.yml +++ b/.github/workflows/coolify-helper-next.yml @@ -4,7 +4,7 @@ on: push: branches: [ "next" ] paths: - - .github/workflows/coolify-helper.yml + - .github/workflows/coolify-helper-next.yml - docker/coolify-helper/Dockerfile env: From 91e1eb7664be5104deae6fe4c68ff17ce46f430e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 21:56:34 +0200 Subject: [PATCH 11/12] fix --- app/Models/Application.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index 1cdfdea29..b08561ef7 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -212,13 +212,9 @@ class Application extends BaseModel { if (data_get($this, 'private_key_id')) { return 'deploy_key'; - } - if (data_get($this, 'source')) { + } else if (data_get($this, 'source')) { return 'source'; } - if (data_get($this, 'private_key_id')) { - return 'deploy_key'; - } throw new \Exception('No deployment type found'); } public function could_set_build_commands(): bool From 38a22dcf4d72e014c6ef6a22c2d9e0362120c642 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 28 Sep 2023 22:20:49 +0200 Subject: [PATCH 12/12] fix: service templates --- app/Console/Commands/SyncBunny.php | 8 ++++---- app/Http/Controllers/ProjectController.php | 7 ++++--- app/Http/Livewire/Project/New/Select.php | 23 ++-------------------- bootstrap/helpers/shared.php | 15 ++++++++++++++ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/SyncBunny.php b/app/Console/Commands/SyncBunny.php index 6b68a6519..a64da5a35 100644 --- a/app/Console/Commands/SyncBunny.php +++ b/app/Console/Commands/SyncBunny.php @@ -48,15 +48,15 @@ class SyncBunny extends Command $versions = "versions.json"; - PendingRequest::macro('storage', function ($fileName) use($that) { + PendingRequest::macro('storage', function ($file) 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); + $fileStream = fopen($file, "r"); + $file = fread($fileStream, filesize($file)); + $that->info('Uploading: ' . $file); return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw(); }); PendingRequest::macro('purge', function ($url) use ($that) { diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 48bf7909e..0e4c0e2c7 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -45,10 +45,10 @@ class ProjectController extends Controller public function new() { - $services = Cache::get('services', []); + $services = getServiceTemplates(); $type = Str::of(request()->query('type')); $destination_uuid = request()->query('destination'); - $server_id = request()->query('server'); + $server_id = request()->query('server_id'); $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (!$project) { @@ -66,9 +66,10 @@ class ProjectController extends Controller 'database_uuid' => $standalone_postgresql->uuid, ]); } - if ($type->startsWith('one-click-service-')) { + if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) { $oneClickServiceName = $type->after('one-click-service-')->value(); $oneClickService = data_get($services, "$oneClickServiceName.compose"); + ray($oneClickServiceName); $oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null); if ($oneClickDotEnvs) { $oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); diff --git a/app/Http/Livewire/Project/New/Select.php b/app/Http/Livewire/Project/New/Select.php index 945c646df..4a40c6b35 100644 --- a/app/Http/Livewire/Project/New/Select.php +++ b/app/Http/Livewire/Project/New/Select.php @@ -60,28 +60,9 @@ class Select extends Component if ($forceReload) { Cache::forget('services'); } - if (isDev()) { - $cached = Cache::remember('services', 3600, function () { - $services = File::get(base_path('templates/service-templates.json')); - $services = collect(json_decode($services))->sortKeys(); - $this->emit('success', 'Successfully reloaded services from filesystem (development mode).'); - return $services; - }); - } else { - $cached = Cache::remember('services', 3600, function () { - $services = Http::get(config('constants.services.official')); - if ($services->failed()) { - throw new \Exception($services->body()); - } - - $services = collect($services->json())->sortKeys(); - $this->emit('success', 'Successfully reloaded services from the internet.'); - return $services; - }); - } - $this->services = $cached; + $this->services = getServiceTemplates(); + $this->emit('success', 'Successfully loaded services.'); } catch (\Throwable $e) { - ray($e); return handleError($e, $this); } finally { $this->loadingServices = false; diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 946fa198f..5c19b408d 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -406,3 +406,18 @@ function sslip(Server $server) } return "{$server->ip}.sslip.io"; } + +function getServiceTemplates() +{ + if (isDev()) { + $services = File::get(base_path('templates/service-templates.json')); + $services = collect(json_decode($services))->sortKeys(); + } else { + $services = Http::get(config('constants.services.official')); + if ($services->failed()) { + throw new \Exception($services->body()); + } + $services = collect($services->json())->sortKeys(); + } + return $services; +}