Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -15,7 +15,6 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Throwable;
class Init extends Command
{
@@ -23,7 +22,7 @@ class Init extends Command
protected $description = 'Cleanup instance related stuffs';
public $servers;
public $servers = null;
public function handle()
{
@@ -36,7 +35,8 @@ class Init extends Command
}
$this->servers = Server::all();
if (! isCloud()) {
if (isCloud()) {
} else {
$this->send_alive_signal();
get_public_ips();
}
@@ -61,14 +61,14 @@ class Init extends Command
try {
$this->pullHelperImage();
} catch (Throwable $e) {
} catch (\Throwable $e) {
//
}
if (isCloud()) {
try {
$this->pullTemplatesFromCDN();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n";
}
}
@@ -76,13 +76,13 @@ class Init extends Command
if (! isCloud()) {
try {
$this->pullTemplatesFromCDN();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not pull templates from CDN: {$e->getMessage()}\n";
}
try {
$localhost = $this->servers->where('id', 0)->first();
$localhost->setupDynamicProxyConfiguration();
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Could not setup dynamic configuration: {$e->getMessage()}\n";
}
$settings = instanceSettings();
@@ -119,8 +119,8 @@ class Init extends Command
private function update_user_emails()
{
try {
User::query()->whereRaw('email ~ \'[A-Z]\'')->get()->each(fn (User $user) => $user->update(['email' => strtolower($user->email)]));
} catch (Throwable $e) {
User::whereRaw('email ~ \'[A-Z]\'')->get()->each(fn (User $user) => $user->update(['email' => strtolower($user->email)]));
} catch (\Throwable $e) {
echo "Error in updating user emails: {$e->getMessage()}\n";
}
}
@@ -128,8 +128,8 @@ class Init extends Command
private function update_traefik_labels()
{
try {
Server::query()->where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']);
} catch (Throwable $e) {
Server::where('proxy->type', 'TRAEFIK_V2')->update(['proxy->type' => 'TRAEFIK']);
} catch (\Throwable $e) {
echo "Error in updating traefik labels: {$e->getMessage()}\n";
}
}
@@ -149,12 +149,10 @@ class Init extends Command
return instant_remote_process([
"rm -f $file",
], $server, false);
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning up unnecessary dynamic proxy configuration: {$e->getMessage()}\n";
}
}
return null;
}
private function cleanup_unused_network_from_coolify_proxy()
@@ -170,19 +168,19 @@ class Init extends Command
['networks' => $networks, 'allNetworks' => $allNetworks] = collectDockerNetworksByServer($server);
$removeNetworks = $allNetworks->diff($networks);
$commands = collect();
foreach ($removeNetworks as $removeNetwork) {
$out = instant_remote_process(["docker network inspect -f json {$removeNetwork} | jq '.[].Containers | if . == {} then null else . end'"], $server, false);
if ($out === null || $out === '' || $out === '0') {
$commands->push("docker network disconnect {$removeNetwork} coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm {$removeNetwork} >/dev/null 2>&1 || true");
foreach ($removeNetworks as $network) {
$out = instant_remote_process(["docker network inspect -f json $network | jq '.[].Containers | if . == {} then null else . end'"], $server, false);
if (empty($out)) {
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm $network >/dev/null 2>&1 || true");
} else {
$data = collect(json_decode($out, true));
if ($data->count() === 1) {
// If only coolify-proxy itself is connected to that network (it should not be possible, but who knows)
$isCoolifyProxyItself = data_get($data->first(), 'Name') === 'coolify-proxy';
if ($isCoolifyProxyItself) {
$commands->push("docker network disconnect {$removeNetwork} coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm {$removeNetwork} >/dev/null 2>&1 || true");
$commands->push("docker network disconnect $network coolify-proxy >/dev/null 2>&1 || true");
$commands->push("docker network rm $network >/dev/null 2>&1 || true");
}
}
}
@@ -190,7 +188,7 @@ class Init extends Command
if ($commands->isNotEmpty()) {
remote_process(command: $commands, type: ActivityTypes::INLINE->value, server: $server, ignore_errors: false);
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in cleaning up unused networks from coolify proxy: {$e->getMessage()}\n";
}
}
@@ -204,20 +202,20 @@ class Init extends Command
if ($database && $database->trashed()) {
echo "Restoring coolify db backup\n";
$database->restore();
$scheduledBackup = ScheduledDatabaseBackup::query()->find(0);
$scheduledBackup = ScheduledDatabaseBackup::find(0);
if (! $scheduledBackup) {
ScheduledDatabaseBackup::query()->create([
ScheduledDatabaseBackup::create([
'id' => 0,
'enabled' => true,
'save_s3' => false,
'frequency' => '0 0 * * *',
'database_id' => $database->id,
'database_type' => StandalonePostgresql::class,
'database_type' => \App\Models\StandalonePostgresql::class,
'team_id' => 0,
]);
}
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in restoring coolify db backup: {$e->getMessage()}\n";
}
}
@@ -236,7 +234,7 @@ class Init extends Command
}
try {
Http::get("https://undead.coolify.io/v4/alive?appId=$id&version=$version");
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error in sending live signal: {$e->getMessage()}\n";
}
}
@@ -248,12 +246,12 @@ class Init extends Command
if (isCloud()) {
return;
}
$queued_inprogress_deployments = ApplicationDeploymentQueue::query()->whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS->value, ApplicationDeploymentStatus::QUEUED->value])->get();
foreach ($queued_inprogress_deployments as $queued_inprogress_deployment) {
$queued_inprogress_deployment->status = ApplicationDeploymentStatus::FAILED->value;
$queued_inprogress_deployment->save();
$queued_inprogress_deployments = ApplicationDeploymentQueue::whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS->value, ApplicationDeploymentStatus::QUEUED->value])->get();
foreach ($queued_inprogress_deployments as $deployment) {
$deployment->status = ApplicationDeploymentStatus::FAILED->value;
$deployment->save();
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
echo "Error: {$e->getMessage()}\n";
}
}