fix: realtime connection?!

This commit is contained in:
Andras Bacsai 2023-12-11 18:06:29 +01:00
parent 3ffa2b6b8d
commit 17c8872130
8 changed files with 170 additions and 11 deletions

View File

@ -36,6 +36,7 @@ public function handle()
}
$this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers();
setup_dynamic_configuration();
}
private function cleanup_stucked_helper_containers()
{

View File

@ -93,6 +93,14 @@ private function setup_instance_fqdn()
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
],
'coolify-realtime-ws' =>
[
'entryPoints' => [
0 => 'http',
],
'service' => 'coolify-realtime',
'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
],
],
'services' =>
[
@ -109,6 +117,19 @@ private function setup_instance_fqdn()
],
],
],
'coolify-realtime' =>
[
'loadBalancer' =>
[
'servers' =>
[
0 =>
[
'url' => 'http://coolify-realtime:6001',
],
],
],
],
],
],
];
@ -117,6 +138,9 @@ private function setup_instance_fqdn()
$traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [
0 => 'redirect-to-https@docker',
];
$traefik_dynamic_conf['http']['routers']['coolify-realtime-wss']['middlewares'] = [
0 => 'redirect-to-https@docker',
];
$traefik_dynamic_conf['http']['routers']['coolify-https'] = [
'entryPoints' => [
0 => 'https',
@ -127,6 +151,16 @@ private function setup_instance_fqdn()
'certresolver' => 'letsencrypt',
],
];
$traefik_dynamic_conf['http']['routers']['coolify-realtime-wss'] = [
'entryPoints' => [
0 => 'https',
],
'service' => 'coolify-realtime',
'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
'tls' => [
'certresolver' => 'letsencrypt',
],
];
}
$this->save_configuration_to_disk($traefik_dynamic_conf, $file);
}

View File

@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Request;
use Spatie\Url\Url;
class InstanceSettings extends Model implements SendsEmail
@ -30,6 +31,18 @@ public function fqdn(): Attribute
}
);
}
public static function realtimePort() {
$envDefined = env('PUSHER_PORT');
if ($envDefined != '6001') {
return $envDefined;
}
$url = Url::fromString(Request::getSchemeAndHttpHost());
if ($url->getScheme() === 'https') {
return 443;
} else {
return 6001;
}
}
public static function get()
{
return InstanceSettings::findOrFail(0);

View File

@ -2,7 +2,9 @@
use App\Actions\Proxy\SaveConfiguration;
use App\Models\Application;
use App\Models\InstanceSettings;
use App\Models\Server;
use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml;
function get_proxy_path()
@ -155,7 +157,119 @@ function generate_default_proxy_configuration(Server $server)
SaveConfiguration::run($server, $config);
return $config;
}
function setup_dynamic_configuration()
{
$dynamic_config_path = get_proxy_path() . "/dynamic";
$settings = InstanceSettings::get();
$server = Server::findOrFail(0);
$file = "$dynamic_config_path/coolify.yaml";
if (empty($settings->fqdn)) {
instant_remote_process([
"rm -f $file",
], $server);
} else {
$url = Url::fromString($settings->fqdn);
$host = $url->getHost();
$schema = $url->getScheme();
$traefik_dynamic_conf = [
'http' =>
[
'routers' =>
[
'coolify-http' =>
[
'entryPoints' => [
0 => 'http',
],
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
],
'coolify-ws' =>
[
'entryPoints' => [
0 => 'http',
],
'service' => 'coolify-realtime',
'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
],
],
'services' =>
[
'coolify' =>
[
'loadBalancer' =>
[
'servers' =>
[
0 =>
[
'url' => 'http://coolify:80',
],
],
],
],
'coolify-realtime' =>
[
'loadBalancer' =>
[
'servers' =>
[
0 =>
[
'url' => 'http://coolify-realtime:6001',
],
],
],
],
],
],
];
if ($schema === 'https') {
$traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [
0 => 'redirect-to-https@docker',
];
$traefik_dynamic_conf['http']['routers']['coolify-ws']['middlewares'] = [
0 => 'redirect-to-https@docker',
];
$traefik_dynamic_conf['http']['routers']['coolify-https'] = [
'entryPoints' => [
0 => 'https',
],
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
'tls' => [
'certresolver' => 'letsencrypt',
],
];
$traefik_dynamic_conf['http']['routers']['coolify-wss'] = [
'entryPoints' => [
0 => 'https',
],
'service' => 'coolify-realtime',
'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
'tls' => [
'certresolver' => 'letsencrypt',
],
];
}
$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);
instant_remote_process([
"mkdir -p $dynamic_config_path",
"echo '$base64' | base64 -d > $file",
], $server);
if (config('app.env') == 'local') {
ray($yaml);
}
}
}
function setup_default_redirect_404(string|null $redirect_url, Server $server)
{
$traefik_dynamic_conf_path = get_proxy_path() . "/dynamic";

View File

@ -57,6 +57,7 @@ services:
- "${FORWARD_SOKETI_PORT:-6001}:6001"
environment:
SOKETI_DEBUG: "true"
SOKETI_PATH_PREFIX: "${PUSHER_PATH_PREFIX:-/realtime}"
SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID:-coolify}"
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY:-coolify}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}"

View File

@ -124,6 +124,7 @@ services:
- "${SOKETI_PORT:-6001}:6001"
environment:
SOKETI_DEBUG: "${SOKETI_DEBUG:-false}"
SOKETI_PATH_PREFIX: "${PUSHER_PATH_PREFIX:-/realtime}"
SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID}"
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"

View File

@ -49,17 +49,12 @@
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
cluster: "{{ env('PUSHER_HOST') }}" ||
"{{ App\Models\InstanceSettings::get()->public_ipv4 }}" ||
"{{ App\Models\InstanceSettings::get()->public_ipv6 }}" ||
window.location.hostname,
cluster: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
key: "{{ env('PUSHER_APP_KEY') }}" || 'coolify',
wsHost: "{{ env('PUSHER_HOST') }}" ||
"{{ App\Models\InstanceSettings::get()->public_ipv4 }}" ||
"{{ App\Models\InstanceSettings::get()->public_ipv6 }}" ||
window.location.hostname,
wsPort: "{{ env('PUSHER_PORT') }}" || 6001,
wssPort: "{{ env('PUSHER_PORT') }}" || 6001,
wsHost: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
wsPort: "{{ App\Models\InstanceSettings::realtimePort() }}",
wssPort: "{{ App\Models\InstanceSettings::realtimePort() }}",
wsPath: '/realtime',
forceTLS: false,
encrypted: true,
enableStats: false,

View File

@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
"version": "4.0.0-beta.157"
"version": "4.0.0-beta.153"
}
}
}