diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 79994b132..d864c9c48 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -18,7 +18,6 @@ use App\Models\StandalonePostgresql; use App\Models\StandaloneRedis; use Illuminate\Console\Command; use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Storage; class Init extends Command { @@ -36,6 +35,14 @@ class Init extends Command } $this->cleanup_in_progress_application_deployments(); $this->cleanup_stucked_helper_containers(); + setup_dynamic_configuration(); + + $settings = InstanceSettings::get(); + if (env('AUTOUPDATE') == true) { + $settings->update(['is_auto_update_enabled' => true]); + } else { + $settings->update(['is_auto_update_enabled' => false]); + } } private function cleanup_stucked_helper_containers() { diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php index 62ade961b..43f4afb7a 100644 --- a/app/Livewire/Settings/Configuration.php +++ b/app/Livewire/Settings/Configuration.php @@ -71,83 +71,7 @@ class Configuration extends Component private function setup_instance_fqdn() { - $file = "$this->dynamic_config_path/coolify.yaml"; - if (empty($this->settings->fqdn)) { - instant_remote_process([ - "rm -f $file", - ], $this->server); - } else { - $url = Url::fromString($this->settings->fqdn); - $host = $url->getHost(); - $schema = $url->getScheme(); - $traefik_dynamic_conf = [ - 'http' => - [ - 'routers' => - [ - 'coolify-http' => - [ - 'entryPoints' => [ - 0 => 'http', - ], - 'service' => 'coolify', - 'rule' => "Host(`{$host}`)", - ], - ], - 'services' => - [ - 'coolify' => - [ - 'loadBalancer' => - [ - 'servers' => - [ - 0 => - [ - 'url' => 'http://coolify:80', - ], - ], - ], - ], - ], - ], - ]; + setup_dynamic_configuration(); - if ($schema === 'https') { - $traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [ - 0 => 'redirect-to-https@docker', - ]; - $traefik_dynamic_conf['http']['routers']['coolify-https'] = [ - 'entryPoints' => [ - 0 => 'https', - ], - 'service' => 'coolify', - 'rule' => "Host(`{$host}`)", - 'tls' => [ - 'certresolver' => 'letsencrypt', - ], - ]; - } - $this->save_configuration_to_disk($traefik_dynamic_conf, $file); - } - } - - private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file) - { - $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 $this->dynamic_config_path", - "echo '$base64' | base64 -d > $file", - ], $this->server); - - if (config('app.env') == 'local') { - ray($yaml); - } } } diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php index 846148159..0705ef1a1 100644 --- a/app/Models/InstanceSettings.php +++ b/app/Models/InstanceSettings.php @@ -6,6 +6,8 @@ use App\Notifications\Channels\SendsEmail; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Request; use Spatie\Url\Url; class InstanceSettings extends Model implements SendsEmail diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c50a53bef..d0618f406 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -16,7 +16,6 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class); - Http::macro('github', function (string $api_url, string|null $github_access_token = null) { if ($github_access_token) { return Http::withHeaders([ diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php index 76fa9cc5a..3fa657216 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -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,117 @@ 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-realtime-ws' => + [ + 'entryPoints' => [ + 0 => 'http', + ], + 'service' => 'coolify-realtime', + 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", + ], + ], + '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-https'] = [ + 'entryPoints' => [ + 0 => 'https', + ], + 'service' => 'coolify', + 'rule' => "Host(`{$host}`)", + 'tls' => [ + 'certresolver' => 'letsencrypt', + ], + ]; + $traefik_dynamic_conf['http']['routers']['coolify-realtime-wss'] = [ + 'entryPoints' => [ + 0 => 'https', + ], + 'service' => 'coolify-realtime', + 'rule' => "Host(`{$host}`) && PathPrefix(`/app`)", + '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"; diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 4f0fda777..d9cec50d5 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -29,7 +29,9 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; use Illuminate\Support\Stringable; @@ -1545,3 +1547,19 @@ function generateEnvValue(string $command) } return $generatedValue; } + +function getRealtime() +{ + $envDefined = env('PUSHER_PORT'); + if (empty($envDefined)) { + $url = Url::fromString(Request::getSchemeAndHttpHost()); + $port = $url->getPort(); + if ($port) { + return '6001'; + } else { + return null; + } + } else { + return $envDefined; + } +} diff --git a/config/sentry.php b/config/sentry.php index 6ce447961..1cd69403b 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.156', + 'release' => '4.0.0-beta.157', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 0da84d93c..5c2f640e6 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ -