From f0adf10e6ac0615935cf1178ff35d1999235a6f8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 14:11:22 +0200 Subject: [PATCH 01/13] 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 e1e34c182..417d21025 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.33', + 'release' => '4.0.0-beta.34', 'server_name' => env('APP_ID', 'coolify'), // 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 c3d0beeb6..44c9c0c1a 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Mon, 11 Sep 2023 15:53:05 +0200 Subject: [PATCH 02/13] wip: nixpacksarchive --- .../Livewire/Project/Application/General.php | 2 + app/Http/Middleware/IsBoardingFlow.php | 2 +- app/Jobs/ApplicationDeploymentJob.php | 10 ++ composer.json | 3 +- composer.lock | 112 +++++++++++++++++- ...057_add_nixpkgsarchive_to_applications.php | 22 ++++ docker/coolify-helper/Dockerfile | 2 +- docker/testing-host/Dockerfile | 2 +- .../project/application/general.blade.php | 16 ++- 9 files changed, 161 insertions(+), 10 deletions(-) create mode 100644 database/migrations/2023_08_22_071057_add_nixpkgsarchive_to_applications.php diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index 80054d5db..13d73c36e 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -48,6 +48,7 @@ class General extends Component 'application.ports_exposes' => 'required', 'application.ports_mappings' => 'nullable', 'application.dockerfile' => 'nullable', + 'application.nixpkgsarchive' => 'nullable', ]; protected $validationAttributes = [ 'application.name' => 'name', @@ -66,6 +67,7 @@ class General extends Component 'application.ports_exposes' => 'Ports exposes', 'application.ports_mappings' => 'Ports mappings', 'application.dockerfile' => 'Dockerfile', + 'application.nixpkgsarchive' => 'Nixpkgs archive', ]; public function instantSave() diff --git a/app/Http/Middleware/IsBoardingFlow.php b/app/Http/Middleware/IsBoardingFlow.php index e0542a57a..5858fe191 100644 --- a/app/Http/Middleware/IsBoardingFlow.php +++ b/app/Http/Middleware/IsBoardingFlow.php @@ -15,7 +15,7 @@ class IsBoardingFlow */ public function handle(Request $request, Closure $next): Response { - ray()->showQueries()->color('orange'); + // ray()->showQueries()->color('orange'); if (showBoarding() && !in_array($request->path(), allowedPathsForBoardingAccounts())) { return redirect('boarding'); } diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index d5431b0e8..53a6c1406 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -28,6 +28,8 @@ use Spatie\Url\Url; use Symfony\Component\Yaml\Yaml; use Throwable; use Visus\Cuid2\Cuid2; +use Yosymfony\Toml\Toml; +use Yosymfony\Toml\TomlArray; class ApplicationDeploymentJob implements ShouldQueue { @@ -411,6 +413,7 @@ class ApplicationDeploymentJob implements ShouldQueue private function generate_nixpacks_confs() { + ray('nixpkgsarchive', $this->application->nixpkgsarchive); $this->execute_remote_command( [ "echo -n 'Generating nixpacks configuration.'", @@ -419,6 +422,13 @@ class ApplicationDeploymentJob implements ShouldQueue [$this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile")], [$this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile")] ); + + // if ($this->application->nixpkgsarchive) { + // $this->execute_remote_command([ + // $this->execute_in_builder("cat {$this->workdir}/nixpacks.toml"), "hidden" => true, "save" => 'nixpacks_toml' + // ]); + + // } } private function nixpacks_build_cmd() diff --git a/composer.json b/composer.json index c8acddbe5..79f3793dd 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,8 @@ "spatie/url": "^2.2", "stripe/stripe-php": "^12.0", "symfony/yaml": "^6.2", - "visus/cuid2": "^2.0.0" + "visus/cuid2": "^2.0.0", + "yosymfony/toml": "^1.0" }, "require-dev": { "fakerphp/faker": "^v1.21.0", diff --git a/composer.lock b/composer.lock index cef0f8b2b..63d0c626d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0603276b60e77cd859fabacdaaf31550", + "content-hash": "cf138424c896f30b035bc8cdff63e8d1", "packages": [ { "name": "aws/aws-crt-php", @@ -9771,6 +9771,116 @@ }, "time": "2022-06-03T18:03:27+00:00" }, + { + "name": "yosymfony/parser-utils", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/yosymfony/parser-utils.git", + "reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yosymfony/parser-utils/zipball/00bec9a12722b21f2baf7f9db35f127e90c162c9", + "reference": "00bec9a12722b21f2baf7f9db35f127e90c162c9", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Yosymfony\\ParserUtils\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Victor Puertas", + "email": "vpgugr@gmail.com", + "homepage": "http://yosymfony.com" + } + ], + "description": "Parser utilities", + "homepage": "http://github.com/yosymfony/toml", + "keywords": [ + "lexer", + "parser" + ], + "support": { + "issues": "https://github.com/yosymfony/parser-utils/issues", + "source": "https://github.com/yosymfony/parser-utils/tree/master" + }, + "time": "2018-06-29T15:31:11+00:00" + }, + { + "name": "yosymfony/toml", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/yosymfony/toml.git", + "reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yosymfony/toml/zipball/bdab92ad920d0e36810a3a3e4a998d23f3498f8e", + "reference": "bdab92ad920d0e36810a3a3e4a998d23f3498f8e", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "yosymfony/parser-utils": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Yosymfony\\Toml\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Victor Puertas", + "email": "vpgugr@gmail.com", + "homepage": "http://yosymfony.com" + } + ], + "description": "A PHP parser for TOML compatible with specification 0.4.0", + "homepage": "http://github.com/yosymfony/toml", + "keywords": [ + "mojombo", + "parser", + "toml" + ], + "support": { + "issues": "https://github.com/yosymfony/toml/issues", + "source": "https://github.com/yosymfony/toml/tree/master" + }, + "time": "2018-08-08T15:08:14+00:00" + }, { "name": "zbateson/mail-mime-parser", "version": "2.4.0", diff --git a/database/migrations/2023_08_22_071057_add_nixpkgsarchive_to_applications.php b/database/migrations/2023_08_22_071057_add_nixpkgsarchive_to_applications.php new file mode 100644 index 000000000..4c3b283db --- /dev/null +++ b/database/migrations/2023_08_22_071057_add_nixpkgsarchive_to_applications.php @@ -0,0 +1,22 @@ +string('nixpkgsarchive')->nullable(); + }); + } + + public function down(): void + { + Schema::table('teams', function (Blueprint $table) { + $table->dropColumn('nixpkgsarchive'); + }); + } +}; diff --git a/docker/coolify-helper/Dockerfile b/docker/coolify-helper/Dockerfile index 301322c63..45834de78 100644 --- a/docker/coolify-helper/Dockerfile +++ b/docker/coolify-helper/Dockerfile @@ -10,7 +10,7 @@ ARG DOCKER_BUILDX_VERSION=0.11.2 # https://github.com/buildpacks/pack/releases ARG PACK_VERSION=0.30.0 # https://github.com/railwayapp/nixpacks/releases -ARG NIXPACKS_VERSION=1.13.0 +ARG NIXPACKS_VERSION=1.14.0 USER root WORKDIR /artifacts diff --git a/docker/testing-host/Dockerfile b/docker/testing-host/Dockerfile index 6783e4f69..3a1e053a5 100644 --- a/docker/testing-host/Dockerfile +++ b/docker/testing-host/Dockerfile @@ -10,7 +10,7 @@ ARG DOCKER_BUILDX_VERSION=0.11.2 # https://github.com/buildpacks/pack/releases ARG PACK_VERSION=0.30.0 # https://github.com/railwayapp/nixpacks/releases -ARG NIXPACKS_VERSION=1.13.0 +ARG NIXPACKS_VERSION=1.14.0 USER root WORKDIR /root diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index f8d5aff37..768f19d7e 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -26,11 +26,17 @@ @endif @endif - - - - - +
+ + + + + + {{-- @if ($application->build_pack === 'nixpacks') + + @endif --}} +
@if ($application->settings->is_static) From f4fb519d555b64182e44424b451d6a67e8f360ab Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 16:41:43 +0200 Subject: [PATCH 03/13] internal: add Plausible analytics --- resources/views/layouts/base.blade.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 6c69eecc3..7f07b857b 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -20,6 +20,9 @@ } @livewireStyles + @if (config('app.name') == 'Coolify Cloud') + + @endif @section('body') From 363f525ad1f4ef340ac37364a8680a7df6306763 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 16:51:38 +0200 Subject: [PATCH 04/13] fix: sentry 4469575117 --- routes/web.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index 6094a4a43..a18af5df0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -49,7 +49,7 @@ Route::post('/forgot-password', function (Request $request) { return response()->json(['message' => 'Transactional emails are not active'], 400); })->name('password.forgot'); Route::get('/waitlist', WaitlistIndex::class)->name('waitlist.index'); -Route::middleware(['throttle:login'])->group(function() { +Route::middleware(['throttle:login'])->group(function () { Route::get('/auth/link', [Controller::class, 'link'])->name('auth.link'); }); Route::prefix('magic')->middleware(['auth'])->group(function () { @@ -143,7 +143,11 @@ Route::middleware(['auth'])->group(function () { ]); })->name('source.all'); Route::get('/source/github/{github_app_uuid}', function (Request $request) { - $github_app = GithubApp::where('uuid', request()->github_app_uuid)->first()->makeVisible('client_secret')->makeVisible('webhook_secret'); + $github_app = GithubApp::where('uuid', request()->github_app_uuid)->first(); + if (!$github_app) { + abort(404); + } + $github_app->makeVisible('client_secret')->makeVisible('webhook_secret'); $settings = InstanceSettings::get(); $name = Str::of(Str::kebab($github_app->name)); if ($settings->public_ipv4) { From 16c71f364787e805170a8e98b62e720e5abeca19 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 17:19:30 +0200 Subject: [PATCH 05/13] fix: old docker version error --- app/Http/Livewire/Server/Form.php | 5 +++-- app/Http/Livewire/Server/ShowPrivateKey.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index 76dbb1a06..b3346fa23 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -56,14 +56,15 @@ class Form extends Component $this->uptime = $uptime; $this->emit('success', 'Server is reachable!'); } else { - throw new \Exception('Server is not rachable'); + $this->emit('error', 'Server is not rachable'); + return; } if ($dockerVersion) { $this->dockerVersion = $dockerVersion; $this->emit('proxyStatusUpdated'); $this->emit('success', 'Docker Engine 23+ is installed!'); } else { - throw new \Exception('Old Docker version detected (lower than 23).'); + $this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.'); } } catch (\Exception $e) { return general_error_handler($e, that: $this); diff --git a/app/Http/Livewire/Server/ShowPrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php index fe75d8cfd..993afde00 100644 --- a/app/Http/Livewire/Server/ShowPrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -38,12 +38,13 @@ class ShowPrivateKey extends Component if ($uptime) { $this->emit('success', 'Server is reachable with this private key.'); } else { - throw new \Exception('Server is not reachable with this private key.'); + $this->emit('error', 'Server is not reachable with this private key.'); + return; } if ($dockerVersion) { $this->emit('success', 'Server is usable for Coolify.'); } else { - throw new \Exception('Old Docker version detected (lower than 23).'); + $this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.'); } } catch (\Exception $e) { throw new \Exception($e->getMessage()); From 64a65e201803b9a2c3b0c02a716e64ba93cc1b21 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 17:36:30 +0200 Subject: [PATCH 06/13] fix: errors --- app/Actions/CoolifyTask/RunRemoteProcess.php | 1 - app/Actions/License/CheckResaleLicense.php | 6 ++--- app/Actions/Proxy/SaveConfigurationSync.php | 4 ++-- app/Actions/Server/UpdateCoolify.php | 8 +++---- app/Console/Commands/Init.php | 2 +- app/Console/Commands/SyncBunny.php | 2 +- app/Exceptions/Handler.php | 2 +- app/Exceptions/ProcessException.php | 10 +++++++++ app/Http/Controllers/Controller.php | 8 +++---- app/Http/Livewire/Boarding/Index.php | 2 +- app/Http/Livewire/CheckLicense.php | 6 ++--- app/Http/Livewire/Destination/Form.php | 2 +- .../Destination/New/StandaloneDocker.php | 2 +- app/Http/Livewire/ForcePasswordReset.php | 2 +- app/Http/Livewire/Help.php | 2 +- .../Notifications/DiscordSettings.php | 2 +- .../Livewire/Notifications/EmailSettings.php | 12 +++++----- .../Notifications/TelegramSettings.php | 2 +- app/Http/Livewire/PrivateKey/Change.php | 4 ++-- app/Http/Livewire/PrivateKey/Create.php | 2 +- app/Http/Livewire/Project/AddEmpty.php | 2 +- app/Http/Livewire/Project/AddEnvironment.php | 2 +- .../Livewire/Project/Application/General.php | 2 +- .../Livewire/Project/Database/BackupEdit.php | 4 ++-- .../Database/CreateScheduledBackup.php | 2 +- app/Http/Livewire/Project/Edit.php | 2 +- .../Project/New/GithubPrivateRepository.php | 2 +- .../New/GithubPrivateRepositoryDeployKey.php | 2 +- .../Project/New/PublicGitRepository.php | 6 ++--- app/Http/Livewire/Project/New/Select.php | 2 +- .../Shared/EnvironmentVariable/All.php | 2 +- .../Project/Shared/ResourceLimits.php | 2 +- .../Livewire/Project/Shared/Storages/All.php | 2 +- app/Http/Livewire/RunCommand.php | 2 +- app/Http/Livewire/Server/Form.php | 4 ++-- app/Http/Livewire/Server/New/ByIp.php | 2 +- app/Http/Livewire/Server/Proxy.php | 6 ++--- app/Http/Livewire/Server/ShowPrivateKey.php | 4 ++-- app/Http/Livewire/Settings/Email.php | 10 ++++----- app/Http/Livewire/Source/Github/Change.php | 4 ++-- app/Http/Livewire/Source/Github/Create.php | 2 +- app/Http/Livewire/Subscription/Actions.php | 4 ++-- app/Http/Livewire/Team/Create.php | 4 ++-- app/Http/Livewire/Team/Form.php | 4 ++-- app/Http/Livewire/Team/Storage/Create.php | 8 +++---- app/Http/Livewire/Team/Storage/Form.php | 12 +++++----- app/Http/Livewire/Upgrade.php | 2 +- app/Http/Livewire/Waitlist/Index.php | 2 +- app/Jobs/ApplicationContainerStatusJob.php | 6 ++--- app/Jobs/ApplicationPullRequestUpdateJob.php | 2 +- app/Jobs/CheckResaleLicenseJob.php | 8 +++---- app/Jobs/CleanupInstanceStuffsJob.php | 2 +- app/Jobs/DatabaseBackupJob.php | 20 ++++++++--------- app/Jobs/DatabaseContainerStatusJob.php | 2 +- app/Jobs/DockerCleanupJob.php | 2 +- app/Jobs/ProxyCheckJob.php | 8 +++---- app/Jobs/ProxyContainerStatusJob.php | 2 +- app/Jobs/ProxyStartJob.php | 8 +++---- app/Jobs/ResourceStatusJob.php | 8 +++---- app/Jobs/SendConfirmationForWaitlistJob.php | 8 +++---- app/Jobs/SubscriptionInvoiceFailedJob.php | 8 +++---- app/Models/PrivateKey.php | 2 +- bootstrap/helpers/docker.php | 2 +- bootstrap/helpers/remoteProcess.php | 6 ++--- bootstrap/helpers/shared.php | 22 +++++++++---------- database/seeders/InstanceSettingsSeeder.php | 2 +- database/seeders/ProductionSeeder.php | 2 +- 67 files changed, 156 insertions(+), 147 deletions(-) create mode 100644 app/Exceptions/ProcessException.php diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php index 192144f8b..1444684a0 100644 --- a/app/Actions/CoolifyTask/RunRemoteProcess.php +++ b/app/Actions/CoolifyTask/RunRemoteProcess.php @@ -97,7 +97,6 @@ class RunRemoteProcess 'status' => $status->value, ]); $this->activity->save(); - if ($processResult->exitCode() != 0 && !$this->ignore_errors) { throw new \RuntimeException($processResult->errorOutput()); } diff --git a/app/Actions/License/CheckResaleLicense.php b/app/Actions/License/CheckResaleLicense.php index 54f97c834..8dd456ccd 100644 --- a/app/Actions/License/CheckResaleLicense.php +++ b/app/Actions/License/CheckResaleLicense.php @@ -57,13 +57,13 @@ class CheckResaleLicense throw new \Exception('Invalid license key.'); } throw new \Exception('Cannot activate license key.'); - } catch (\Throwable $th) { - ray($th); + } catch (\Throwable $e) { + ray($e); $settings->update([ 'resale_license' => null, 'is_resale_license_active' => false, ]); - throw $th; + throw $e; } } } diff --git a/app/Actions/Proxy/SaveConfigurationSync.php b/app/Actions/Proxy/SaveConfigurationSync.php index b35b4375b..8be3ca9db 100644 --- a/app/Actions/Proxy/SaveConfigurationSync.php +++ b/app/Actions/Proxy/SaveConfigurationSync.php @@ -20,8 +20,8 @@ class SaveConfigurationSync "mkdir -p $proxy_path", "echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml", ], $server); - } catch (\Throwable $th) { - ray($th); + } catch (\Throwable $e) { + ray($e); } } diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php index de4700b75..bdf8275c7 100644 --- a/app/Actions/Server/UpdateCoolify.php +++ b/app/Actions/Server/UpdateCoolify.php @@ -43,11 +43,11 @@ class UpdateCoolify $this->update(); } send_internal_notification('InstanceAutoUpdateJob done to version: ' . $this->latestVersion . ' from version: ' . $this->currentVersion); - } catch (\Exception $th) { + } catch (\Throwable $e) { ray('InstanceAutoUpdateJob failed'); - ray($th->getMessage()); - send_internal_notification('InstanceAutoUpdateJob failed: ' . $th->getMessage()); - throw $th; + ray($e->getMessage()); + send_internal_notification('InstanceAutoUpdateJob failed: ' . $e->getMessage()); + throw $e; } } diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index ae682e682..446b0c693 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -26,7 +26,7 @@ class Init extends Command $deployment->status = ApplicationDeploymentStatus::FAILED->value; $deployment->save(); } - } catch (\Exception $e) { + } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; } } diff --git a/app/Console/Commands/SyncBunny.php b/app/Console/Commands/SyncBunny.php index 3f4bc412a..4a9945ece 100644 --- a/app/Console/Commands/SyncBunny.php +++ b/app/Console/Commands/SyncBunny.php @@ -82,7 +82,7 @@ class SyncBunny extends Command $pool->purge("$bunny_cdn/$bunny_cdn_path/$versions"), ]); echo "All files uploaded & purged...\n"; - } catch (\Exception $e) { + } catch (\Throwable $e) { echo $e->getMessage(); } } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index d8cf0c9cf..17db86d13 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -25,7 +25,7 @@ class Handler extends ExceptionHandler * @var array> */ protected $dontReport = [ - // + ProcessException::class ]; /** * A list of the inputs that are never flashed to the session on validation exceptions. diff --git a/app/Exceptions/ProcessException.php b/app/Exceptions/ProcessException.php new file mode 100644 index 000000000..68dbb53b2 --- /dev/null +++ b/app/Exceptions/ProcessException.php @@ -0,0 +1,10 @@ +delete(); abort(401); } - } catch (Throwable $th) { - throw $th; + } catch (Throwable $e) { + throw $e; } } @@ -172,8 +172,8 @@ class Controller extends BaseController } $invitation->delete(); return redirect()->route('team.index'); - } catch (Throwable $th) { - throw $th; + } catch (Throwable $e) { + throw $e; } } } diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index 44b45dee7..2cb3b1049 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -193,7 +193,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== } $this->getProxyType(); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this); } } diff --git a/app/Http/Livewire/CheckLicense.php b/app/Http/Livewire/CheckLicense.php index 3afefed34..3c5d1b8f2 100644 --- a/app/Http/Livewire/CheckLicense.php +++ b/app/Http/Livewire/CheckLicense.php @@ -34,9 +34,9 @@ class CheckLicense extends Component try { resolve(CheckResaleLicense::class)(); $this->emit('reloadWindow'); - } catch (\Throwable $th) { - session()->flash('error', 'Something went wrong. Please contact support.
Error: ' . $th->getMessage()); - ray($th->getMessage()); + } catch (\Throwable $e) { + session()->flash('error', 'Something went wrong. Please contact support.
Error: ' . $e->getMessage()); + ray($e->getMessage()); return redirect()->to('/settings/license'); } } diff --git a/app/Http/Livewire/Destination/Form.php b/app/Http/Livewire/Destination/Form.php index 56c7ba5ed..9bfb8cf74 100644 --- a/app/Http/Livewire/Destination/Form.php +++ b/app/Http/Livewire/Destination/Form.php @@ -37,7 +37,7 @@ class Form extends Component } $this->destination->delete(); return redirect()->route('dashboard'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php index 1af7bc2df..519b1e700 100644 --- a/app/Http/Livewire/Destination/New/StandaloneDocker.php +++ b/app/Http/Livewire/Destination/New/StandaloneDocker.php @@ -71,7 +71,7 @@ class StandaloneDocker extends Component } $this->createNetworkAndAttachToProxy(); return redirect()->route('destination.show', $docker->uuid); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/ForcePasswordReset.php b/app/Http/Livewire/ForcePasswordReset.php index df2b37691..732859280 100644 --- a/app/Http/Livewire/ForcePasswordReset.php +++ b/app/Http/Livewire/ForcePasswordReset.php @@ -36,7 +36,7 @@ class ForcePasswordReset extends Component send_internal_notification('First login for ' . auth()->user()->email); } return redirect()->route('dashboard'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Help.php b/app/Http/Livewire/Help.php index 107821501..9f3ca434f 100644 --- a/app/Http/Livewire/Help.php +++ b/app/Http/Livewire/Help.php @@ -43,7 +43,7 @@ class Help extends Component $mail->subject("[HELP - {$subscriptionType}]: {$this->subject}"); send_user_an_email($mail, 'hi@coollabs.io'); $this->emit('success', 'Your message has been sent successfully. We will get in touch with you as soon as possible.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } diff --git a/app/Http/Livewire/Notifications/DiscordSettings.php b/app/Http/Livewire/Notifications/DiscordSettings.php index cd7a413a5..97a8878f1 100644 --- a/app/Http/Livewire/Notifications/DiscordSettings.php +++ b/app/Http/Livewire/Notifications/DiscordSettings.php @@ -29,7 +29,7 @@ class DiscordSettings extends Component { try { $this->submit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { ray($e->getMessage()); $this->team->discord_enabled = false; $this->validate(); diff --git a/app/Http/Livewire/Notifications/EmailSettings.php b/app/Http/Livewire/Notifications/EmailSettings.php index 4ef735a04..939b8bce0 100644 --- a/app/Http/Livewire/Notifications/EmailSettings.php +++ b/app/Http/Livewire/Notifications/EmailSettings.php @@ -63,7 +63,7 @@ class EmailSettings extends Component ]); $this->team->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -82,7 +82,7 @@ class EmailSettings extends Component $this->team->resend_enabled = false; $this->team->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -92,7 +92,7 @@ class EmailSettings extends Component try { $this->team->smtp_enabled = false; $this->submitResend(); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->team->smtp_enabled = false; return general_error_handler($e, $this); } @@ -102,7 +102,7 @@ class EmailSettings extends Component try { $this->team->resend_enabled = false; $this->submit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->team->smtp_enabled = false; return general_error_handler($e, $this); } @@ -131,7 +131,7 @@ class EmailSettings extends Component ]); $this->team->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->team->smtp_enabled = false; return general_error_handler($e, $this); } @@ -146,7 +146,7 @@ class EmailSettings extends Component $this->team->save(); refreshSession(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->team->resend_enabled = false; return general_error_handler($e, $this); } diff --git a/app/Http/Livewire/Notifications/TelegramSettings.php b/app/Http/Livewire/Notifications/TelegramSettings.php index d6c6c8395..15dca1490 100644 --- a/app/Http/Livewire/Notifications/TelegramSettings.php +++ b/app/Http/Livewire/Notifications/TelegramSettings.php @@ -35,7 +35,7 @@ class TelegramSettings extends Component { try { $this->submit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { ray($e->getMessage()); $this->team->telegram_enabled = false; $this->validate(); diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php index 6c849b0a9..a85bac8d2 100644 --- a/app/Http/Livewire/PrivateKey/Change.php +++ b/app/Http/Livewire/PrivateKey/Change.php @@ -38,7 +38,7 @@ class Change extends Component return redirect()->route('security.private-key.index'); } $this->emit('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } @@ -49,7 +49,7 @@ class Change extends Component $this->private_key->private_key = formatPrivateKey($this->private_key->private_key); $this->private_key->save(); refresh_server_connection($this->private_key); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.php index eac749399..37363195d 100644 --- a/app/Http/Livewire/PrivateKey/Create.php +++ b/app/Http/Livewire/PrivateKey/Create.php @@ -38,7 +38,7 @@ class Create extends Component return redirect()->route('server.create'); } return redirect()->route('security.private-key.show', ['private_key_uuid' => $private_key->uuid]); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/AddEmpty.php b/app/Http/Livewire/Project/AddEmpty.php index fc20f9850..8d2399a47 100644 --- a/app/Http/Livewire/Project/AddEmpty.php +++ b/app/Http/Livewire/Project/AddEmpty.php @@ -28,7 +28,7 @@ class AddEmpty extends Component 'team_id' => currentTeam()->id, ]); return redirect()->route('project.show', $project->uuid); - } catch (\Exception $e) { + } catch (\Throwable $e) { general_error_handler($e, $this); } finally { $this->name = ''; diff --git a/app/Http/Livewire/Project/AddEnvironment.php b/app/Http/Livewire/Project/AddEnvironment.php index ea38df073..fc0ac61c6 100644 --- a/app/Http/Livewire/Project/AddEnvironment.php +++ b/app/Http/Livewire/Project/AddEnvironment.php @@ -31,7 +31,7 @@ class AddEnvironment extends Component 'project_uuid' => $this->project->uuid, 'environment_name' => $environment->name, ]); - } catch (\Exception $e) { + } catch (\Throwable $e) { general_error_handler($e, $this); } finally { $this->name = ''; diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index 13d73c36e..0f68a8a2c 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -161,7 +161,7 @@ class General extends Component } $this->application->save(); $this->emit('success', 'Application settings updated!'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/Database/BackupEdit.php b/app/Http/Livewire/Project/Database/BackupEdit.php index 39b29c83f..a8a0ef055 100644 --- a/app/Http/Livewire/Project/Database/BackupEdit.php +++ b/app/Http/Livewire/Project/Database/BackupEdit.php @@ -51,7 +51,7 @@ class BackupEdit extends Component $this->backup->save(); $this->backup->refresh(); $this->emit('success', 'Backup updated successfully'); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->emit('error', $e->getMessage()); } } @@ -76,7 +76,7 @@ class BackupEdit extends Component $this->backup->save(); $this->backup->refresh(); $this->emit('success', 'Backup updated successfully'); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->emit('error', $e->getMessage()); } } diff --git a/app/Http/Livewire/Project/Database/CreateScheduledBackup.php b/app/Http/Livewire/Project/Database/CreateScheduledBackup.php index 9297f65f6..d9887efbf 100644 --- a/app/Http/Livewire/Project/Database/CreateScheduledBackup.php +++ b/app/Http/Livewire/Project/Database/CreateScheduledBackup.php @@ -42,7 +42,7 @@ class CreateScheduledBackup extends Component 'team_id' => currentTeam()->id, ]); $this->emit('refreshScheduledBackups'); - } catch (\Exception $e) { + } catch (\Throwable $e) { general_error_handler($e, $this); } finally { $this->frequency = ''; diff --git a/app/Http/Livewire/Project/Edit.php b/app/Http/Livewire/Project/Edit.php index 60702ca3e..9d5342b5a 100644 --- a/app/Http/Livewire/Project/Edit.php +++ b/app/Http/Livewire/Project/Edit.php @@ -19,7 +19,7 @@ class Edit extends Component try { $this->project->save(); $this->emit('saved'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepository.php b/app/Http/Livewire/Project/New/GithubPrivateRepository.php index dec4e80e8..cf371404a 100644 --- a/app/Http/Livewire/Project/New/GithubPrivateRepository.php +++ b/app/Http/Livewire/Project/New/GithubPrivateRepository.php @@ -164,7 +164,7 @@ class GithubPrivateRepository extends Component 'environment_name' => $environment->name, 'project_uuid' => $project->uuid, ]); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php index d18fe2541..21fa87e42 100644 --- a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php +++ b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php @@ -117,7 +117,7 @@ class GithubPrivateRepositoryDeployKey extends Component 'environment_name' => $environment->name, 'application_uuid' => $application->uuid, ]); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index eb36cb1f1..105a56167 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -75,14 +75,14 @@ class PublicGitRepository extends Component $this->get_git_source(); $this->get_branch(); $this->selected_branch = $this->git_branch; - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } if (!$this->branch_found && $this->git_branch == 'main') { try { $this->git_branch = 'master'; $this->get_branch(); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } @@ -161,7 +161,7 @@ class PublicGitRepository extends Component 'environment_name' => $environment->name, 'application_uuid' => $application->uuid, ]); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/New/Select.php b/app/Http/Livewire/Project/New/Select.php index 0ea7fd8c1..9a64a0e31 100644 --- a/app/Http/Livewire/Project/New/Select.php +++ b/app/Http/Livewire/Project/New/Select.php @@ -40,7 +40,7 @@ class Select extends Component // try { // instantCommand("psql {$this->existingPostgresqlUrl} -c 'SELECT 1'"); // $this->emit('success', 'Successfully connected to the database.'); - // } catch (\Exception $e) { + // } catch (\Throwable $e) { // return general_error_handler($e, $this); // } // } diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php index 899060085..d88a71a1b 100644 --- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -108,7 +108,7 @@ class All extends Component $environment->save(); $this->refreshEnvs(); $this->emit('success', 'Environment variable added successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/Shared/ResourceLimits.php b/app/Http/Livewire/Project/Shared/ResourceLimits.php index 6b4ae7e3a..edf6702c6 100644 --- a/app/Http/Livewire/Project/Shared/ResourceLimits.php +++ b/app/Http/Livewire/Project/Shared/ResourceLimits.php @@ -53,7 +53,7 @@ class ResourceLimits extends Component $this->validate(); $this->resource->save(); $this->emit('success', 'Resource limits updated successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Project/Shared/Storages/All.php b/app/Http/Livewire/Project/Shared/Storages/All.php index ee016143b..db9dd19f5 100644 --- a/app/Http/Livewire/Project/Shared/Storages/All.php +++ b/app/Http/Livewire/Project/Shared/Storages/All.php @@ -28,7 +28,7 @@ class All extends Component $this->resource->refresh(); $this->emit('success', 'Storage added successfully'); $this->emit('clearAddStorage'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/RunCommand.php b/app/Http/Livewire/RunCommand.php index 747ce9568..2f0edc9da 100755 --- a/app/Http/Livewire/RunCommand.php +++ b/app/Http/Livewire/RunCommand.php @@ -32,7 +32,7 @@ class RunCommand extends Component try { $activity = remote_process([$this->command], Server::where('uuid', $this->server)->first(), ignore_errors: true); $this->emit('newMonitorActivity', $activity->id); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index b3346fa23..53cf8234d 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -66,7 +66,7 @@ class Form extends Component } else { $this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.'); } - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, that: $this); } } @@ -81,7 +81,7 @@ class Form extends Component } $this->server->delete(); return redirect()->route('server.all'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Server/New/ByIp.php b/app/Http/Livewire/Server/New/ByIp.php index 7b3297995..d0b44ecaf 100644 --- a/app/Http/Livewire/Server/New/ByIp.php +++ b/app/Http/Livewire/Server/New/ByIp.php @@ -78,7 +78,7 @@ class ByIp extends Component $server->settings->is_part_of_swarm = $this->is_part_of_swarm; $server->settings->save(); return redirect()->route('server.show', $server->uuid); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index 2e8530e1c..c11476d65 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -55,7 +55,7 @@ class Proxy extends Component setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server); $this->emit('success', 'Proxy configuration saved.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } @@ -64,7 +64,7 @@ class Proxy extends Component { try { $this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } @@ -73,7 +73,7 @@ class Proxy extends Component { try { $this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e); } } diff --git a/app/Http/Livewire/Server/ShowPrivateKey.php b/app/Http/Livewire/Server/ShowPrivateKey.php index 993afde00..cfb1cdd67 100644 --- a/app/Http/Livewire/Server/ShowPrivateKey.php +++ b/app/Http/Livewire/Server/ShowPrivateKey.php @@ -21,7 +21,7 @@ class ShowPrivateKey extends Component $this->server->refresh(); refresh_server_connection($this->server->privateKey); $this->checkConnection(); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->server->update([ 'private_key_id' => $oldPrivateKeyId ]); @@ -46,7 +46,7 @@ class ShowPrivateKey extends Component } else { $this->emit('error', 'Old (lower than 23) or no Docker version detected. Install Docker Engine on the General tab.'); } - } catch (\Exception $e) { + } catch (\Throwable $e) { throw new \Exception($e->getMessage()); } } diff --git a/app/Http/Livewire/Settings/Email.php b/app/Http/Livewire/Settings/Email.php index 878b1133f..f03fccc46 100644 --- a/app/Http/Livewire/Settings/Email.php +++ b/app/Http/Livewire/Settings/Email.php @@ -50,7 +50,7 @@ class Email extends Component ]); $this->settings->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -62,7 +62,7 @@ class Email extends Component ]); $this->settings->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { $this->settings->resend_enabled = false; return general_error_handler($e, $this); } @@ -71,7 +71,7 @@ class Email extends Component try { $this->settings->smtp_enabled = false; $this->submitResend(); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -80,7 +80,7 @@ class Email extends Component try { $this->settings->resend_enabled = false; $this->submit(); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -99,7 +99,7 @@ class Email extends Component ]); $this->settings->save(); $this->emit('success', 'Settings saved successfully.'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } diff --git a/app/Http/Livewire/Source/Github/Change.php b/app/Http/Livewire/Source/Github/Change.php index 32f84e8ed..41ce367d9 100644 --- a/app/Http/Livewire/Source/Github/Change.php +++ b/app/Http/Livewire/Source/Github/Change.php @@ -51,7 +51,7 @@ class Change extends Component try { $this->validate(); $this->github_app->save(); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } @@ -65,7 +65,7 @@ class Change extends Component try { $this->github_app->delete(); redirect()->route('source.all'); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Source/Github/Create.php b/app/Http/Livewire/Source/Github/Create.php index c607af451..83e6e2988 100644 --- a/app/Http/Livewire/Source/Github/Create.php +++ b/app/Http/Livewire/Source/Github/Create.php @@ -49,7 +49,7 @@ class Create extends Component session(['from' => session('from') + ['source_id' => $github_app->id]]); } redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Subscription/Actions.php b/app/Http/Livewire/Subscription/Actions.php index 7de0ec728..1ed3ca378 100644 --- a/app/Http/Livewire/Subscription/Actions.php +++ b/app/Http/Livewire/Subscription/Actions.php @@ -30,7 +30,7 @@ class Actions extends Component $this->emit('success', 'Subscription cancelled successfully. Reloading in 5s.'); $this->emit('reloadWindow', 5000); } - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } @@ -65,7 +65,7 @@ class Actions extends Component $this->emit('success', 'Subscription resumed successfully. Reloading in 5s.'); $this->emit('reloadWindow', 5000); } - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler($e, $this); } } diff --git a/app/Http/Livewire/Team/Create.php b/app/Http/Livewire/Team/Create.php index 0e721814c..d5b80e53b 100644 --- a/app/Http/Livewire/Team/Create.php +++ b/app/Http/Livewire/Team/Create.php @@ -31,8 +31,8 @@ class Create extends Component auth()->user()->teams()->attach($team, ['role' => 'admin']); refreshSession(); return redirect()->route('team.index'); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } } diff --git a/app/Http/Livewire/Team/Form.php b/app/Http/Livewire/Team/Form.php index 16aff27ee..212957e44 100644 --- a/app/Http/Livewire/Team/Form.php +++ b/app/Http/Livewire/Team/Form.php @@ -28,8 +28,8 @@ class Form extends Component try { $this->team->save(); refreshSession(); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } } diff --git a/app/Http/Livewire/Team/Storage/Create.php b/app/Http/Livewire/Team/Storage/Create.php index e1330784a..28e6f63c7 100644 --- a/app/Http/Livewire/Team/Storage/Create.php +++ b/app/Http/Livewire/Team/Storage/Create.php @@ -67,8 +67,8 @@ class Create extends Component $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); $this->storage->save(); return redirect()->route('team.storages.show', $this->storage->uuid); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } @@ -77,8 +77,8 @@ class Create extends Component try { $this->storage->testConnection(); return $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } } diff --git a/app/Http/Livewire/Team/Storage/Form.php b/app/Http/Livewire/Team/Storage/Form.php index 3bdbbc508..1572c45ac 100644 --- a/app/Http/Livewire/Team/Storage/Form.php +++ b/app/Http/Livewire/Team/Storage/Form.php @@ -32,8 +32,8 @@ class Form extends Component try { $this->storage->testConnection(); return $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } @@ -42,8 +42,8 @@ class Form extends Component try { $this->storage->delete(); return redirect()->route('team.storages.all'); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } @@ -55,8 +55,8 @@ class Form extends Component $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); $this->storage->save(); $this->emit('success', 'Storage settings saved.'); - } catch (\Throwable $th) { - return general_error_handler($th, $this); + } catch (\Throwable $e) { + return general_error_handler($e, $this); } } } diff --git a/app/Http/Livewire/Upgrade.php b/app/Http/Livewire/Upgrade.php index e79c73fb7..69300b0eb 100644 --- a/app/Http/Livewire/Upgrade.php +++ b/app/Http/Livewire/Upgrade.php @@ -37,7 +37,7 @@ class Upgrade extends Component $this->showProgress = true; resolve(UpdateCoolify::class)(true); Toaster::success("Upgrading to {$this->latestVersion} version..."); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Http/Livewire/Waitlist/Index.php b/app/Http/Livewire/Waitlist/Index.php index 72d16b682..fb040c6d5 100644 --- a/app/Http/Livewire/Waitlist/Index.php +++ b/app/Http/Livewire/Waitlist/Index.php @@ -52,7 +52,7 @@ class Index extends Component $this->emit('success', 'Check your email to verify your email address.'); dispatch(new SendConfirmationForWaitlistJob($this->email, $waitlist->uuid)); - } catch (\Exception $e) { + } catch (\Throwable $e) { return general_error_handler(err: $e, that: $this); } } diff --git a/app/Jobs/ApplicationContainerStatusJob.php b/app/Jobs/ApplicationContainerStatusJob.php index f7496770d..67e629425 100644 --- a/app/Jobs/ApplicationContainerStatusJob.php +++ b/app/Jobs/ApplicationContainerStatusJob.php @@ -46,9 +46,9 @@ class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique $this->application->status = $status; $this->application->save(); } - } catch (\Exception $th) { - ray($th->getMessage()); - throw $th; + } catch (\Throwable $e) { + ray($e->getMessage()); + throw $e; } } } diff --git a/app/Jobs/ApplicationPullRequestUpdateJob.php b/app/Jobs/ApplicationPullRequestUpdateJob.php index f54063183..19fbcd7e7 100755 --- a/app/Jobs/ApplicationPullRequestUpdateJob.php +++ b/app/Jobs/ApplicationPullRequestUpdateJob.php @@ -57,7 +57,7 @@ class ApplicationPullRequestUpdateJob implements ShouldQueue } else { $this->create_comment(); } - } catch (\Exception $e) { + } catch (\Throwable $e) { ray($e); throw $e; } diff --git a/app/Jobs/CheckResaleLicenseJob.php b/app/Jobs/CheckResaleLicenseJob.php index 30f9ff198..fe4eed27f 100644 --- a/app/Jobs/CheckResaleLicenseJob.php +++ b/app/Jobs/CheckResaleLicenseJob.php @@ -21,10 +21,10 @@ class CheckResaleLicenseJob implements ShouldQueue { try { resolve(CheckResaleLicense::class)(); - } catch (\Throwable $th) { - send_internal_notification('CheckResaleLicenseJob failed with: ' . $th->getMessage()); - ray($th); - throw $th; + } catch (\Throwable $e) { + send_internal_notification('CheckResaleLicenseJob failed with: ' . $e->getMessage()); + ray($e); + throw $e; } } } diff --git a/app/Jobs/CleanupInstanceStuffsJob.php b/app/Jobs/CleanupInstanceStuffsJob.php index 96fd490ba..3d08203e3 100644 --- a/app/Jobs/CleanupInstanceStuffsJob.php +++ b/app/Jobs/CleanupInstanceStuffsJob.php @@ -28,7 +28,7 @@ class CleanupInstanceStuffsJob implements ShouldQueue, ShouldBeUnique { try { // $this->cleanup_waitlist(); - } catch (\Exception $e) { + } catch (\Throwable $e) { send_internal_notification('CleanupInstanceStuffsJob failed with error: ' . $e->getMessage()); ray($e->getMessage()); throw $e; diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php index d8ad4ec12..778272705 100644 --- a/app/Jobs/DatabaseBackupJob.php +++ b/app/Jobs/DatabaseBackupJob.php @@ -90,10 +90,10 @@ class DatabaseBackupJob implements ShouldQueue } $this->save_backup_logs(); // TODO: Notify user - } catch (\Throwable $th) { - ray($th->getMessage()); - send_internal_notification('DatabaseBackupJob failed with: ' . $th->getMessage()); - throw $th; + } catch (\Throwable $e) { + ray($e->getMessage()); + send_internal_notification('DatabaseBackupJob failed with: ' . $e->getMessage()); + throw $e; } } @@ -116,10 +116,10 @@ class DatabaseBackupJob implements ShouldQueue $this->backup_status = 'success'; $this->team->notify(new BackupSuccess($this->backup, $this->database)); - } catch (Throwable $th) { + } catch (Throwable $e) { $this->backup_status = 'failed'; - $this->add_to_backup_output($th->getMessage()); - ray('Backup failed for ' . $this->container_name . ' at ' . $this->server->name . ':' . $this->backup_location . '\n\nError:' . $th->getMessage()); + $this->add_to_backup_output($e->getMessage()); + ray('Backup failed for ' . $this->container_name . ' at ' . $this->server->name . ':' . $this->backup_location . '\n\nError:' . $e->getMessage()); $this->team->notify(new BackupFailed($this->backup, $this->database, $this->backup_output)); } finally { $this->backup_log->update([ @@ -173,9 +173,9 @@ class DatabaseBackupJob implements ShouldQueue instant_remote_process($commands, $this->server); $this->add_to_backup_output('Uploaded to S3.'); ray('Uploaded to S3. ' . $this->backup_location . ' to s3://' . $bucket . $this->backup_dir); - } catch (\Throwable $th) { - $this->add_to_backup_output($th->getMessage()); - ray($th->getMessage()); + } catch (\Throwable $e) { + $this->add_to_backup_output($e->getMessage()); + ray($e->getMessage()); } finally { $command = "docker rm -f backup-of-{$this->backup->uuid}"; instant_remote_process([$command], $this->server); diff --git a/app/Jobs/DatabaseContainerStatusJob.php b/app/Jobs/DatabaseContainerStatusJob.php index 1630545c5..d7b4d0085 100644 --- a/app/Jobs/DatabaseContainerStatusJob.php +++ b/app/Jobs/DatabaseContainerStatusJob.php @@ -47,7 +47,7 @@ class DatabaseContainerStatusJob implements ShouldQueue, ShouldBeUnique $this->database->status = $status; $this->database->save(); } - } catch (\Exception $e) { + } catch (\Throwable $e) { send_internal_notification('DatabaseContainerStatusJob failed with: ' . $e->getMessage()); ray($e->getMessage()); throw $e; diff --git a/app/Jobs/DockerCleanupJob.php b/app/Jobs/DockerCleanupJob.php index ecdf6dbcb..fbb9ac2c7 100644 --- a/app/Jobs/DockerCleanupJob.php +++ b/app/Jobs/DockerCleanupJob.php @@ -75,7 +75,7 @@ class DockerCleanupJob implements ShouldQueue ray('No need to clean up ' . $server->name)->color('orange'); } } - } catch (\Exception $e) { + } catch (\Throwable $e) { send_internal_notification('DockerCleanupJob failed with: ' . $e->getMessage()); ray($e->getMessage())->color('orange'); throw $e; diff --git a/app/Jobs/ProxyCheckJob.php b/app/Jobs/ProxyCheckJob.php index 720dd2ea1..65d04bf05 100755 --- a/app/Jobs/ProxyCheckJob.php +++ b/app/Jobs/ProxyCheckJob.php @@ -37,10 +37,10 @@ class ProxyCheckJob implements ShouldQueue resolve(StartProxy::class)($server); } } - } catch (\Throwable $th) { - ray($th->getMessage()); - send_internal_notification('ProxyCheckJob failed with: ' . $th->getMessage()); - throw $th; + } catch (\Throwable $e) { + ray($e->getMessage()); + send_internal_notification('ProxyCheckJob failed with: ' . $e->getMessage()); + throw $e; } } } diff --git a/app/Jobs/ProxyContainerStatusJob.php b/app/Jobs/ProxyContainerStatusJob.php index 24ad24be0..a69c96ef3 100644 --- a/app/Jobs/ProxyContainerStatusJob.php +++ b/app/Jobs/ProxyContainerStatusJob.php @@ -52,7 +52,7 @@ class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique } $this->server->save(); } - } catch (\Exception $e) { + } catch (\Throwable $e) { if ($e->getCode() === 1) { $this->server->proxy->status = 'exited'; $this->server->save(); diff --git a/app/Jobs/ProxyStartJob.php b/app/Jobs/ProxyStartJob.php index 91932a48c..90230ccbf 100755 --- a/app/Jobs/ProxyStartJob.php +++ b/app/Jobs/ProxyStartJob.php @@ -35,10 +35,10 @@ class ProxyStartJob implements ShouldQueue $this->server->save(); } resolve(StartProxy::class)($this->server); - } catch (\Throwable $th) { - send_internal_notification('ProxyStartJob failed with: ' . $th->getMessage()); - ray($th->getMessage()); - throw $th; + } catch (\Throwable $e) { + send_internal_notification('ProxyStartJob failed with: ' . $e->getMessage()); + ray($e->getMessage()); + throw $e; } } } diff --git a/app/Jobs/ResourceStatusJob.php b/app/Jobs/ResourceStatusJob.php index efd6d1445..3e5f5a455 100644 --- a/app/Jobs/ResourceStatusJob.php +++ b/app/Jobs/ResourceStatusJob.php @@ -37,10 +37,10 @@ class ResourceStatusJob implements ShouldQueue, ShouldBeUnique database: $postgresql, )); } - } catch (\Exception $th) { - send_internal_notification('ResourceStatusJob failed with: ' . $th->getMessage()); - ray($th); - throw $th; + } catch (\Throwable $e) { + send_internal_notification('ResourceStatusJob failed with: ' . $e->getMessage()); + ray($e); + throw $e; } } } diff --git a/app/Jobs/SendConfirmationForWaitlistJob.php b/app/Jobs/SendConfirmationForWaitlistJob.php index a8790f27f..470b1bafe 100755 --- a/app/Jobs/SendConfirmationForWaitlistJob.php +++ b/app/Jobs/SendConfirmationForWaitlistJob.php @@ -34,10 +34,10 @@ class SendConfirmationForWaitlistJob implements ShouldQueue ]); $mail->subject('You are on the waitlist!'); send_user_an_email($mail, $this->email); - } catch (\Throwable $th) { - send_internal_notification("SendConfirmationForWaitlistJob failed for {$this->email} with error: " . $th->getMessage()); - ray($th->getMessage()); - throw $th; + } catch (\Throwable $e) { + send_internal_notification("SendConfirmationForWaitlistJob failed for {$this->email} with error: " . $e->getMessage()); + ray($e->getMessage()); + throw $e; } } } diff --git a/app/Jobs/SubscriptionInvoiceFailedJob.php b/app/Jobs/SubscriptionInvoiceFailedJob.php index 48e9fea64..5e8654673 100755 --- a/app/Jobs/SubscriptionInvoiceFailedJob.php +++ b/app/Jobs/SubscriptionInvoiceFailedJob.php @@ -33,10 +33,10 @@ class SubscriptionInvoiceFailedJob implements ShouldQueue send_user_an_email($mail, $member->email); } }); - } catch (\Throwable $th) { - send_internal_notification('SubscriptionInvoiceFailedJob failed with: ' . $th->getMessage()); - ray($th->getMessage()); - throw $th; + } catch (\Throwable $e) { + send_internal_notification('SubscriptionInvoiceFailedJob failed with: ' . $e->getMessage()); + ray($e->getMessage()); + throw $e; } } } diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php index d96aecd4e..797c2efbb 100644 --- a/app/Models/PrivateKey.php +++ b/app/Models/PrivateKey.php @@ -24,7 +24,7 @@ class PrivateKey extends BaseModel { try { return PublicKeyLoader::load($this->private_key)->getPublicKey()->toString('OpenSSH',['comment' => '']); - } catch (\Exception $e) { + } catch (\Throwable $e) { return 'Error loading private key'; } } diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index b90f5ebd5..080448f71 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -52,7 +52,7 @@ function format_docker_envs_to_json($rawOutput) $env = explode('=', $env); return [$env[0] => $env[1]]; }); - } catch (\Throwable $th) { + } catch (\Throwable $e) { return collect([]); } } diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index 673c9801f..40ff2f958 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -203,7 +203,7 @@ function validateServer(Server $server) "uptime" => $uptime, "dockerVersion" => $dockerVersion, ]; - } catch (\Exception $e) { + } catch (\Throwable $e) { $server->settings->is_reachable = false; $server->settings->is_usable = false; throw $e; @@ -219,7 +219,7 @@ function check_server_connection(Server $server) instant_remote_process(['uptime'], $server); $server->unreachable_count = 0; $server->settings->is_reachable = true; - } catch (\Exception $e) { + } catch (\Throwable $e) { if ($server->unreachable_count == 2) { $server->team->notify(new NotReachable($server)); $server->settings->is_reachable = false; @@ -246,7 +246,7 @@ function checkRequiredCommands(Server $server) } try { instant_remote_process(["docker run --rm --privileged --net=host --pid=host --ipc=host --volume /:/host busybox chroot /host bash -c 'apt update && apt install -y {$command}'"], $server); - } catch (\Exception $e) { + } catch (\Throwable $e) { ray('could not install ' . $command); ray($e); break; diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 7a8c5429b..edb54ab64 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -89,18 +89,18 @@ function general_error_handler(Throwable | null $err = null, $that = null, $isJs } throw new Exception($customErrorMessage ?? $err->getMessage()); } - } catch (Throwable $error) { + } catch (Throwable $e) { if ($that) { - return $that->emit('error', $customErrorMessage ?? $error->getMessage()); + return $that->emit('error', $customErrorMessage ?? $e->getMessage()); } elseif ($isJson) { return response()->json([ - 'code' => $error->getCode(), - 'error' => $error->getMessage(), + 'code' => $e->getCode(), + 'error' => $e->getMessage(), ]); } else { ray($customErrorMessage); - ray($error); - return $customErrorMessage ?? $error->getMessage(); + ray($e); + return $customErrorMessage ?? $e->getMessage(); } } } @@ -116,9 +116,9 @@ function get_latest_version_of_coolify(): string $response = Http::get('https://cdn.coollabs.io/coolify/versions.json'); $versions = $response->json(); return data_get($versions, 'coolify.v4.version'); - } catch (Throwable $th) { - //throw $th; - ray($th->getMessage()); + } catch (Throwable $e) { + //throw $e; + ray($e->getMessage()); return '0.0.0'; } } @@ -258,8 +258,8 @@ function send_internal_notification(string $message): void $baseUrl = config('app.name'); $team = Team::find(0); $team->notify(new GeneralNotification("👀 {$baseUrl}: " . $message)); - } catch (\Throwable $th) { - ray($th->getMessage()); + } catch (\Throwable $e) { + ray($e->getMessage()); } } function send_user_an_email(MailMessage $mail, string $email): void diff --git a/database/seeders/InstanceSettingsSeeder.php b/database/seeders/InstanceSettingsSeeder.php index 1be6462c9..31c8cfb5f 100644 --- a/database/seeders/InstanceSettingsSeeder.php +++ b/database/seeders/InstanceSettingsSeeder.php @@ -38,7 +38,7 @@ class InstanceSettingsSeeder extends Seeder if (is_null($settings->public_ipv6) && $ipv6) { $settings->update(['public_ipv6' => $ipv6]); } - } catch (\Exception $e) { + } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; } } diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index 9a307c7eb..719c06df3 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -119,7 +119,7 @@ class ProductionSeeder extends Seeder $settings->update(['public_ipv6' => $ipv6]); } } - } catch (\Exception $e) { + } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; } } From 42daae10c61562718aec4f16d939907e89a91253 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 20:51:31 +0200 Subject: [PATCH 07/13] feat: able to invite more people at once --- app/Console/Commands/WaitlistInvite.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/WaitlistInvite.php b/app/Console/Commands/WaitlistInvite.php index 61d0bac18..dd629d706 100644 --- a/app/Console/Commands/WaitlistInvite.php +++ b/app/Console/Commands/WaitlistInvite.php @@ -19,7 +19,7 @@ class WaitlistInvite extends Command * * @var string */ - protected $signature = 'waitlist:invite {email?} {--only-email}'; + protected $signature = 'waitlist:invite {--people=1} {--only-email} {email?}'; /** * The console command description. @@ -33,6 +33,12 @@ class WaitlistInvite extends Command */ public function handle() { + $people = $this->option('people'); + for ($i = 0; $i < $people; $i++) { + $this->main(); + } + } + private function main() { if ($this->argument('email')) { if ($this->option('only-email')) { $this->next_patient = User::whereEmail($this->argument('email'))->first(); From 8a39a4469a06c62d3ba5be57d7cfeed09e29c955 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 11 Sep 2023 22:29:34 +0200 Subject: [PATCH 08/13] fix: proxy check, reduce jobs, etc --- app/Actions/Proxy/StartProxy.php | 9 ++-- app/Console/Commands/TestEmail.php | 1 - app/Console/Kernel.php | 22 +++++--- app/Http/Livewire/Server/Proxy.php | 9 ++-- app/Http/Livewire/Server/Proxy/Deploy.php | 9 +++- app/Http/Livewire/Server/Proxy/Status.php | 27 +++++++--- app/Http/Livewire/Settings/Configuration.php | 4 +- app/Jobs/ApplicationDeploymentJob.php | 2 +- app/Jobs/ProxyCheckJob.php | 46 ----------------- app/Jobs/ProxyContainerStatusJob.php | 51 +++++++++++++------ app/Jobs/ProxyStartJob.php | 44 ---------------- app/Jobs/ResourceStatusJob.php | 46 ----------------- app/Models/Server.php | 22 ++++++-- app/View/Components/Modal.php | 7 +-- resources/views/components/modal.blade.php | 3 +- .../views/livewire/server/form.blade.php | 7 ++- .../views/livewire/server/proxy.blade.php | 23 ++++++--- .../livewire/server/proxy/deploy.blade.php | 17 ++----- .../livewire/server/proxy/status.blade.php | 11 +++- 19 files changed, 146 insertions(+), 214 deletions(-) delete mode 100755 app/Jobs/ProxyCheckJob.php delete mode 100755 app/Jobs/ProxyStartJob.php delete mode 100644 app/Jobs/ResourceStatusJob.php diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php index 70dcbdab3..d8a14d27e 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -2,8 +2,6 @@ namespace App\Actions\Proxy; -use App\Enums\ProxyStatus; -use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Support\Str; use Spatie\Activitylog\Models\Activity; @@ -36,11 +34,14 @@ class StartProxy "echo '####### Creating Docker Compose file...'", "echo '####### Pulling docker image...'", 'docker compose pull', - "echo '####### Stopping existing proxy...'", + "echo '####### Stopping existing coolify-proxy...'", 'docker compose down -v --remove-orphans', "lsof -nt -i:80 | xargs -r kill -9", "lsof -nt -i:443 | xargs -r kill -9", - "echo '####### Starting proxy...'", + "systemctl disable nginx > /dev/null 2>&1 || true", + "systemctl disable apache2 > /dev/null 2>&1 || true", + "systemctl disable apache > /dev/null 2>&1 || true", + "echo '####### Starting coolify-proxy...'", 'docker compose up -d --remove-orphans', "echo '####### Proxy installed successfully...'" ], $server); diff --git a/app/Console/Commands/TestEmail.php b/app/Console/Commands/TestEmail.php index 682848a05..4e29d7962 100644 --- a/app/Console/Commands/TestEmail.php +++ b/app/Console/Commands/TestEmail.php @@ -21,7 +21,6 @@ use Exception; use Illuminate\Console\Command; use Illuminate\Mail\Message; use Illuminate\Notifications\Messages\MailMessage; -use Illuminate\Support\Facades\Process; use Mail; use Str; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 276a27067..85fa80aac 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,7 @@ namespace App\Console; +use App\Enums\ProxyTypes; use App\Jobs\ApplicationContainerStatusJob; use App\Jobs\CheckResaleLicenseJob; use App\Jobs\CleanupInstanceStuffsJob; @@ -9,11 +10,11 @@ use App\Jobs\DatabaseBackupJob; use App\Jobs\DatabaseContainerStatusJob; use App\Jobs\DockerCleanupJob; use App\Jobs\InstanceAutoUpdateJob; -use App\Jobs\ProxyCheckJob; -use App\Jobs\ResourceStatusJob; +use App\Jobs\ProxyContainerStatusJob; use App\Models\Application; use App\Models\InstanceSettings; use App\Models\ScheduledDatabaseBackup; +use App\Models\Server; use App\Models\StandalonePostgresql; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -24,22 +25,26 @@ class Kernel extends ConsoleKernel { if (isDev()) { $schedule->command('horizon:snapshot')->everyMinute(); - // $schedule->job(new ResourceStatusJob)->everyMinute(); - $schedule->job(new ProxyCheckJob)->everyFiveMinutes(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute(); // $schedule->job(new CheckResaleLicenseJob)->hourly(); $schedule->job(new DockerCleanupJob)->everyOddHour(); } else { $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->job(new CleanupInstanceStuffsJob)->everyTenMinutes()->onOneServer(); - // $schedule->job(new ResourceStatusJob)->everyMinute()->onOneServer(); $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); - $schedule->job(new ProxyCheckJob)->everyFiveMinutes()->onOneServer(); $schedule->job(new DockerCleanupJob)->everyTenMinutes()->onOneServer(); } $this->instance_auto_update($schedule); $this->check_scheduled_backups($schedule); $this->check_resources($schedule); + $this->check_proxies($schedule); + } + private function check_proxies($schedule) + { + $servers = Server::all()->where('settings.is_usable', true)->where('settings.is_reachable', true)->whereNotNull('proxy.type')->where('proxy.type', '!=', ProxyTypes::NONE->value); + foreach ($servers as $server) { + $schedule->job(new ProxyContainerStatusJob($server))->everyMinute()->onOneServer(); + } } private function check_resources($schedule) { @@ -53,7 +58,8 @@ class Kernel extends ConsoleKernel $schedule->job(new DatabaseContainerStatusJob($postgresql))->everyMinute()->onOneServer(); } } - private function instance_auto_update($schedule){ + private function instance_auto_update($schedule) + { if (isDev()) { return; } @@ -74,7 +80,7 @@ class Kernel extends ConsoleKernel if (!$scheduled_backup->enabled) { continue; } - if (is_null(data_get($scheduled_backup,'database'))) { + if (is_null(data_get($scheduled_backup, 'database'))) { ray('database not found'); $scheduled_backup->delete(); continue; diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index c11476d65..7f0a11f98 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -14,14 +14,14 @@ class Proxy extends Component public ?string $selectedProxy = null; public $proxy_settings = null; - public string|null $redirect_url = null; + public ?string $redirect_url = null; protected $listeners = ['proxyStatusUpdated', 'saveConfiguration' => 'submit']; public function mount() { - $this->selectedProxy = $this->server->proxy->type; - $this->redirect_url = $this->server->proxy->redirect_url; + $this->selectedProxy = data_get($this->server, 'proxy.type'); + $this->redirect_url = data_get($this->server, 'proxy.redirect_url'); } public function proxyStatusUpdated() @@ -69,9 +69,10 @@ class Proxy extends Component } } - public function load_proxy_configuration() + public function loadProxyConfiguration() { try { + ray('loadProxyConfiguration'); $this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server); } catch (\Throwable $e) { return general_error_handler(err: $e); diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.php index f78763479..19e421d1f 100644 --- a/app/Http/Livewire/Server/Proxy/Deploy.php +++ b/app/Http/Livewire/Server/Proxy/Deploy.php @@ -10,15 +10,20 @@ class Deploy extends Component { public Server $server; public $proxy_settings = null; + protected $listeners = ['proxyStatusUpdated']; - public function start_proxy() + public function proxyStatusUpdated() { + $this->server->refresh(); + } + public function startProxy() { if ( $this->server->proxy->last_applied_settings && $this->server->proxy->last_saved_settings !== $this->server->proxy->last_applied_settings ) { - $this->emit('saveConfiguration', $this->server); + resolve(SaveConfigurationSync::class)($this->server, $this->proxy_settings); } + $activity = resolve(StartProxy::class)($this->server); $this->emit('newMonitorActivity', $activity->id); } diff --git a/app/Http/Livewire/Server/Proxy/Status.php b/app/Http/Livewire/Server/Proxy/Status.php index 352a1df52..be0189f54 100644 --- a/app/Http/Livewire/Server/Proxy/Status.php +++ b/app/Http/Livewire/Server/Proxy/Status.php @@ -2,7 +2,6 @@ namespace App\Http\Livewire\Server\Proxy; -use App\Jobs\ProxyContainerStatusJob; use App\Models\Server; use Livewire\Component; @@ -10,14 +9,26 @@ class Status extends Component { public Server $server; - public function get_status() + protected $listeners = ['proxyStatusUpdated']; + public function proxyStatusUpdated() { + $this->server->refresh(); + } + public function getProxyStatus() { - if (data_get($this->server,'settings.is_usable')) { - dispatch_sync(new ProxyContainerStatusJob( - server: $this->server - )); - $this->server->refresh(); - $this->emit('proxyStatusUpdated'); + try { + if (data_get($this->server, 'settings.is_usable') && data_get($this->server, 'settings.is_reachable')) { + $container = getContainerStatus(server: $this->server, container_id: 'coolify-proxy'); + $this->server->proxy->status = $container; + $this->server->save(); + $this->emit('proxyStatusUpdated'); + } + } catch (\Throwable $e) { + return general_error_handler(err: $e); } + + } + public function getProxyStatusWithNoti() { + $this->emit('success', 'Refreshing proxy status.'); + $this->getProxyStatus(); } } diff --git a/app/Http/Livewire/Settings/Configuration.php b/app/Http/Livewire/Settings/Configuration.php index 965f0335b..6801823fe 100644 --- a/app/Http/Livewire/Settings/Configuration.php +++ b/app/Http/Livewire/Settings/Configuration.php @@ -2,7 +2,7 @@ namespace App\Http\Livewire\Settings; -use App\Jobs\ProxyStartJob; +use App\Jobs\ProxyContainerStatusJob; use App\Models\InstanceSettings as ModelsInstanceSettings; use App\Models\Server; use Livewire\Component; @@ -124,7 +124,7 @@ class Configuration extends Component ]; } $this->save_configuration_to_disk($traefik_dynamic_conf, $file); - dispatch(new ProxyStartJob($this->server)); + dispatch(new ProxyContainerStatusJob($this->server)); } } diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 53a6c1406..7a61029e0 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -135,7 +135,7 @@ class ApplicationDeploymentJob implements ShouldQueue $this->deploy(); } } - if ($this->application->fqdn) dispatch(new ProxyStartJob($this->server)); + if ($this->application->fqdn) dispatch(new ProxyContainerStatusJob($this->server)); $this->next(ApplicationDeploymentStatus::FINISHED->value); } catch (Exception $e) { ray($e); diff --git a/app/Jobs/ProxyCheckJob.php b/app/Jobs/ProxyCheckJob.php deleted file mode 100755 index 65d04bf05..000000000 --- a/app/Jobs/ProxyCheckJob.php +++ /dev/null @@ -1,46 +0,0 @@ -settings->is_reachable === false || $server->settings->is_usable === false - ) { - continue; - } - $status = getContainerStatus(server: $server, container_id: $container_name); - if ($status === 'running') { - continue; - } - if (data_get($server, 'proxy.type')) { - resolve(StartProxy::class)($server); - } - } - } catch (\Throwable $e) { - ray($e->getMessage()); - send_internal_notification('ProxyCheckJob failed with: ' . $e->getMessage()); - throw $e; - } - } -} diff --git a/app/Jobs/ProxyContainerStatusJob.php b/app/Jobs/ProxyContainerStatusJob.php index a69c96ef3..1e7eac6a3 100644 --- a/app/Jobs/ProxyContainerStatusJob.php +++ b/app/Jobs/ProxyContainerStatusJob.php @@ -2,6 +2,8 @@ namespace App\Jobs; +use App\Actions\Proxy\StartProxy; +use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Bus\Queueable; @@ -11,7 +13,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Str; class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique { @@ -28,29 +29,49 @@ class ProxyContainerStatusJob implements ShouldQueue, ShouldBeUnique public function middleware(): array { - return [new WithoutOverlapping($this->server->id)]; + return [new WithoutOverlapping($this->server->uuid)]; } - public function uniqueId(): int + public function uniqueId(): string { - return $this->server->id; + ray($this->server->uuid); + return $this->server->uuid; } public function handle(): void { try { - $container = getContainerStatus(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: false); - $status = data_get($container, 'State.Status'); - if ($status && data_get($this->server, 'proxy.status') !== $status) { - $this->server->proxy->status = $status; - if ($this->server->proxy->status === 'running') { - $traefik = $container['Config']['Labels']['org.opencontainers.image.title']; - $version = $container['Config']['Labels']['org.opencontainers.image.version']; - if (isset($version) && isset($traefik) && $traefik === 'Traefik' && Str::of($version)->startsWith('v2')) { - $this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value; - } + $proxyType = data_get($this->server, 'proxy.type'); + if ($proxyType === ProxyTypes::NONE->value) { + return; + } + if (is_null($proxyType)) { + if ($this->server->isProxyShouldRun()) { + $this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value; + $this->server->proxy->status = ProxyStatus::EXITED->value; + $this->server->save(); + resolve(StartProxy::class)($this->server); + return; + } + } + + $container = getContainerStatus(server: $this->server, all_data: true, container_id: 'coolify-proxy', throwError: false); + $containerStatus = data_get($container, 'State.Status'); + $databaseContainerStatus = data_get($this->server, 'proxy.status', 'exited'); + + + if ($proxyType !== ProxyTypes::NONE->value) { + if ($containerStatus === 'running') { + $this->server->proxy->status = $containerStatus; + $this->server->save(); + return; + } + if ((is_null($containerStatus) ||$containerStatus !== 'running' || $databaseContainerStatus !== 'running' || ($containerStatus && $databaseContainerStatus !== $containerStatus)) && $this->server->isProxyShouldRun()) { + $this->server->proxy->status = $containerStatus; + $this->server->save(); + resolve(StartProxy::class)($this->server); + return; } - $this->server->save(); } } catch (\Throwable $e) { if ($e->getCode() === 1) { diff --git a/app/Jobs/ProxyStartJob.php b/app/Jobs/ProxyStartJob.php deleted file mode 100755 index 90230ccbf..000000000 --- a/app/Jobs/ProxyStartJob.php +++ /dev/null @@ -1,44 +0,0 @@ -server->name); - $status = getContainerStatus(server: $this->server, container_id: $container_name); - if ($status === 'running') { - return; - } - if (is_null(data_get($this->server, 'proxy.type'))) { - $this->server->proxy->type = ProxyTypes::TRAEFIK_V2->value; - $this->server->proxy->status = ProxyStatus::EXITED->value; - $this->server->save(); - } - resolve(StartProxy::class)($this->server); - } catch (\Throwable $e) { - send_internal_notification('ProxyStartJob failed with: ' . $e->getMessage()); - ray($e->getMessage()); - throw $e; - } - } -} diff --git a/app/Jobs/ResourceStatusJob.php b/app/Jobs/ResourceStatusJob.php deleted file mode 100644 index 3e5f5a455..000000000 --- a/app/Jobs/ResourceStatusJob.php +++ /dev/null @@ -1,46 +0,0 @@ -applications = Application::all(); - $this->postgresqls = StandalonePostgresql::all(); - } - - public function handle(): void - { - try { - foreach ($this->applications as $application) { - dispatch(new ApplicationContainerStatusJob( - application: $application, - )); - } - foreach ($this->postgresqls as $postgresql) { - dispatch(new DatabaseContainerStatusJob( - database: $postgresql, - )); - } - } catch (\Throwable $e) { - send_internal_notification('ResourceStatusJob failed with: ' . $e->getMessage()); - ray($e); - throw $e; - } - } -} diff --git a/app/Models/Server.php b/app/Models/Server.php index f3d9090a0..973d2d628 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -30,7 +30,6 @@ class Server extends BaseModel 'server_id' => $server->id, ]); } - }); static::deleting(function ($server) { $server->destinations()->each(function ($destination) { @@ -72,7 +71,6 @@ class Server extends BaseModel $swarmDocker = collect($server->swarmDockers->all()); return $standaloneDocker->concat($swarmDocker); } - public function settings() { return $this->hasOne(ServerSetting::class); @@ -93,7 +91,8 @@ class Server extends BaseModel return false; } - public function databases() { + public function databases() + { return $this->destinations()->map(function ($standaloneDocker) { $postgresqls = $standaloneDocker->postgresqls; return $postgresqls?->concat([]) ?? collect([]); @@ -137,4 +136,21 @@ class Server extends BaseModel { return $this->belongsTo(Team::class); } + public function isProxyShouldRun() + { + $shouldRun = false; + foreach ($this->applications() as $application) { + if (data_get($application, 'fqdn')) { + $shouldRun = true; + break; + } + } + if ($this->id === 0) { + $settings = InstanceSettings::get(); + if (data_get($settings, 'fqdn')) { + $shouldRun = true; + } + } + return $shouldRun; + } } diff --git a/app/View/Components/Modal.php b/app/View/Components/Modal.php index d37e10dca..e38d2dfb1 100644 --- a/app/View/Components/Modal.php +++ b/app/View/Components/Modal.php @@ -13,9 +13,10 @@ class Modal extends Component */ public function __construct( public string $modalId, - public string|null $modalTitle = null, - public string|null $modalBody = null, - public string|null $modalSubmit = null, + public ?string $submitWireAction = null, + public ?string $modalTitle = null, + public ?string $modalBody = null, + public ?string $modalSubmit = null, public bool $noSubmit = false, public bool $yesOrNo = false, public string $action = 'delete' diff --git a/resources/views/components/modal.blade.php b/resources/views/components/modal.blade.php index 650903c44..d457b2651 100644 --- a/resources/views/components/modal.blade.php +++ b/resources/views/components/modal.blade.php @@ -34,7 +34,8 @@ @else