refactor: Cleanup unnecessary dynamic proxy configuration in Init command

This commit is contained in:
Andras Bacsai
2024-08-06 10:53:13 +02:00
parent 74e8a4a703
commit e3c7c615c6
2 changed files with 29 additions and 21 deletions

View File

@@ -21,13 +21,15 @@ class Init extends Command
protected $description = 'Cleanup instance related stuffs'; protected $description = 'Cleanup instance related stuffs';
public $servers = null;
public function handle() public function handle()
{ {
$this->servers = Server::all();
$this->alive(); $this->alive();
get_public_ips(); get_public_ips();
if (version_compare('4.0.0-beta.312', config('version'), '<=')) { if (version_compare('4.0.0-beta.312', config('version'), '<=')) {
$servers = Server::all(); foreach ($this->servers as $server) {
foreach ($servers as $server) {
if ($server->settings->is_metrics_enabled === true) { if ($server->settings->is_metrics_enabled === true) {
$server->settings->update(['is_metrics_enabled' => false]); $server->settings->update(['is_metrics_enabled' => false]);
} }
@@ -57,14 +59,15 @@ class Init extends Command
// Required for falsely deleted coolify db // Required for falsely deleted coolify db
$this->restore_coolify_db_backup(); $this->restore_coolify_db_backup();
$this->cleanup_unused_network_from_coolify_proxy(); $this->cleanup_unused_network_from_coolify_proxy();
$this->cleanup_unnecessary_dynamic_proxy_configuration();
$this->cleanup_in_progress_application_deployments(); $this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers(); $this->cleanup_stucked_helper_containers();
$this->call('cleanup:queue'); $this->call('cleanup:queue');
$this->call('cleanup:stucked-resources'); $this->call('cleanup:stucked-resources');
if (! isCloud()) { if (! isCloud()) {
try { try {
$server = Server::find(0)->first(); $localhost = $this->servers->where('id', 0)->first();
$server->setupDynamicProxyConfiguration(); $localhost->setupDynamicProxyConfiguration();
} catch (\Throwable $e) { } catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n"; echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
} }
@@ -85,11 +88,30 @@ class Init extends Command
$this->call('cleanup:stucked-resources'); $this->call('cleanup:stucked-resources');
} }
private function cleanup_unnecessary_dynamic_proxy_configuration()
{
if (isCloud()) {
foreach ($this->servers as $server) {
if (! $server->isFunctional()) {
continue;
}
if ($server->id === 0) {
continue;
}
$file = $server->proxyPath().'/dynamic/coolify.yaml';
return instant_remote_process([
"rm -f $file",
], $server, false);
}
}
}
private function cleanup_unused_network_from_coolify_proxy() private function cleanup_unused_network_from_coolify_proxy()
{ {
ray()->clearAll(); ray()->clearAll();
$servers = Server::all(); foreach ($this->servers as $server) {
foreach ($servers as $server) {
if (! $server->isFunctional()) { if (! $server->isFunctional()) {
continue; continue;
} }
@@ -150,8 +172,7 @@ class Init extends Command
private function cleanup_stucked_helper_containers() private function cleanup_stucked_helper_containers()
{ {
$servers = Server::all(); foreach ($this->servers as $server) {
foreach ($servers as $server) {
if ($server->isFunctional()) { if ($server->isFunctional()) {
CleanupHelperContainersJob::dispatch($server); CleanupHelperContainersJob::dispatch($server);
} }

View File

@@ -106,7 +106,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
private function serverStatus() private function serverStatus()
{ {
$this->removeUnnevessaryCoolifyYaml();
['uptime' => $uptime] = $this->server->validateConnection(); ['uptime' => $uptime] = $this->server->validateConnection();
if ($uptime) { if ($uptime) {
if ($this->server->unreachable_notification_sent === true) { if ($this->server->unreachable_notification_sent === true) {
@@ -138,18 +137,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
} }
private function removeUnnevessaryCoolifyYaml()
{
// This will remote the coolify.yaml file from the server as it is not needed on cloud servers
if (isCloud() && $this->server->id !== 0) {
$file = $this->server->proxyPath().'/dynamic/coolify.yaml';
return instant_remote_process([
"rm -f $file",
], $this->server, false);
}
}
private function checkLogDrainContainer() private function checkLogDrainContainer()
{ {
$foundLogDrainContainer = $this->containers->filter(function ($value, $key) { $foundLogDrainContainer = $this->containers->filter(function ($value, $key) {