From 59702c6dbc8e58686c050b78cf95bed574417303 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 7 Aug 2024 17:52:51 +0200 Subject: [PATCH] refactor: Update ProxyTypes enum values to use TRAEFIK instead of TRAEFIK_V2 --- app/Enums/ProxyTypes.php | 2 +- app/Http/Controllers/Api/ServersController.php | 2 +- app/Livewire/Boarding/Index.php | 2 +- app/Livewire/Server/New/ByIp.php | 2 +- app/Livewire/Server/Proxy/NewDynamicConfiguration.php | 5 +++-- app/Models/Server.php | 10 +++++----- bootstrap/helpers/proxy.php | 2 +- database/seeders/ProductionSeeder.php | 4 ++-- resources/views/components/server/sidebar.blade.php | 10 +++++----- resources/views/livewire/server/proxy.blade.php | 5 +++-- resources/views/livewire/server/proxy/deploy.blade.php | 6 +++++- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/Enums/ProxyTypes.php b/app/Enums/ProxyTypes.php index 5ccf82e21..b3dc56746 100644 --- a/app/Enums/ProxyTypes.php +++ b/app/Enums/ProxyTypes.php @@ -5,7 +5,7 @@ enum ProxyTypes: string { case NONE = 'NONE'; - case TRAEFIK_V2 = 'TRAEFIK_V2'; + case TRAEFIK = 'TRAEFIK'; case NGINX = 'NGINX'; case CADDY = 'CADDY'; } diff --git a/app/Http/Controllers/Api/ServersController.php b/app/Http/Controllers/Api/ServersController.php index 5d4b56988..9044c4a35 100644 --- a/app/Http/Controllers/Api/ServersController.php +++ b/app/Http/Controllers/Api/ServersController.php @@ -525,7 +525,7 @@ public function create_server(Request $request) 'private_key_id' => $privateKey->id, 'team_id' => $teamId, 'proxy' => [ - 'type' => ProxyTypes::TRAEFIK_V2->value, + 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, ], ]); diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php index 8127ca009..147a1ad6f 100644 --- a/app/Livewire/Boarding/Index.php +++ b/app/Livewire/Boarding/Index.php @@ -179,7 +179,7 @@ public function selectExistingServer() public function getProxyType() { // Set Default Proxy Type - $this->selectProxy(ProxyTypes::TRAEFIK_V2->value); + $this->selectProxy(ProxyTypes::TRAEFIK->value); // $proxyTypeSet = $this->createdServer->proxy->type; // if (!$proxyTypeSet) { // $this->currentState = 'select-proxy'; diff --git a/app/Livewire/Server/New/ByIp.php b/app/Livewire/Server/New/ByIp.php index 0f4c1afea..5f69835d7 100644 --- a/app/Livewire/Server/New/ByIp.php +++ b/app/Livewire/Server/New/ByIp.php @@ -104,7 +104,7 @@ public function submit() 'private_key_id' => $this->private_key_id, 'proxy' => [ // set default proxy type to traefik v2 - 'type' => ProxyTypes::TRAEFIK_V2->value, + 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, ], ]; diff --git a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php index e5de6eda0..2155f1e82 100644 --- a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php +++ b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php @@ -2,6 +2,7 @@ namespace App\Livewire\Server\Proxy; +use App\Enums\ProxyTypes; use App\Models\Server; use Livewire\Component; use Symfony\Component\Yaml\Yaml; @@ -45,7 +46,7 @@ public function addDynamicConfiguration() return redirect()->route('server.index'); } $proxy_type = $this->server->proxyType(); - if ($proxy_type === 'TRAEFIK_V2') { + if ($proxy_type === ProxyTypes::TRAEFIK->value) { if (! str($this->fileName)->endsWith('.yaml') && ! str($this->fileName)->endsWith('.yml')) { $this->fileName = "{$this->fileName}.yaml"; } @@ -69,7 +70,7 @@ public function addDynamicConfiguration() return; } } - if ($proxy_type === 'TRAEFIK_V2') { + if ($proxy_type === ProxyTypes::TRAEFIK->value) { $yaml = Yaml::parse($this->value); $yaml = Yaml::dump($yaml, 10, 2); $this->value = $yaml; diff --git a/app/Models/Server.php b/app/Models/Server.php index a53de14e3..99dca3ecf 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -151,7 +151,7 @@ public function setupDefault404Redirect() $dynamic_conf_path = $this->proxyPath().'/dynamic'; $proxy_type = $this->proxyType(); $redirect_url = $this->proxy->redirect_url; - if ($proxy_type === 'TRAEFIK_V2') { + if ($proxy_type === ProxyTypes::TRAEFIK->value) { $default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml"; } elseif ($proxy_type === 'CADDY') { $default_redirect_file = "$dynamic_conf_path/default_redirect_404.caddy"; @@ -181,7 +181,7 @@ public function setupDefault404Redirect() return; } - if ($proxy_type === 'TRAEFIK_V2') { + if ($proxy_type === ProxyTypes::TRAEFIK->value) { $dynamic_conf = [ 'http' => [ 'routers' => [ @@ -255,7 +255,7 @@ public function setupDynamicProxyConfiguration() { $settings = \App\Models\InstanceSettings::get(); $dynamic_config_path = $this->proxyPath().'/dynamic'; - if ($this->proxyType() === 'TRAEFIK_V2') { + if ($this->proxyType() === ProxyTypes::TRAEFIK->value) { $file = "$dynamic_config_path/coolify.yaml"; if (empty($settings->fqdn) || (isCloud() && $this->id !== 0) || ! $this->isLocalhost()) { instant_remote_process([ @@ -403,7 +403,7 @@ public function proxyPath() // TODO: should use /traefik for already exisiting configurations? // Should move everything except /caddy and /nginx to /traefik // The code needs to be modified as well, so maybe it does not worth it - if ($proxyType === ProxyTypes::TRAEFIK_V2->value) { + if ($proxyType === ProxyTypes::TRAEFIK->value) { $proxy_path = $proxy_path; } elseif ($proxyType === ProxyTypes::CADDY->value) { $proxy_path = $proxy_path.'/caddy'; @@ -421,7 +421,7 @@ public function proxyType() // return $proxyType; // } // if (is_null($proxyType)) { - // $this->proxy->type = ProxyTypes::TRAEFIK_V2->value; + // $this->proxy->type = ProxyTypes::TRAEFIK->value; // $this->proxy->status = ProxyStatus::EXITED->value; // $this->save(); // } diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php index c8202af2d..f18b09f56 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -136,7 +136,7 @@ function generate_default_proxy_configuration(Server $server) 'external' => true, ]; }); - if ($proxy_type === 'TRAEFIK_V2') { + if ($proxy_type === ProxyTypes::TRAEFIK->value) { $labels = [ 'traefik.enable=true', 'traefik.http.routers.traefik.entrypoints=http', diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index e030c0ae6..c88a35f6a 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -100,7 +100,7 @@ public function run(): void 'private_key_id' => 0, ]; $server_details['proxy'] = ServerMetadata::from([ - 'type' => ProxyTypes::TRAEFIK_V2->value, + 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, ]); $server = Server::create($server_details); @@ -153,7 +153,7 @@ public function run(): void 'private_key_id' => 0, ]; $server_details['proxy'] = ServerMetadata::from([ - 'type' => ProxyTypes::TRAEFIK_V2->value, + 'type' => ProxyTypes::TRAEFIK->value, 'status' => ProxyStatus::EXITED->value, ]); $server = Server::create($server_details); diff --git a/resources/views/components/server/sidebar.blade.php b/resources/views/components/server/sidebar.blade.php index 2b06ba7e6..8a6400aef 100644 --- a/resources/views/components/server/sidebar.blade.php +++ b/resources/views/components/server/sidebar.blade.php @@ -5,11 +5,11 @@ @if ($server->proxyType() !== 'NONE') - {{-- @if ($server->proxyType() === 'TRAEFIK_V2') --}} - - - + {{-- @if ($server->proxyType() === 'TRAEFIK') --}} + + + {{-- @endif --}} diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.php index 4e96c8efb..191787ebd 100644 --- a/resources/views/livewire/server/proxy.blade.php +++ b/resources/views/livewire/server/proxy.blade.php @@ -1,3 +1,4 @@ +@php use App\Enums\ProxyTypes; @endphp
@if ($server->proxyType())
@@ -20,7 +21,7 @@ Before switching proxies, please read this.
- @if ($server->proxyType() === 'TRAEFIK_V2') + @if ($server->proxyType() === ProxyTypes::TRAEFIK->value)

Traefik

@elseif ($server->proxyType() === 'CADDY')

Caddy

@@ -69,7 +70,7 @@ Custom (None) - + Traefik diff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.php index d485b4f9a..dba4ce80c 100644 --- a/resources/views/livewire/server/proxy/deploy.blade.php +++ b/resources/views/livewire/server/proxy/deploy.blade.php @@ -1,3 +1,4 @@ +@php use App\Enums\ProxyTypes; @endphp
@if ( $server->proxyType() !== 'NONE' && @@ -12,7 +13,10 @@ @if (data_get($server, 'proxy.status') === 'running')
- @if ($currentRoute === 'server.proxy' && $traefikDashboardAvailable && $server->proxyType() === 'TRAEFIK_V2') + @if ( + $currentRoute === 'server.proxy' && + $traefikDashboardAvailable && + $server->proxyType() === ProxyTypes::TRAEFIK->value)