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: dynamic configuration for caddy
Andras Bacsai149082806914
diff --git a/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.phpindex aee61f7de0..a9c01daed9 100644--- a/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php+++ b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php@@ -15,8 +15,16 @@ class DynamicConfigurationNavbar extends Component{$server = Server::ownedByCurrentTeam()->whereId($this->server_id)->first();$proxy_path = $server->proxyPath();+ $proxy_type = $server->proxyType();$file = str_replace('|', '.', $fileName);+ if ($proxy_type === 'CADDY' && $file === "Caddyfile") {+ $this->dispatch('error', 'Cannot delete Caddyfile.');+ return;+ }instant_remote_process(["rm -f {$proxy_path}/dynamic/{$file}"], $server);+ if ($proxy_type === 'CADDY') {+ $server->reloadCaddy();+ }$this->dispatch('success', 'File deleted.');$this->dispatch('loadDynamicConfigurations');$this->dispatch('refresh');diff --git a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php b/app/Livewire/Server/Proxy/NewDynamicConfiguration.phpindex 302e603b39..06180d9473 100644--- a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php+++ b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php@@ -29,7 +29,6 @@ class NewDynamicConfiguration extends Component'fileName' => 'required','value' => 'required',]);-if (data_get($this->parameters, 'server_uuid')) {$this->server = Server::ownedByCurrentTeam()->whereUuid(data_get($this->parameters, 'server_uuid'))->first();}@@ -39,14 +38,21 @@ class NewDynamicConfiguration extends Componentif (is_null($this->server)) {return redirect()->route('server.index');}- if (!str($this->fileName)->endsWith('.yaml') && !str($this->fileName)->endsWith('.yml')) {- $this->fileName = "{$this->fileName}.yaml";- }- if ($this->fileName === 'coolify.yaml') {- $this->dispatch('error', 'File name is reserved.');- return;+ $proxy_type = $this->server->proxyType();+ if ($proxy_type === 'TRAEFIK_V2') {+ if (!str($this->fileName)->endsWith('.yaml') && !str($this->fileName)->endsWith('.yml')) {+ $this->fileName = "{$this->fileName}.yaml";+ }+ if ($this->fileName === 'coolify.yaml') {+ $this->dispatch('error', 'File name is reserved.');+ return;+ }+ } else if ($proxy_type === 'CADDY') {+ if (!str($this->fileName)->endsWith('.caddy')) {+ $this->fileName = "{$this->fileName}.caddy";+ }}- $proxy_path = $this->proxyPath();+ $proxy_path = $this->server->proxyPath();$file = "{$proxy_path}/dynamic/{$this->fileName}";if ($this->newFile) {$exists = instant_remote_process(["test -f $file && echo 1 || echo 0"], $this->server);@@ -55,11 +61,18 @@ class NewDynamicConfiguration extends Componentreturn;}}- $yaml = Yaml::parse($this->value);- $yaml = Yaml::dump($yaml, 10, 2);- $this->value = $yaml;+ if ($proxy_type === 'TRAEFIK_V2') {+ $yaml = Yaml::parse($this->value);+ $yaml = Yaml::dump($yaml, 10, 2);+ $this->value = $yaml;+ }$base64_value = base64_encode($this->value);- instant_remote_process(["echo '{$base64_value}' | base64 -d > {$file}"], $this->server);+ instant_remote_process([+ "echo '{$base64_value}' | base64 -d > {$file}",+ ], $this->server);+ if ($proxy_type === 'CADDY') {+ $this->server->reloadCaddy();+ }$this->dispatch('loadDynamicConfigurations');$this->dispatch('dynamic-configuration-added');$this->dispatch('success', 'Dynamic configuration saved.');diff --git a/app/Models/Server.php b/app/Models/Server.phpindex d2c412d9e8..3cf20d7ae6 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -249,8 +249,9 @@ class Server extends BaseModelif (empty($settings->fqdn)) {instant_remote_process(["rm -f $file",- "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile",], $this);+ $this->reloadCaddy();+} else {$url = Url::fromString($settings->fqdn);$host = $url->getHost();@@ -262,12 +263,17 @@ $schema://$host {$base64 = base64_encode($caddy_file);instant_remote_process(["echo '$base64' | base64 -d > $file",- "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile",], $this);+ $this->reloadCaddy();}}}}+ public function reloadCaddy() {+ return instant_remote_process([+ "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile",+ ], $this);+ }public function proxyPath(){$base_path = config('coolify.base_config_path');diff --git a/resources/views/components/server/sidebar.blade.php b/resources/views/components/server/sidebar.blade.phpindex 94c8c97556..ef2b4b8e75 100644--- a/resources/views/components/server/sidebar.blade.php+++ b/resources/views/components/server/sidebar.blade.php@@ -5,12 +5,12 @@<button>Configuration</button></a>@if ($server->proxyType() !== 'NONE')- @if ($server->proxyType() === 'TRAEFIK_V2')+ {{-- @if ($server->proxyType() === 'TRAEFIK_V2') --}}<a class="{{ request()->routeIs('server.proxy.dynamic-confs') ? 'text-white' : '' }}"href="{{ route('server.proxy.dynamic-confs', $parameters) }}"><button>Dynamic Configurations</button></a>- @endif+ {{-- @endif --}}<a class="{{ request()->routeIs('server.proxy.logs') ? 'text-white' : '' }}"href="{{ route('server.proxy.logs', $parameters) }}"><button>Logs</button>diff --git a/resources/views/livewire/server/proxy/dynamic-configurations.blade.php b/resources/views/livewire/server/proxy/dynamic-configurations.blade.phpindex cb788dda45..0fd92f41ef 100644--- a/resources/views/livewire/server/proxy/dynamic-configurations.blade.php+++ b/resources/views/livewire/server/proxy/dynamic-configurations.blade.php@@ -19,7 +19,7 @@Add</button></x-slide-over></div>- <div class='pb-4'>You can add dynamic Traefik configurations here.</div>+ <div class='pb-4'>You can add dynamic proxy configurations here.</div></div></div><div wire:loading wire:target="loadDynamicConfigurations">@@ -29,7 +29,7 @@@if ($contents?->isNotEmpty())@foreach ($contents as $fileName => $value)<div class="flex flex-col gap-2 py-2">- @if (str_replace('|', '.', $fileName) === 'coolify.yaml')+ @if (str_replace('|', '.', $fileName) === 'coolify.yaml' ||str_replace('|', '.', $fileName) === 'Caddyfile' )<div><h3 class="text-white">File: {{ str_replace('|', '.', $fileName) }}</h3></div>diff --git a/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php b/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.phpindex 9e98b0ed42..110ba289c6 100644--- a/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php+++ b/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php@@ -1,5 +1,5 @@<form wire:submit.prevent="addDynamicConfiguration" class="flex flex-col gap-4">- <x-forms.input id="fileName" label="Filename (.yaml or .yml)" required />+ <x-forms.input id="fileName" label="Filename" required /><x-forms.textarea id="value" label="Configuration" required rows="20" /><x-forms.button type="submit" @click="slideOverOpen=false">Save</x-forms.button></form>