refactor: Update ProxyTypes enum values to use TRAEFIK instead of TRAEFIK_V2

This commit is contained in:
Andras Bacsai 2024-08-07 17:52:51 +02:00
parent 13e8d3c17c
commit 59702c6dbc
11 changed files with 28 additions and 22 deletions

View File

@ -5,7 +5,7 @@
enum ProxyTypes: string
{
case NONE = 'NONE';
case TRAEFIK_V2 = 'TRAEFIK_V2';
case TRAEFIK = 'TRAEFIK';
case NGINX = 'NGINX';
case CADDY = 'CADDY';
}

View File

@ -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,
],
]);

View File

@ -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';

View File

@ -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,
],
];

View File

@ -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;

View File

@ -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();
// }

View File

@ -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',

View File

@ -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);

View File

@ -5,7 +5,7 @@
<button>Configuration</button>
</a>
@if ($server->proxyType() !== 'NONE')
{{-- @if ($server->proxyType() === 'TRAEFIK_V2') --}}
{{-- @if ($server->proxyType() === 'TRAEFIK') --}}
<a class="{{ request()->routeIs('server.proxy.dynamic-confs') ? 'dark:text-white' : '' }}"
href="{{ route('server.proxy.dynamic-confs', $parameters) }}">
<button>Dynamic Configurations</button>

View File

@ -1,3 +1,4 @@
@php use App\Enums\ProxyTypes; @endphp
<div>
@if ($server->proxyType())
<div x-init="$wire.loadProxyConfiguration">
@ -20,7 +21,7 @@
</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>
@if ($server->proxyType() === 'TRAEFIK_V2')
@if ($server->proxyType() === ProxyTypes::TRAEFIK->value)
<h4>Traefik</h4>
@elseif ($server->proxyType() === 'CADDY')
<h4>Caddy</h4>
@ -69,7 +70,7 @@
<x-forms.button class="box" wire:click="select_proxy('NONE')">
Custom (None)
</x-forms.button>
<x-forms.button class="box" wire:click="select_proxy('TRAEFIK_V2')">
<x-forms.button class="box" wire:click="select_proxy('TRAEFIK')">
Traefik
</x-forms.button>
<x-forms.button class="box" wire:click="select_proxy('CADDY')">

View File

@ -1,3 +1,4 @@
@php use App\Enums\ProxyTypes; @endphp
<div>
@if (
$server->proxyType() !== 'NONE' &&
@ -12,7 +13,10 @@
</x-slide-over>
@if (data_get($server, 'proxy.status') === 'running')
<div class="flex gap-2">
@if ($currentRoute === 'server.proxy' && $traefikDashboardAvailable && $server->proxyType() === 'TRAEFIK_V2')
@if (
$currentRoute === 'server.proxy' &&
$traefikDashboardAvailable &&
$server->proxyType() === ProxyTypes::TRAEFIK->value)
<button>
<a target="_blank" href="http://{{ $serverIp }}:8080">
Traefik Dashboard