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
feat: able to generate only the required labels for resources
Andras Bacsai0b000919cf59
diff --git a/app/Livewire/Server/Proxy.php b/app/Livewire/Server/Proxy.phpindex a170ee0295..123b29d707 100644--- a/app/Livewire/Server/Proxy.php+++ b/app/Livewire/Server/Proxy.php@@ -20,6 +20,10 @@ class Proxy extends Componentprotected $listeners = ['proxyStatusUpdated', 'saveConfiguration' => 'submit'];+ protected $rules = [+ 'server.settings.generate_exact_labels' => 'required|boolean',+ ];+public function mount(){$this->selectedProxy = $this->server->proxyType();@@ -31,13 +35,13 @@ class Proxy extends Component$this->dispatch('refresh')->self();}- public function change_proxy()+ public function changeProxy(){$this->server->proxy = null;$this->server->save();}- public function select_proxy($proxy_type)+ public function selectProxy($proxy_type){$this->server->proxy->set('status', 'exited');$this->server->proxy->set('type', $proxy_type);@@ -49,6 +53,17 @@ class Proxy extends Component$this->dispatch('proxyStatusUpdated');}+ public function instantSave()+ {+ try {+ $this->validate();+ $this->server->settings->save();+ $this->dispatch('success', 'Settings saved.');+ } catch (\Throwable $e) {+ return handleError($e, $this);+ }+ }+public function submit(){try {diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex 437c1ee413..a534dc5ff3 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -540,16 +540,73 @@ function generateLabelsApplication(Application $application, ?ApplicationPreviewif ($pull_request_id === 0) {if ($application->fqdn) {$domains = str(data_get($application, 'fqdn'))->explode(',');+ $shouldGenerateLabelsExactly = $application->destination->server->settings->generate_exact_labels;+ if ($shouldGenerateLabelsExactly) {+ switch ($application->destination->server->proxyType()) {+ case ProxyTypes::TRAEFIK->value:+ $labels = $labels->merge(fqdnLabelsForTraefik(+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled(),+ redirect_direction: $application->redirect+ ));+ break;+ case ProxyTypes::CADDY->value:+ $labels = $labels->merge(fqdnLabelsForCaddy(+ network: $application->destination->network,+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled(),+ redirect_direction: $application->redirect+ ));+ break;+ }+ } else {+ $labels = $labels->merge(fqdnLabelsForTraefik(+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled(),+ redirect_direction: $application->redirect+ ));+ $labels = $labels->merge(fqdnLabelsForCaddy(+ network: $application->destination->network,+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled(),+ redirect_direction: $application->redirect+ ));+ }++ }+ } else {+ if (data_get($preview, 'fqdn')) {+ $domains = str(data_get($preview, 'fqdn'))->explode(',');+ } else {+ $domains = collect([]);+ }+ $shouldGenerateLabelsExactly = $application->destination->server->settings->generate_exact_labels;+ if ($shouldGenerateLabelsExactly) {switch ($application->destination->server->proxyType()) {- case ProxyTypes::TRAEFIK_V2->value:+ case ProxyTypes::TRAEFIK->value:$labels = $labels->merge(fqdnLabelsForTraefik(uuid: $appUuid,domains: $domains,onlyPort: $onlyPort,is_force_https_enabled: $application->isForceHttpsEnabled(),is_gzip_enabled: $application->isGzipEnabled(),- is_stripprefix_enabled: $application->isStripprefixEnabled(),- redirect_direction: $application->redirect+ is_stripprefix_enabled: $application->isStripprefixEnabled()));break;case ProxyTypes::CADDY->value:@@ -560,41 +617,28 @@ function generateLabelsApplication(Application $application, ?ApplicationPreviewonlyPort: $onlyPort,is_force_https_enabled: $application->isForceHttpsEnabled(),is_gzip_enabled: $application->isGzipEnabled(),- is_stripprefix_enabled: $application->isStripprefixEnabled(),- redirect_direction: $application->redirect+ is_stripprefix_enabled: $application->isStripprefixEnabled()));break;}- }- } else {- if (data_get($preview, 'fqdn')) {- $domains = str(data_get($preview, 'fqdn'))->explode(',');} else {- $domains = collect([]);- }-- switch ($application->destination->server->proxyType()) {- case ProxyTypes::TRAEFIK_V2->value:- $labels = $labels->merge(fqdnLabelsForTraefik(- uuid: $appUuid,- domains: $domains,- onlyPort: $onlyPort,- is_force_https_enabled: $application->isForceHttpsEnabled(),- is_gzip_enabled: $application->isGzipEnabled(),- is_stripprefix_enabled: $application->isStripprefixEnabled()- ));- break;- case ProxyTypes::CADDY->value:- $labels = $labels->merge(fqdnLabelsForCaddy(- network: $application->destination->network,- uuid: $appUuid,- domains: $domains,- onlyPort: $onlyPort,- is_force_https_enabled: $application->isForceHttpsEnabled(),- is_gzip_enabled: $application->isGzipEnabled(),- is_stripprefix_enabled: $application->isStripprefixEnabled()- ));- break;+ $labels = $labels->merge(fqdnLabelsForTraefik(+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled()+ ));+ $labels = $labels->merge(fqdnLabelsForCaddy(+ network: $application->destination->network,+ uuid: $appUuid,+ domains: $domains,+ onlyPort: $onlyPort,+ is_force_https_enabled: $application->isForceHttpsEnabled(),+ is_gzip_enabled: $application->isGzipEnabled(),+ is_stripprefix_enabled: $application->isStripprefixEnabled()+ ));}}diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex dd71a28868..aae4fafd4e 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1305,32 +1305,57 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal$serviceLabels = $serviceLabels->merge($defaultLabels);if (! $isDatabase && $fqdns->count() > 0) {if ($fqdns) {- switch ($resource->destination->server->proxyType()) {- case ProxyTypes::TRAEFIK_V2->value:- $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(- uuid: $resource->uuid,- domains: $fqdns,- is_force_https_enabled: true,- serviceLabels: $serviceLabels,- is_gzip_enabled: $savedService->isGzipEnabled(),- is_stripprefix_enabled: $savedService->isStripprefixEnabled(),- service_name: $serviceName,- image: data_get($service, 'image')- ));- break;- case ProxyTypes::CADDY->value:- $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(- network: $resource->destination->network,- uuid: $resource->uuid,- domains: $fqdns,- is_force_https_enabled: true,- serviceLabels: $serviceLabels,- is_gzip_enabled: $savedService->isGzipEnabled(),- is_stripprefix_enabled: $savedService->isStripprefixEnabled(),- service_name: $serviceName,- image: data_get($service, 'image')- ));- break;+ $shouldGenerateLabelsExactly = $resource->server->settings->generate_exact_labels;+ if ($shouldGenerateLabelsExactly) {+ switch ($resource->server->proxyType()) {+ case ProxyTypes::TRAEFIK->value:+ $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(+ uuid: $resource->uuid,+ domains: $fqdns,+ is_force_https_enabled: true,+ serviceLabels: $serviceLabels,+ is_gzip_enabled: $savedService->isGzipEnabled(),+ is_stripprefix_enabled: $savedService->isStripprefixEnabled(),+ service_name: $serviceName,+ image: data_get($service, 'image')+ ));+ break;+ case ProxyTypes::CADDY->value:+ $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(+ network: $resource->destination->network,+ uuid: $resource->uuid,+ domains: $fqdns,+ is_force_https_enabled: true,+ serviceLabels: $serviceLabels,+ is_gzip_enabled: $savedService->isGzipEnabled(),+ is_stripprefix_enabled: $savedService->isStripprefixEnabled(),+ service_name: $serviceName,+ image: data_get($service, 'image')+ ));+ break;+ }+ } else {+ $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik(+ uuid: $resource->uuid,+ domains: $fqdns,+ is_force_https_enabled: true,+ serviceLabels: $serviceLabels,+ is_gzip_enabled: $savedService->isGzipEnabled(),+ is_stripprefix_enabled: $savedService->isStripprefixEnabled(),+ service_name: $serviceName,+ image: data_get($service, 'image')+ ));+ $serviceLabels = $serviceLabels->merge(fqdnLabelsForCaddy(+ network: $resource->destination->network,+ uuid: $resource->uuid,+ domains: $fqdns,+ is_force_https_enabled: true,+ serviceLabels: $serviceLabels,+ is_gzip_enabled: $savedService->isGzipEnabled(),+ is_stripprefix_enabled: $savedService->isStripprefixEnabled(),+ service_name: $serviceName,+ image: data_get($service, 'image')+ ));}}}@@ -2037,35 +2062,63 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal});}}- switch ($server->proxyType()) {- case ProxyTypes::TRAEFIK_V2->value:- $serviceLabels = $serviceLabels->merge(- fqdnLabelsForTraefik(- uuid: $resource->uuid,- domains: $fqdns,- serviceLabels: $serviceLabels,- generate_unique_uuid: $resource->build_pack === 'dockercompose',- image: data_get($service, 'image'),- is_force_https_enabled: $resource->isForceHttpsEnabled(),- is_gzip_enabled: $resource->isGzipEnabled(),- is_stripprefix_enabled: $resource->isStripprefixEnabled(),- )- );- break;- case ProxyTypes::CADDY->value:- $serviceLabels = $serviceLabels->merge(- fqdnLabelsForCaddy(- network: $resource->destination->network,- uuid: $resource->uuid,- domains: $fqdns,- serviceLabels: $serviceLabels,- image: data_get($service, 'image'),- is_force_https_enabled: $resource->isForceHttpsEnabled(),- is_gzip_enabled: $resource->isGzipEnabled(),- is_stripprefix_enabled: $resource->isStripprefixEnabled(),- )- );- break;+ $shouldGenerateLabelsExactly = $server->settings->generate_exact_labels;+ if ($shouldGenerateLabelsExactly) {+ switch ($server->proxyType()) {+ case ProxyTypes::TRAEFIK->value:+ $serviceLabels = $serviceLabels->merge(+ fqdnLabelsForTraefik(+ uuid: $resource->uuid,+ domains: $fqdns,+ serviceLabels: $serviceLabels,+ generate_unique_uuid: $resource->build_pack === 'dockercompose',+ image: data_get($service, 'image'),+ is_force_https_enabled: $resource->isForceHttpsEnabled(),+ is_gzip_enabled: $resource->isGzipEnabled(),+ is_stripprefix_enabled: $resource->isStripprefixEnabled(),+ )+ );+ break;+ case ProxyTypes::CADDY->value:+ $serviceLabels = $serviceLabels->merge(+ fqdnLabelsForCaddy(+ network: $resource->destination->network,+ uuid: $resource->uuid,+ domains: $fqdns,+ serviceLabels: $serviceLabels,+ image: data_get($service, 'image'),+ is_force_https_enabled: $resource->isForceHttpsEnabled(),+ is_gzip_enabled: $resource->isGzipEnabled(),+ is_stripprefix_enabled: $resource->isStripprefixEnabled(),+ )+ );+ break;+ }+ } else {+ $serviceLabels = $serviceLabels->merge(+ fqdnLabelsForTraefik(+ uuid: $resource->uuid,+ domains: $fqdns,+ serviceLabels: $serviceLabels,+ generate_unique_uuid: $resource->build_pack === 'dockercompose',+ image: data_get($service, 'image'),+ is_force_https_enabled: $resource->isForceHttpsEnabled(),+ is_gzip_enabled: $resource->isGzipEnabled(),+ is_stripprefix_enabled: $resource->isStripprefixEnabled(),+ )+ );+ $serviceLabels = $serviceLabels->merge(+ fqdnLabelsForCaddy(+ network: $resource->destination->network,+ uuid: $resource->uuid,+ domains: $fqdns,+ serviceLabels: $serviceLabels,+ image: data_get($service, 'image'),+ is_force_https_enabled: $resource->isForceHttpsEnabled(),+ is_gzip_enabled: $resource->isGzipEnabled(),+ is_stripprefix_enabled: $resource->isStripprefixEnabled(),+ )+ );}}}diff --git a/database/migrations/2024_08_07_155324_add_proxy_label_chooser.php b/database/migrations/2024_08_07_155324_add_proxy_label_chooser.phpnew file mode 100644index 0000000000..7bc8a06572--- /dev/null+++ b/database/migrations/2024_08_07_155324_add_proxy_label_chooser.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->boolean('generate_exact_labels')->default(false);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->dropColumn('generate_exact_labels');+ });+ }+};diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.phpindex 191787ebdc..2b8ede4a5e 100644--- a/resources/views/livewire/server/proxy.blade.php+++ b/resources/views/livewire/server/proxy.blade.php@@ -7,9 +7,9 @@<div class="flex items-center gap-2"><h2>Configuration</h2>@if ($server->proxy->status === 'exited' || $server->proxy->status === 'removing')- <x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>+ <x-forms.button wire:click.prevent="changeProxy">Switch Proxy</x-forms.button>@else- <x-forms.button disabled wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>+ <x-forms.button disabled wire:click.prevent="changeProxy">Switch Proxy</x-forms.button>@endif<x-forms.button type="submit">Save</x-forms.button>@@ -21,6 +21,13 @@</svg>Before switching proxies, please read <a class="underline dark:text-white"href="https://coolify.io/docs/knowledge-base/server/proxies#switch-between-proxies">this</a>.</div>+ <h4>Advanced</h4>+ <div class="pb-4 w-96">+ <x-forms.checkbox+ helper="If set, all resources will only have docker container labels for {{ str($server->proxyType())->title() }}.<br>For applications, labels needs to be regenerated manually. <br>Resources needs to be restarted."+ id="server.settings.generate_exact_labels"+ label="Generate labels only for {{ str($server->proxyType())->title() }}" instantSave />+ </div>@if ($server->proxyType() === ProxyTypes::TRAEFIK->value)<h4>Traefik</h4>@elseif ($server->proxyType() === 'CADDY')@@ -53,13 +60,13 @@@elseif($selectedProxy === 'NONE')<div class="flex items-center gap-2"><h2>Configuration</h2>- <x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>+ <x-forms.button wire:click.prevent="changeProxy">Switch Proxy</x-forms.button></div><div class="pt-2 pb-4">Custom (None) Proxy Selected</div>@else<div class="flex items-center gap-2"><h2>Configuration</h2>- <x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>+ <x-forms.button wire:click.prevent="changeProxy">Switch Proxy</x-forms.button></div>@endif@else@@ -67,13 +74,13 @@<h2>Configuration</h2><div class="subtitle">Select a proxy you would like to use on this server.</div><div class="grid gap-4">- <x-forms.button class="box" wire:click="select_proxy('NONE')">+ <x-forms.button class="box" wire:click="selectProxy('NONE')">Custom (None)</x-forms.button>- <x-forms.button class="box" wire:click="select_proxy('TRAEFIK')">+ <x-forms.button class="box" wire:click="selectProxy('TRAEFIK')">Traefik</x-forms.button>- <x-forms.button class="box" wire:click="select_proxy('CADDY')">+ <x-forms.button class="box" wire:click="selectProxy('CADDY')">Caddy</x-forms.button><x-forms.button disabled class="box">