fix(core): Adding a new server should not try to make the default docker network

This commit is contained in:
Andras Bacsai
2025-02-28 11:23:08 +01:00
parent 9c4395e6de
commit 2f826c56e8

View File

@@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Stringable; use Illuminate\Support\Stringable;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
@@ -24,6 +25,7 @@ use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait; use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
use Spatie\Url\Url; use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Visus\Cuid2\Cuid2;
#[OA\Schema( #[OA\Schema(
description: 'Server model', description: 'Server model',
@@ -101,11 +103,13 @@ class Server extends BaseModel
'server_id' => $server->id, 'server_id' => $server->id,
]); ]);
} else { } else {
StandaloneDocker::create([ $standaloneDocker = new StandaloneDocker([
'name' => 'coolify', 'name' => 'coolify',
'uuid' => (string) new Cuid2,
'network' => 'coolify', 'network' => 'coolify',
'server_id' => $server->id, 'server_id' => $server->id,
]); ]);
$standaloneDocker->saveQuietly();
} }
} }
if (! isset($server->proxy->redirect_enabled)) { if (! isset($server->proxy->redirect_enabled)) {
@@ -705,22 +709,6 @@ $schema://$host {
]; ];
} }
public function getContainersWithSentinel(): Collection
{
$sentinel_found = instant_remote_process(['docker inspect coolify-sentinel'], $this, false);
$sentinel_found = json_decode($sentinel_found, true);
$status = data_get($sentinel_found, '0.State.Status', 'exited');
if ($status === 'running') {
$containers = instant_remote_process(['docker exec coolify-sentinel sh -c "curl http://127.0.0.1:8888/api/containers"'], $this, false);
if (is_null($containers)) {
return collect([]);
}
$containers = data_get(json_decode($containers, true), 'containers', []);
return collect($containers);
}
}
public function loadAllContainers(): Collection public function loadAllContainers(): Collection
{ {
if ($this->isFunctional()) { if ($this->isFunctional()) {
@@ -1036,7 +1024,7 @@ $schema://$host {
$unreachableNotificationSent = (bool) $this->unreachable_notification_sent; $unreachableNotificationSent = (bool) $this->unreachable_notification_sent;
$isReachable = (bool) $this->settings->is_reachable; $isReachable = (bool) $this->settings->is_reachable;
\Log::debug('Server reachability check', [ Log::debug('Server reachability check', [
'server_id' => $this->id, 'server_id' => $this->id,
'is_reachable' => $isReachable, 'is_reachable' => $isReachable,
'notification_sent' => $unreachableNotificationSent, 'notification_sent' => $unreachableNotificationSent,
@@ -1048,7 +1036,7 @@ $schema://$host {
$this->save(); $this->save();
if ($unreachableNotificationSent === true) { if ($unreachableNotificationSent === true) {
\Log::debug('Server is now reachable, sending notification', [ Log::debug('Server is now reachable, sending notification', [
'server_id' => $this->id, 'server_id' => $this->id,
]); ]);
$this->sendReachableNotification(); $this->sendReachableNotification();
@@ -1058,7 +1046,7 @@ $schema://$host {
} }
$this->increment('unreachable_count'); $this->increment('unreachable_count');
\Log::debug('Incremented unreachable count', [ Log::debug('Incremented unreachable count', [
'server_id' => $this->id, 'server_id' => $this->id,
'new_count' => $this->unreachable_count, 'new_count' => $this->unreachable_count,
]); ]);
@@ -1066,7 +1054,7 @@ $schema://$host {
if ($this->unreachable_count === 1) { if ($this->unreachable_count === 1) {
$this->settings->is_reachable = true; $this->settings->is_reachable = true;
$this->settings->save(); $this->settings->save();
\Log::debug('First unreachable attempt, marking as reachable', [ Log::debug('First unreachable attempt, marking as reachable', [
'server_id' => $this->id, 'server_id' => $this->id,
]); ]);
@@ -1077,7 +1065,7 @@ $schema://$host {
$failedChecks = 0; $failedChecks = 0;
for ($i = 0; $i < 3; $i++) { for ($i = 0; $i < 3; $i++) {
$status = $this->serverStatus(); $status = $this->serverStatus();
\Log::debug('Additional reachability check', [ Log::debug('Additional reachability check', [
'server_id' => $this->id, 'server_id' => $this->id,
'attempt' => $i + 1, 'attempt' => $i + 1,
'status' => $status, 'status' => $status,
@@ -1089,7 +1077,7 @@ $schema://$host {
} }
if ($failedChecks === 3 && ! $unreachableNotificationSent) { if ($failedChecks === 3 && ! $unreachableNotificationSent) {
\Log::debug('Server confirmed unreachable after 3 attempts, sending notification', [ Log::debug('Server confirmed unreachable after 3 attempts, sending notification', [
'server_id' => $this->id, 'server_id' => $this->id,
]); ]);
$this->sendUnreachableNotification(); $this->sendUnreachableNotification();