An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor: only get instanceSettings once from db
Andras Bacsai88f33be5b608
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 9607cffec1..d382dedfe8 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -65,7 +65,7 @@ class Handler extends ExceptionHandlerif ($e instanceof RuntimeException) {return;}- $this->settings = InstanceSettings::get();+ $this->settings = view()->shared('instanceSettings');if ($this->settings->do_not_track) {return;}diff --git a/app/Http/Controllers/Api/OtherController.php b/app/Http/Controllers/Api/OtherController.phpindex 96dded3ce0..917ccc857c 100644--- a/app/Http/Controllers/Api/OtherController.php+++ b/app/Http/Controllers/Api/OtherController.php@@ -3,7 +3,6 @@namespace App\Http\Controllers\Api;use App\Http\Controllers\Controller;-use App\Models\InstanceSettings;use Illuminate\Http\Request;use Illuminate\Support\Facades\Http;use OpenApi\Attributes as OA;@@ -85,7 +84,7 @@ class OtherController extends Controllerif ($teamId !== '0') {return response()->json(['message' => 'You are not allowed to enable the API.'], 403);}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$settings->update(['is_api_enabled' => true]);return response()->json(['message' => 'API enabled.'], 200);@@ -136,7 +135,7 @@ class OtherController extends Controllerif ($teamId !== '0') {return response()->json(['message' => 'You are not allowed to disable the API.'], 403);}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$settings->update(['is_api_enabled' => false]);return response()->json(['message' => 'API disabled.'], 200);diff --git a/app/Http/Controllers/Api/ServersController.php b/app/Http/Controllers/Api/ServersController.phpindex 247a2519f8..161bc3a341 100644--- a/app/Http/Controllers/Api/ServersController.php+++ b/app/Http/Controllers/Api/ServersController.php@@ -301,7 +301,7 @@ class ServersController extends Controller$projects = Project::where('team_id', $teamId)->get();$domains = collect();$applications = $projects->pluck('applications')->flatten();- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if ($applications->count() > 0) {foreach ($applications as $application) {$ip = $application->destination->server->ip;diff --git a/app/Http/Middleware/ApiAllowed.php b/app/Http/Middleware/ApiAllowed.phpindex dc0a433e25..b2a2d0c9a7 100644--- a/app/Http/Middleware/ApiAllowed.php+++ b/app/Http/Middleware/ApiAllowed.php@@ -15,7 +15,7 @@ class ApiAllowedif (isCloud()) {return $next($request);}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if ($settings->is_api_enabled === false) {return response()->json(['success' => true, 'message' => 'API is disabled.'], 403);}diff --git a/app/Jobs/PullCoolifyImageJob.php b/app/Jobs/PullCoolifyImageJob.phpindex 2bcbfc4df5..793b4c4e37 100644--- a/app/Jobs/PullCoolifyImageJob.php+++ b/app/Jobs/PullCoolifyImageJob.php@@ -36,7 +36,7 @@ class PullCoolifyImageJob implements ShouldBeEncrypted, ShouldQueue$latest_version = get_latest_version_of_coolify();instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$latest_version}"], $server, false);- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$current_version = config('version');if (! $settings->is_auto_update_enabled) {return;diff --git a/app/Livewire/Help.php b/app/Livewire/Help.phpindex 2fbd2bc7e5..f85610bece 100644--- a/app/Livewire/Help.php+++ b/app/Livewire/Help.php@@ -48,7 +48,7 @@ class Help extends Component]);$mail->subject("[HELP]: {$this->subject}");- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$type = set_transanctional_email_settings($settings);if (! $type) {$url = 'https://app.coolify.io/api/feedback';diff --git a/app/Livewire/Notifications/Email.php b/app/Livewire/Notifications/Email.phpindex 91c108edcc..aa5279d063 100644--- a/app/Livewire/Notifications/Email.php+++ b/app/Livewire/Notifications/Email.php@@ -173,7 +173,7 @@ class Email extends Componentpublic function copyFromInstanceSettings(){- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if ($settings->smtp_enabled) {$team = currentTeam();$team->update([diff --git a/app/Livewire/Project/Shared/Webhooks.php b/app/Livewire/Project/Shared/Webhooks.phpindex 40e7cdd49b..99fbecbce0 100644--- a/app/Livewire/Project/Shared/Webhooks.php+++ b/app/Livewire/Project/Shared/Webhooks.php@@ -29,6 +29,8 @@ class Webhooks extends Componentpublic function mount(){+ // ray()->clearAll();+ // ray()->showQueries();$this->deploywebhook = generateDeployWebhook($this->resource);$this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github');diff --git a/app/Livewire/Settings/Index.php b/app/Livewire/Settings/Index.phpindex f6f918933c..044f78016f 100644--- a/app/Livewire/Settings/Index.php+++ b/app/Livewire/Settings/Index.php@@ -18,7 +18,7 @@ class Index extends Componentpublic function mount(){if (isInstanceAdmin()) {- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$database = StandalonePostgresql::whereName('coolify-db')->first();$s3s = S3Storage::whereTeamId(0)->get() ?? [];if ($database) {diff --git a/app/Livewire/Settings/License.php b/app/Livewire/Settings/License.phpindex 212bc95be2..dce8e44778 100644--- a/app/Livewire/Settings/License.php+++ b/app/Livewire/Settings/License.php@@ -29,7 +29,7 @@ class License extends Componentabort(404);}$this->instance_id = config('app.id');- $this->settings = InstanceSettings::get();+ $this->settings = view()->shared('instanceSettings');}public function render()diff --git a/app/Livewire/Source/Github/Change.php b/app/Livewire/Source/Github/Change.phpindex ee28f88479..1395c16fc3 100644--- a/app/Livewire/Source/Github/Change.php+++ b/app/Livewire/Source/Github/Change.php@@ -100,7 +100,7 @@ class Change extends Componentreturn redirect()->route('source.all');}$this->applications = $this->github_app->applications;- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');$this->name = str($this->github_app->name)->kebab();diff --git a/app/Livewire/Subscription/Index.php b/app/Livewire/Subscription/Index.phpindex c072352fe2..365e6a3912 100644--- a/app/Livewire/Subscription/Index.php+++ b/app/Livewire/Subscription/Index.php@@ -23,7 +23,7 @@ class Index extends Componentif (data_get(currentTeam(), 'subscription') && isSubscriptionActive()) {return redirect()->route('subscription.show');}- $this->settings = InstanceSettings::get();+ $this->settings = view()->shared('instanceSettings');$this->alreadySubscribed = currentTeam()->subscription()->exists();}diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 2efc9907bb..7ab04f05ef 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -318,7 +318,7 @@ respond 404public function setupDynamicProxyConfiguration(){- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$dynamic_config_path = $this->proxyPath().'/dynamic';if ($this->proxyType() === 'TRAEFIK_V2') {$file = "$dynamic_config_path/coolify.yaml";diff --git a/app/Notifications/Channels/TransactionalEmailChannel.php b/app/Notifications/Channels/TransactionalEmailChannel.phpindex 3d7b7c8d05..49bebd692c 100644--- a/app/Notifications/Channels/TransactionalEmailChannel.php+++ b/app/Notifications/Channels/TransactionalEmailChannel.php@@ -2,7 +2,6 @@namespace App\Notifications\Channels;-use App\Models\InstanceSettings;use App\Models\User;use Exception;use Illuminate\Mail\Message;@@ -14,7 +13,7 @@ class TransactionalEmailChannel{public function send(User $notifiable, Notification $notification): void{- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) {Log::info('SMTP/Resend not enabled');diff --git a/app/Notifications/TransactionalEmails/ResetPassword.php b/app/Notifications/TransactionalEmails/ResetPassword.phpindex 45243c4d52..fcb1ddb759 100644--- a/app/Notifications/TransactionalEmails/ResetPassword.php+++ b/app/Notifications/TransactionalEmails/ResetPassword.php@@ -18,7 +18,7 @@ class ResetPassword extends Notificationpublic function __construct($token){- $this->settings = InstanceSettings::get();+ $this->settings = view()->shared('instanceSettings');$this->token = $token;}diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.phpindex 6822dec135..22fa55058f 100644--- a/app/Providers/AppServiceProvider.php+++ b/app/Providers/AppServiceProvider.php@@ -2,8 +2,10 @@namespace App\Providers;+use App\Models\InstanceSettings;use App\Models\PersonalAccessToken;use Illuminate\Support\Facades\Http;+use Illuminate\Support\Facades\View;use Illuminate\Support\ServiceProvider;use Laravel\Sanctum\Sanctum;@@ -27,5 +29,7 @@ class AppServiceProvider extends ServiceProvider])->baseUrl($api_url);}});++ View::share('instanceSettings', InstanceSettings::get());}}diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.phpindex cd6ec77057..bb5dc81f4d 100644--- a/app/Providers/FortifyServiceProvider.php+++ b/app/Providers/FortifyServiceProvider.php@@ -6,7 +6,6 @@ use App\Actions\Fortify\CreateNewUser;use App\Actions\Fortify\ResetUserPassword;use App\Actions\Fortify\UpdateUserPassword;use App\Actions\Fortify\UpdateUserProfileInformation;-use App\Models\InstanceSettings;use App\Models\OauthSetting;use App\Models\User;use Illuminate\Cache\RateLimiting\Limit;@@ -45,7 +44,7 @@ class FortifyServiceProvider extends ServiceProvider{Fortify::createUsersUsing(CreateNewUser::class);Fortify::registerView(function () {- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (! $settings->is_registration_enabled) {return redirect()->route('login');}@@ -57,7 +56,7 @@ class FortifyServiceProvider extends ServiceProvider});Fortify::loginView(function () {- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$enabled_oauth_providers = OauthSetting::where('enabled', true)->get();$users = User::count();if ($users == 0) {diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex e09b007938..bc1299088e 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -244,13 +244,13 @@ function generate_application_name(string $git_repository, string $git_branch, ?function is_transactional_emails_active(): bool{- return isEmailEnabled(InstanceSettings::get());+ return isEmailEnabled(view()->shared('instanceSettings'));}function set_transanctional_email_settings(?InstanceSettings $settings = null): ?string{if (! $settings) {- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');}config()->set('mail.from.address', data_get($settings, 'smtp_from_address'));config()->set('mail.from.name', data_get($settings, 'smtp_from_name'));@@ -284,7 +284,7 @@ function base_ip(): stringif (isDev()) {return 'localhost';}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if ($settings->public_ipv4) {return "$settings->public_ipv4";}@@ -312,7 +312,7 @@ function getFqdnWithoutPort(string $fqdn)*/function base_url(bool $withPort = true): string{- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if ($settings->fqdn) {return $settings->fqdn;}@@ -379,7 +379,7 @@ function send_internal_notification(string $message): void}function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null): void{- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$type = set_transanctional_email_settings($settings);if (! $type) {throw new Exception('No email settings found.');@@ -2258,7 +2258,7 @@ function validate_dns_entry(string $fqdn, Server $server)if (str($host)->contains('sslip.io')) {return true;}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');$is_dns_validation_enabled = data_get($settings, 'is_dns_validation_enabled');if (! $is_dns_validation_enabled) {return true;@@ -2378,7 +2378,7 @@ function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId =if ($domainFound) {return true;}- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (data_get($settings, 'fqdn')) {$domain = data_get($settings, 'fqdn');if (str($domain)->endsWith('/')) {@@ -2450,7 +2450,7 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null}}if ($resource) {- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (data_get($settings, 'fqdn')) {$domain = data_get($settings, 'fqdn');if (str($domain)->endsWith('/')) {@@ -2525,7 +2525,7 @@ function get_public_ips(){try {echo "Refreshing public ips!\n";- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');[$first, $second] = Process::concurrently(function (Pool $pool) {$pool->path(__DIR__)->command('curl -4s https://ifconfig.io');$pool->path(__DIR__)->command('curl -6s https://ifconfig.io');diff --git a/config/livewire.php b/config/livewire.phpindex 02725e9443..bd3733076d 100644--- a/config/livewire.php+++ b/config/livewire.php@@ -90,7 +90,7 @@ return [|*/- 'legacy_model_binding' => true,+ 'legacy_model_binding' => false,/*|---------------------------------------------------------------------------diff --git a/database/seeders/InstanceSettingsSeeder.php b/database/seeders/InstanceSettingsSeeder.phpindex 31c8cfb5f1..f4b4a7fa29 100644--- a/database/seeders/InstanceSettingsSeeder.php+++ b/database/seeders/InstanceSettingsSeeder.php@@ -27,14 +27,14 @@ class InstanceSettingsSeeder extends Seeder$ipv4 = Process::run('curl -4s https://ifconfig.io')->output();$ipv4 = trim($ipv4);$ipv4 = filter_var($ipv4, FILTER_VALIDATE_IP);- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (is_null($settings->public_ipv4) && $ipv4) {$settings->update(['public_ipv4' => $ipv4]);}$ipv6 = Process::run('curl -6s https://ifconfig.io')->output();$ipv6 = trim($ipv6);$ipv6 = filter_var($ipv6, FILTER_VALIDATE_IP);- $settings = InstanceSettings::get();+ $settings = view()->shared('instanceSettings');if (is_null($settings->public_ipv6) && $ipv6) {$settings->update(['public_ipv6' => $ipv6]);}diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.phpindex 744272242b..9f31790903 100644--- a/resources/views/layouts/base.blade.php+++ b/resources/views/layouts/base.blade.php@@ -8,7 +8,7 @@@use('App\Models\InstanceSettings')@php- $instanceSettings = InstanceSettings::first();+ $instanceSettings = view()->shared('instanceSettings');$name = null;if ($instanceSettings) {diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.phpindex 639776730d..bb3ba9be93 100644--- a/resources/views/livewire/project/application/configuration.blade.php+++ b/resources/views/livewire/project/application/configuration.blade.php@@ -86,57 +86,57 @@</div><div class="w-full"><div x-cloak x-show="activeTab === 'general'" class="h-full">- <livewire:project.application.general :application="$application" />+ {{-- <livewire:project.application.general :application="$application" /> --}}</div><div x-cloak x-show="activeTab === 'swarm'" class="h-full">- <livewire:project.application.swarm :application="$application" />+ {{-- <livewire:project.application.swarm :application="$application" /> --}}</div><div x-cloak x-show="activeTab === 'advanced'" class="h-full">- <livewire:project.application.advanced :application="$application" />+ {{-- <livewire:project.application.advanced :application="$application" /> --}}</div><div x-cloak x-show="activeTab === 'environment-variables'">- <livewire:project.shared.environment-variable.all :resource="$application" />+ {{-- <livewire:project.shared.environment-variable.all :resource="$application" /> --}}</div>@if ($application->git_based())<div x-cloak x-show="activeTab === 'source'">- <livewire:project.application.source :application="$application" />+ {{-- <livewire:project.application.source :application="$application" /> --}}</div>@endif<div x-cloak x-show="activeTab === 'servers'">- <livewire:project.shared.destination :resource="$application" :servers="$servers" />+ {{-- <livewire:project.shared.destination :resource="$application" :servers="$servers" /> --}}</div><div x-cloak x-show="activeTab === 'storages'">- <livewire:project.service.storage :resource="$application" />+ {{-- <livewire:project.service.storage :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'webhooks'">- <livewire:project.shared.webhooks :resource="$application" />+ <livewire:project.shared.webhooks :resource="$application" lazy /></div><div x-cloak x-show="activeTab === 'previews'">- <livewire:project.application.previews :application="$application" />+ {{-- <livewire:project.application.previews :application="$application" /> --}}</div><div x-cloak x-show="activeTab === 'health'">- <livewire:project.shared.health-checks :resource="$application" />+ {{-- <livewire:project.shared.health-checks :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'rollback'">- <livewire:project.application.rollback :application="$application" />+ {{-- <livewire:project.application.rollback :application="$application" /> --}}</div><div x-cloak x-show="activeTab === 'resource-limits'">- <livewire:project.shared.resource-limits :resource="$application" />+ {{-- <livewire:project.shared.resource-limits :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'scheduled-tasks'">- <livewire:project.shared.scheduled-task.all :resource="$application" />+ {{-- <livewire:project.shared.scheduled-task.all :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'resource-operations'">- <livewire:project.shared.resource-operations :resource="$application" />+ {{-- <livewire:project.shared.resource-operations :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'metrics'">- <livewire:project.shared.metrics :resource="$application" />+ {{-- <livewire:project.shared.metrics :resource="$application" /> --}}</div><div x-cloak x-show="activeTab === 'tags'">- <livewire:project.shared.tags :resource="$application" />+ <livewire:project.shared.tags :resource="$application" lazy /></div><div x-cloak x-show="activeTab === 'danger'">- <livewire:project.shared.danger :resource="$application" />+ {{-- <livewire:project.shared.danger :resource="$application" /> --}}</div></div></div>diff --git a/resources/views/livewire/project/resource/environment-select.blade.php b/resources/views/livewire/project/resource/environment-select.blade.phpindex ab160dcdaa..c03466d284 100644--- a/resources/views/livewire/project/resource/environment-select.blade.php+++ b/resources/views/livewire/project/resource/environment-select.blade.php@@ -1,5 +1,5 @@<x-forms.select wire:model.live="selectedEnvironment">- <option value="edit">Create/Edit Environments</option>+ <option value="edit">Create / Edit</option><option disabled>-----</option>@foreach ($environments as $environment)<option value="{{ $environment->name }}">{{ $environment->name }}