From 80a797aec8b8a8cb3ac3901a4d7c8e1eb6813c3c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 24 Sep 2023 21:56:57 +0200 Subject: [PATCH 01/30] version++ --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index 3a1955646..592553a39 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.45', + 'release' => '4.0.0-beta.46', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 462d9f013..548f25cb6 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Mon, 25 Sep 2023 09:17:42 +0200 Subject: [PATCH 02/30] fix: proxy configuration + starter --- app/Actions/Proxy/StartProxy.php | 12 ++++++++---- app/Http/Livewire/Server/Proxy.php | 4 ++-- app/Http/Livewire/Server/Proxy/Modal.php | 2 ++ app/Jobs/ContainerStatusJob.php | 4 +++- app/Models/Server.php | 15 +++++++++++---- app/Models/Service.php | 17 ++++++++--------- bootstrap/helpers/proxy.php | 10 +++++++--- .../views/livewire/server/proxy.blade.php | 18 +++++++----------- .../livewire/server/proxy/deploy.blade.php | 2 +- 9 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php index 87cae6522..da09403cc 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -22,6 +22,7 @@ class StartProxy if (!$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.php index ca0235ce6..66eb307b3 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -38,8 +38,8 @@ class Proxy extends Component public 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.php index 2674abe3d..ef9948910 100644 --- a/app/Http/Livewire/Server/Proxy/Modal.php +++ b/app/Http/Livewire/Server/Proxy/Modal.php @@ -11,6 +11,8 @@ class Modal extends Component public 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.php index 1067d0028..46c337260 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, ShouldBeEncrypted foreach ($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.php index 89f104199..0619a589e 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -78,7 +78,8 @@ class Server extends BaseModel return $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 BaseModel return $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 BaseModel public 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.php index ae590f13f..8f95cddce 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.php index 992e6205c..f3ee1fa77 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -1,5 +1,6 @@ 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.php index 1df5c36a2..f0bf00874 100644 --- a/resources/views/livewire/server/proxy.blade.php +++ b/resources/views/livewire/server/proxy.blade.php @@ -1,6 +1,6 @@
@if ($server->isFunctional()) - @if (data_get($server,'proxy.type')) + @if (data_get($server, 'proxy.type'))
@if ($selectedProxy === 'TRAEFIK_V2')
@@ -19,8 +19,8 @@ configurations.
@endif - +
@@ -39,18 +39,14 @@ @elseif($selectedProxy === 'NONE')

Proxy

- @if ($server->proxy->status === 'exited') - Switch Proxy - @endif + Switch Proxy
None
@else -
-

Proxy

- @if ($server->proxy->status === 'exited') +
+

Proxy

Switch Proxy - @endif -
+
@endif @else
diff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.php index 3c7c1f28d..41444fde4 100644 --- a/resources/views/livewire/server/proxy/deploy.blade.php +++ b/resources/views/livewire/server/proxy/deploy.blade.php @@ -8,7 +8,7 @@ @if ($server->isFunctional() && data_get($server, 'proxy.type') !== 'NONE') - @if (data_get($server, 'proxy.status') !== 'exited') + @if (data_get($server, 'proxy.status') === 'running')
@if ($currentRoute === 'server.proxy' && $traefikDashboardAvailable)