From 8f7fd4295efd850a92f6326202c9c09af727551d Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 22 May 2023 11:21:03 +0200 Subject: [PATCH] wildcard domains --- .../Livewire/Project/Application/General.php | 36 +++++++++++++++++++ app/Jobs/DeployApplicationJob.php | 11 ------ resources/css/app.css | 3 ++ .../views/components/inputs/button.blade.php | 8 +++-- .../project/application/general.blade.php | 19 ++++++++-- .../views/livewire/settings/form.blade.php | 13 +++---- 6 files changed, 68 insertions(+), 22 deletions(-) diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index bdf5e2dfa..32bbc4122 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -3,8 +3,10 @@ namespace App\Http\Livewire\Project\Application; use App\Models\Application; +use App\Models\InstanceSettings; use Livewire\Component; use Illuminate\Support\Str; +use Spatie\Url\Url; class General extends Component { @@ -17,6 +19,9 @@ class General extends Component public string $git_branch; public string|null $git_commit_sha; public string $build_pack; + public string|null $wildcard_domain = null; + public string|null $project_wildcard_domain = null; + public string|null $global_wildcard_domain = null; public bool $is_static; public bool $is_git_submodules_allowed; @@ -59,6 +64,14 @@ class General extends Component $this->application->settings->save(); $this->application->refresh(); $this->emit('saved', 'Application settings updated!'); + $this->checkWildCardDomain(); + } + protected function checkWildCardDomain() + { + $coolify_instance_settings = InstanceSettings::get(); + $this->project_wildcard_domain = data_get($this->application, 'environment.project.settings.wildcard_domain'); + $this->global_wildcard_domain = data_get($coolify_instance_settings, 'wildcard_domain'); + $this->wildcard_domain = $this->project_wildcard_domain ?? $this->global_wildcard_domain ?? null; } public function mount() { @@ -71,14 +84,37 @@ class General extends Component $this->is_http2 = $this->application->settings->is_http2; $this->is_auto_deploy = $this->application->settings->is_auto_deploy; $this->is_dual_cert = $this->application->settings->is_dual_cert; + $this->checkWildCardDomain(); + } + public function generateGlobalRandomDomain() + { + // Set wildcard domain based on Global wildcard domain + $url = Url::fromString($this->global_wildcard_domain); + $host = $url->getHost(); + $path = $url->getPath() === '/' ? '' : $url->getPath(); + $scheme = $url->getScheme(); + $this->application->fqdn = $scheme . '://' . $this->application->uuid . '.' . $host . $path; + $this->application->save(); + } + public function generateProjectRandomDomain() + { + // Set wildcard domain based on Project wildcard domain + $url = Url::fromString($this->project_wildcard_domain); + $host = $url->getHost(); + $path = $url->getPath() === '/' ? '' : $url->getPath(); + $scheme = $url->getScheme(); + $this->application->fqdn = $scheme . '://' . $this->application->uuid . '.' . $host . $path; + $this->application->save(); } public function submit() { try { $this->validate(); + $domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) { return Str::of($domain)->trim()->lower(); }); + $this->application->fqdn = $domains->implode(','); $this->application->save(); } catch (\Exception $e) { diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index f5a257095..a18e8ae22 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -101,21 +101,10 @@ class DeployApplicationJob implements ShouldQueue public function handle(): void { try { - $coolify_instance_settings = InstanceSettings::get(); if ($this->application->deploymentType() === 'source') { $this->source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first(); } - // Get Wildcard Domain - $project_wildcard_domain = data_get($this->application, 'environment.project.settings.wildcard_domain'); - $global_wildcard_domain = data_get($coolify_instance_settings, 'wildcard_domain'); - $wildcard_domain = $project_wildcard_domain ?? $global_wildcard_domain ?? null; - - // Set wildcard domain - if (!$this->application->fqdn && $wildcard_domain) { - $this->application->fqdn = 'http://' . $this->application->uuid . '.' . $wildcard_domain; - $this->application->save(); - } $this->workdir = "/artifacts/{$this->deployment_uuid}"; // Pull builder image diff --git a/resources/css/app.css b/resources/css/app.css index 30a9cb87e..202fe1ab3 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -21,6 +21,9 @@ input { input[type="text"],[type="number"],[type="email"],[type="password"] { @apply read-only:opacity-40; } +.label-text, label { + @apply text-neutral-400 text-sm; +} textarea { @apply textarea placeholder:text-neutral-700 text-white; diff --git a/resources/views/components/inputs/button.blade.php b/resources/views/components/inputs/button.blade.php index 6ac266d60..bb1f448a7 100644 --- a/resources/views/components/inputs/button.blade.php +++ b/resources/views/components/inputs/button.blade.php @@ -5,7 +5,9 @@ 'confirmAction' => null, 'tooltip' => null, ]) -
+@isset($tooltip) +
+ @endisset @if ($type === 'submit')
+ @isset($tooltip) +
+@endisset diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index 00a84dd13..07079b47b 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -8,11 +8,25 @@
-
+
+
+ @if ($wildcard_domain) +
+
Set Random Domain
+ @if ($global_wildcard_domain) + Global Wildcard + + @endif + @if ($project_wildcard_domain) + Project Wildcard + + @endif +
+ @endif @@ -24,7 +38,7 @@ @endif -
+
@@ -54,7 +68,6 @@
- {{-- --}} diff --git a/resources/views/livewire/settings/form.blade.php b/resources/views/livewire/settings/form.blade.php index fd8fd0443..53a860b2f 100644 --- a/resources/views/livewire/settings/form.blade.php +++ b/resources/views/livewire/settings/form.blade.php @@ -2,8 +2,9 @@
- - + +
@@ -15,9 +16,9 @@
- - - - + + + {{-- --}} +