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