wip
This commit is contained in:
@@ -15,8 +15,13 @@ class Proxy extends Component
|
|||||||
|
|
||||||
public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;
|
public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;
|
||||||
public $proxy_settings = null;
|
public $proxy_settings = null;
|
||||||
|
public string|null $redirect_url = null;
|
||||||
|
|
||||||
protected $listeners = ['serverValidated', 'saveConfiguration'];
|
protected $listeners = ['serverValidated', 'saveConfiguration'];
|
||||||
|
public function mount()
|
||||||
|
{
|
||||||
|
$this->redirect_url = $this->server->proxy->redirect_url;
|
||||||
|
}
|
||||||
public function serverValidated()
|
public function serverValidated()
|
||||||
{
|
{
|
||||||
$this->server->refresh();
|
$this->server->refresh();
|
||||||
@@ -52,17 +57,20 @@ class Proxy extends Component
|
|||||||
$this->server->proxy->status = 'exited';
|
$this->server->proxy->status = 'exited';
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
}
|
}
|
||||||
public function saveConfiguration(Server $server)
|
public function saveConfiguration()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = config('coolify.proxy_config_path');
|
||||||
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
|
||||||
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
|
||||||
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
$this->server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
|
||||||
$server->save();
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
||||||
|
$this->server->save();
|
||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
|
||||||
], $server);
|
], $this->server);
|
||||||
|
$this->server->refresh();
|
||||||
|
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
|
||||||
$this->emit('success', 'Proxy configuration saved.');
|
$this->emit('success', 'Proxy configuration saved.');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return general_error_handler(err: $e);
|
return general_error_handler(err: $e);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Configuration extends Component
|
|||||||
public $do_not_track;
|
public $do_not_track;
|
||||||
public $is_auto_update_enabled;
|
public $is_auto_update_enabled;
|
||||||
public $is_registration_enabled;
|
public $is_registration_enabled;
|
||||||
protected string $dynamic_config_path;
|
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
|
||||||
protected Server $server;
|
protected Server $server;
|
||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
@@ -117,9 +117,6 @@ class Configuration extends Component
|
|||||||
"rm -f $file",
|
"rm -f $file",
|
||||||
], $this->server);
|
], $this->server);
|
||||||
} else {
|
} else {
|
||||||
$url = Url::fromString($this->settings->default_redirect_404);
|
|
||||||
$host = $url->getHost();
|
|
||||||
$schema = $url->getScheme();
|
|
||||||
$traefik_dynamic_conf = [
|
$traefik_dynamic_conf = [
|
||||||
'http' =>
|
'http' =>
|
||||||
[
|
[
|
||||||
@@ -200,10 +197,9 @@ class Configuration extends Component
|
|||||||
$this->validate();
|
$this->validate();
|
||||||
$this->settings->save();
|
$this->settings->save();
|
||||||
|
|
||||||
$this->dynamic_config_path = '/data/coolify/proxy/dynamic';
|
|
||||||
$this->server = Server::findOrFail(0);
|
$this->server = Server::findOrFail(0);
|
||||||
$this->setup_instance_fqdn();
|
$this->setup_instance_fqdn();
|
||||||
$this->setup_default_redirect_404();
|
setup_default_redirect_404(redirect_url: $this->settings->default_redirect_404, server: $this->server);
|
||||||
if ($this->settings->fqdn || $this->settings->default_redirect_404) {
|
if ($this->settings->fqdn || $this->settings->default_redirect_404) {
|
||||||
dispatch(new InstanceProxyCheckJob());
|
dispatch(new InstanceProxyCheckJob());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class Server extends BaseModel
|
|||||||
static public function ownedByCurrentTeam(array $select = ['*'])
|
static public function ownedByCurrentTeam(array $select = ['*'])
|
||||||
{
|
{
|
||||||
$selectArray = collect($select)->concat(['id']);
|
$selectArray = collect($select)->concat(['id']);
|
||||||
|
ray(Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all())->get());
|
||||||
return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all());
|
return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use Spatie\Url\Url;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
if (!function_exists('getProxyConfiguration')) {
|
|
||||||
function getProxyConfiguration(Server $server)
|
function getProxyConfiguration(Server $server)
|
||||||
{
|
{
|
||||||
$proxy_path = config('coolify.proxy_config_path');
|
$proxy_path = config('coolify.proxy_config_path');
|
||||||
@@ -82,4 +82,79 @@ if (!function_exists('getProxyConfiguration')) {
|
|||||||
}
|
}
|
||||||
return Yaml::dump($config, 4, 2);
|
return Yaml::dump($config, 4, 2);
|
||||||
}
|
}
|
||||||
|
function setup_default_redirect_404(string $redirect_url, Server $server)
|
||||||
|
{
|
||||||
|
$traefik_dynamic_conf_path = '/data/coolify/proxy/dynamic';
|
||||||
|
$traefik_default_redirect_file = "$traefik_dynamic_conf_path/default_redirect_404.yaml";
|
||||||
|
if (empty($redirect_url)) {
|
||||||
|
remote_process([
|
||||||
|
"rm -f $traefik_default_redirect_file",
|
||||||
|
], $server);
|
||||||
|
} else {
|
||||||
|
$traefik_dynamic_conf = [
|
||||||
|
'http' =>
|
||||||
|
[
|
||||||
|
'routers' =>
|
||||||
|
[
|
||||||
|
'catchall' =>
|
||||||
|
[
|
||||||
|
'entryPoints' => [
|
||||||
|
0 => 'http',
|
||||||
|
1 => 'https',
|
||||||
|
],
|
||||||
|
'service' => 'noop',
|
||||||
|
'rule' => "HostRegexp(`{catchall:.*}`)",
|
||||||
|
'priority' => 1,
|
||||||
|
'middlewares' => [
|
||||||
|
0 => 'redirect-regexp@file',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'services' =>
|
||||||
|
[
|
||||||
|
'noop' =>
|
||||||
|
[
|
||||||
|
'loadBalancer' =>
|
||||||
|
[
|
||||||
|
'servers' =>
|
||||||
|
[
|
||||||
|
0 =>
|
||||||
|
[
|
||||||
|
'url' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'middlewares' =>
|
||||||
|
[
|
||||||
|
'redirect-regexp' =>
|
||||||
|
[
|
||||||
|
'redirectRegex' =>
|
||||||
|
[
|
||||||
|
'regex' => '(.*)',
|
||||||
|
'replacement' => $redirect_url,
|
||||||
|
'permanent' => false,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$yaml = Yaml::dump($traefik_dynamic_conf, 12, 2);
|
||||||
|
$yaml =
|
||||||
|
"# This file is automatically generated by Coolify.\n" .
|
||||||
|
"# Do not edit it manually (only if you know what are you doing).\n\n" .
|
||||||
|
$yaml;
|
||||||
|
|
||||||
|
$base64 = base64_encode($yaml);
|
||||||
|
ray("mkdir -p $traefik_dynamic_conf_path");
|
||||||
|
remote_process([
|
||||||
|
"mkdir -p $traefik_dynamic_conf_path",
|
||||||
|
"echo '$base64' | base64 -d > $traefik_default_redirect_file",
|
||||||
|
], $server);
|
||||||
|
|
||||||
|
if (config('app.env') == 'local') {
|
||||||
|
ray($yaml);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@isset($proxy_settings)
|
@isset($proxy_settings)
|
||||||
@if ($selectedProxy->value === 'TRAEFIK_V2')
|
@if ($selectedProxy->value === 'TRAEFIK_V2')
|
||||||
<form wire:submit.prevent='saveConfiguration({{ $server }})'>
|
<form wire:submit.prevent='saveConfiguration'>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<h2>Proxy</h2>
|
<h2>Proxy</h2>
|
||||||
<x-forms.button type="submit">Save</x-forms.button>
|
<x-forms.button type="submit">Save</x-forms.button>
|
||||||
@@ -25,6 +25,10 @@
|
|||||||
<div class="text-red-500 ">Configuration out of sync. Restart to get the new configs.
|
<div class="text-red-500 ">Configuration out of sync. Restart to get the new configs.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@if ($server->id !== 0)
|
||||||
|
<x-forms.input id="redirect_url" label="Default redirect"
|
||||||
|
placeholder="https://coolify.io" />
|
||||||
|
@endif
|
||||||
<div class="container w-full mx-auto">
|
<div class="container w-full mx-auto">
|
||||||
<livewire:activity-monitor :header="true" />
|
<livewire:activity-monitor :header="true" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user