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
fix: proxy configuration + starter
Andras Bacsai51c468ae0b1b
diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.phpindex 87cae6522b..da09403cc1 100644--- a/app/Actions/Proxy/StartProxy.php+++ b/app/Actions/Proxy/StartProxy.php@@ -22,6 +22,7 @@ class StartProxyif (!$configuration) {throw new \Exception("Configuration is not synced");}+ SaveConfiguration::run($server, $configuration);$docker_compose_yml_base64 = base64_encode($configuration);$server->proxy->last_applied_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;$server->save();@@ -50,12 +51,15 @@ class StartProxy"echo '####### Proxy installed successfully.'"]);$commands = $commands->merge(connectProxyToNetworks($server));- if (!$async) {- instant_remote_process($commands, $server);- return 'OK';- } else {+ if ($async) {$activity = remote_process($commands, $server);return $activity;+ } else {+ instant_remote_process($commands, $server);+ $server->proxy->set('status', 'running');+ $server->proxy->set('type', $proxyType);+ $server->save();+ return 'OK';}}}diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.phpindex ca0235ce6d..66eb307b3d 100644--- a/app/Http/Livewire/Server/Proxy.php+++ b/app/Http/Livewire/Server/Proxy.php@@ -38,8 +38,8 @@ class Proxy extends Componentpublic function select_proxy($proxy_type){- $this->server->proxy->type = $proxy_type;- $this->server->proxy->status = 'exited';+ $this->server->proxy->set('status', 'exited');+ $this->server->proxy->set('type', $proxy_type);$this->server->save();$this->selectedProxy = $this->server->proxy->type;$this->emit('proxyStatusUpdated');diff --git a/app/Http/Livewire/Server/Proxy/Modal.php b/app/Http/Livewire/Server/Proxy/Modal.phpindex 2674abe3d1..ef99489107 100644--- a/app/Http/Livewire/Server/Proxy/Modal.php+++ b/app/Http/Livewire/Server/Proxy/Modal.php@@ -11,6 +11,8 @@ class Modal extends Componentpublic function proxyStatusUpdated(){+ $this->server->proxy->set('status', 'running');+ $this->server->save();$this->emit('proxyStatusUpdated');}}diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.phpindex 1067d00285..46c3372607 100644--- a/app/Jobs/ContainerStatusJob.php+++ b/app/Jobs/ContainerStatusJob.php@@ -77,11 +77,13 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted$services = $this->server->services();$previews = $this->server->previews();+ $this->server->proxyType();/// Check if proxy is running$foundProxyContainer = $containers->filter(function ($value, $key) {return data_get($value, 'Name') === '/coolify-proxy';})->first();if (!$foundProxyContainer) {+ ray('Proxy not found, starting it...');if ($this->server->isProxyShouldRun()) {StartProxy::run($this->server, false);$this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server));@@ -99,7 +101,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncryptedforeach ($containers as $container) {$containerStatus = data_get($container, 'State.Status');- $containerHealth = data_get($container, 'State.Health.Status','unhealthy');+ $containerHealth = data_get($container, 'State.Health.Status', 'unhealthy');$containerStatus = "$containerStatus ($containerHealth)";$labels = data_get($container, 'Config.Labels');$labels = Arr::undot(format_docker_labels_to_json($labels));diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 89f1041990..0619a589ed 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -78,7 +78,8 @@ class Server extends BaseModelreturn $this->hasOne(ServerSetting::class);}- public function proxyType() {+ public function proxyType()+ {$type = $this->proxy->get('type');if (is_null($type)) {$this->proxy->type = ProxyTypes::TRAEFIK_V2->value;@@ -115,11 +116,13 @@ class Server extends BaseModelreturn $standaloneDocker->applications;})->flatten();}- public function services() {+ public function services()+ {return $this->hasMany(Service::class);}- public function previews() {+ public function previews()+ {return $this->destinations()->map(function ($standaloneDocker) {return $standaloneDocker->applications->map(function ($application) {return $application->previews;@@ -161,6 +164,9 @@ class Server extends BaseModelpublic function isProxyShouldRun(){$shouldRun = false;+ if ($this->proxyType() === ProxyTypes::NONE->value) {+ return false;+ }foreach ($this->applications() as $application) {if (data_get($application, 'fqdn')) {$shouldRun = true;@@ -175,7 +181,8 @@ class Server extends BaseModel}return $shouldRun;}- public function isFunctional() {+ public function isFunctional()+ {return $this->settings->is_reachable && $this->settings->is_usable;}}diff --git a/app/Models/Service.php b/app/Models/Service.phpindex ae590f13f8..8f95cddcea 100644--- a/app/Models/Service.php+++ b/app/Models/Service.php@@ -405,17 +405,16 @@ class Service extends BaseModel}}}- if ($this->server->proxyType() === ProxyTypes::TRAEFIK_V2->value) {- $labels = collect(data_get($service, 'labels', []));- $labels = collect([]);- $labels = $labels->merge(defaultLabels($this->id, $container_name, type: 'service'));- if (!$isDatabase) {- if ($fqdns) {- $labels = $labels->merge(fqdnLabelsForTraefik($fqdns, $container_name, true));- }+ // Add labels to the service+ $labels = collect(data_get($service, 'labels', []));+ $labels = collect([]);+ $labels = $labels->merge(defaultLabels($this->id, $container_name, type: 'service'));+ if (!$isDatabase) {+ if ($fqdns) {+ $labels = $labels->merge(fqdnLabelsForTraefik($fqdns, $container_name, true));}- data_set($service, 'labels', $labels->toArray());}+ data_set($service, 'labels', $labels->toArray());data_forget($service, 'is_database');data_set($service, 'restart', RESTART_MODE);data_set($service, 'container_name', $container_name);diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.phpindex 992e6205c5..f3ee1fa770 100644--- a/bootstrap/helpers/proxy.php+++ b/bootstrap/helpers/proxy.php@@ -1,5 +1,6 @@<?php+use App\Actions\Proxy\SaveConfiguration;use App\Models\Server;use App\Models\StandalonePostgresql;use Symfony\Component\Yaml\Yaml;@@ -10,7 +11,8 @@ function get_proxy_path()$proxy_path = "$base_path/proxy";return $proxy_path;}-function connectProxyToNetworks(Server $server) {+function connectProxyToNetworks(Server $server)+{$networks = collect($server->standaloneDockers)->map(function ($docker) {return $docker['network'];})->unique();@@ -20,7 +22,7 @@ function connectProxyToNetworks(Server $server) {$commands = $networks->map(function ($network) {return ["echo '####### Connecting coolify-proxy to $network network...'",- "docker network ls --format '{{.Name}}' | grep '^$network$' || docker network create --attachable $network >/dev/null",+ "docker network ls --format '{{.Name}}' | grep '^$network$' >/dev/null || docker network create --attachable $network >/dev/null","docker network connect $network coolify-proxy >/dev/null 2>&1 || true",];});@@ -101,7 +103,9 @@ function generate_default_proxy_configuration(Server $server)if (isDev()) {$config['services']['traefik']['command'][] = "--log.level=debug";}- return Yaml::dump($config, 4, 2);+ $config = Yaml::dump($config, 4, 2);+ SaveConfiguration::run($server, $config);+ return $config;}function setup_default_redirect_404(string|null $redirect_url, Server $server)diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.phpindex 1df5c36a28..f0bf008743 100644--- a/resources/views/livewire/server/proxy.blade.php+++ b/resources/views/livewire/server/proxy.blade.php@@ -1,6 +1,6 @@<div>@if ($server->isFunctional())- @if (data_get($server,'proxy.type'))+ @if (data_get($server, 'proxy.type'))<div x-init="$wire.loadProxyConfiguration">@if ($selectedProxy === 'TRAEFIK_V2')<form wire:submit.prevent='submit'>@@ -19,8 +19,8 @@configurations.</div>@endif- <x-forms.input placeholder="https://coolify.io" id="redirect_url" label="Default Redirect 404"- helper="All urls that has no service available will be redirected to this domain.<span class='text-helper'>You can set to your main marketing page or your social media link.</span>" />+ <x-forms.input placeholder="https://app.coolify.io" id="redirect_url" label="Default Redirect 404"+ helper="All urls that has no service available will be redirected to this domain." /><div wire:loading wire:target="loadProxyConfiguration" class="pt-4"><x-loading text="Loading proxy configuration..." /></div>@@ -39,18 +39,14 @@@elseif($selectedProxy === 'NONE')<div class="flex items-center gap-2"><h2>Proxy</h2>- @if ($server->proxy->status === 'exited')- <x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>- @endif+ <x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button></div><div class="pt-3 pb-4">None</div>@else- <div class="flex items-center gap-2">- <h2>Proxy</h2>- @if ($server->proxy->status === 'exited')+ <div class="flex items-center gap-2">+ <h2>Proxy</h2><x-forms.button wire:click.prevent="change_proxy">Switch Proxy</x-forms.button>- @endif- </div>+ </div>@endif@else<div>diff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.phpindex 3c7c1f28dd..41444fde4d 100644--- a/resources/views/livewire/server/proxy/deploy.blade.php+++ b/resources/views/livewire/server/proxy/deploy.blade.php@@ -8,7 +8,7 @@</x-slot:modalBody></x-modal>@if ($server->isFunctional() && data_get($server, 'proxy.type') !== 'NONE')- @if (data_get($server, 'proxy.status') !== 'exited')+ @if (data_get($server, 'proxy.status') === 'running')<div class="flex gap-4">@if ($currentRoute === 'server.proxy' && $traefikDashboardAvailable)<button>