fix: stop database proxy when is_public changes to false (#8138)
This commit is contained in:
commit
710a3ad958
3 changed files with 49 additions and 17 deletions
|
|
@ -25,7 +25,6 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
|
||||||
$server = data_get($database, 'destination.server');
|
$server = data_get($database, 'destination.server');
|
||||||
$uuid = $database->uuid;
|
$uuid = $database->uuid;
|
||||||
if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||||
$uuid = $database->service->uuid;
|
|
||||||
$server = data_get($database, 'service.server');
|
$server = data_get($database, 'service.server');
|
||||||
}
|
}
|
||||||
instant_remote_process(["docker rm -f {$uuid}-proxy"], $server);
|
instant_remote_process(["docker rm -f {$uuid}-proxy"], $server);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Actions\Docker;
|
namespace App\Actions\Docker;
|
||||||
|
|
||||||
use App\Actions\Database\StartDatabaseProxy;
|
use App\Actions\Database\StartDatabaseProxy;
|
||||||
|
use App\Actions\Database\StopDatabaseProxy;
|
||||||
use App\Actions\Shared\ComplexStatusCheck;
|
use App\Actions\Shared\ComplexStatusCheck;
|
||||||
use App\Events\ServiceChecked;
|
use App\Events\ServiceChecked;
|
||||||
use App\Models\ApplicationPreview;
|
use App\Models\ApplicationPreview;
|
||||||
|
|
@ -180,21 +181,30 @@ public function handle(Server $server, ?Collection $containers = null, ?Collecti
|
||||||
if ($database_id) {
|
if ($database_id) {
|
||||||
$service_db = ServiceDatabase::where('id', $database_id)->first();
|
$service_db = ServiceDatabase::where('id', $database_id)->first();
|
||||||
if ($service_db) {
|
if ($service_db) {
|
||||||
$uuid = data_get($service_db, 'service.uuid');
|
$proxyUuid = $service_db->uuid;
|
||||||
if ($uuid) {
|
$isPublic = data_get($service_db, 'is_public');
|
||||||
$isPublic = data_get($service_db, 'is_public');
|
if ($isPublic) {
|
||||||
if ($isPublic) {
|
$foundTcpProxy = $this->containers->filter(function ($value, $key) use ($proxyUuid) {
|
||||||
$foundTcpProxy = $this->containers->filter(function ($value, $key) use ($uuid) {
|
if ($this->server->isSwarm()) {
|
||||||
if ($this->server->isSwarm()) {
|
return data_get($value, 'Spec.Name') === "coolify-proxy_$proxyUuid";
|
||||||
return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid";
|
} else {
|
||||||
} else {
|
return data_get($value, 'Name') === "/$proxyUuid-proxy";
|
||||||
return data_get($value, 'Name') === "/$uuid-proxy";
|
|
||||||
}
|
|
||||||
})->first();
|
|
||||||
if (! $foundTcpProxy) {
|
|
||||||
StartDatabaseProxy::run($service_db);
|
|
||||||
// $this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$service_db->service->name}", $this->server));
|
|
||||||
}
|
}
|
||||||
|
})->first();
|
||||||
|
if (! $foundTcpProxy) {
|
||||||
|
StartDatabaseProxy::run($service_db);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Clean up orphaned proxy when is_public=false
|
||||||
|
$orphanedProxy = $this->containers->filter(function ($value, $key) use ($proxyUuid) {
|
||||||
|
if ($this->server->isSwarm()) {
|
||||||
|
return data_get($value, 'Spec.Name') === "coolify-proxy_$proxyUuid";
|
||||||
|
} else {
|
||||||
|
return data_get($value, 'Name') === "/$proxyUuid-proxy";
|
||||||
|
}
|
||||||
|
})->first();
|
||||||
|
if ($orphanedProxy) {
|
||||||
|
StopDatabaseProxy::run($service_db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -235,7 +245,18 @@ public function handle(Server $server, ?Collection $containers = null, ?Collecti
|
||||||
})->first();
|
})->first();
|
||||||
if (! $foundTcpProxy) {
|
if (! $foundTcpProxy) {
|
||||||
StartDatabaseProxy::run($database);
|
StartDatabaseProxy::run($database);
|
||||||
// $this->server->team?->notify(new ContainerRestarted("TCP Proxy for database", $this->server));
|
}
|
||||||
|
} else {
|
||||||
|
// Clean up orphaned proxy when is_public=false
|
||||||
|
$orphanedProxy = $this->containers->filter(function ($value, $key) use ($uuid) {
|
||||||
|
if ($this->server->isSwarm()) {
|
||||||
|
return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid";
|
||||||
|
} else {
|
||||||
|
return data_get($value, 'Name') === "/$uuid-proxy";
|
||||||
|
}
|
||||||
|
})->first();
|
||||||
|
if ($orphanedProxy) {
|
||||||
|
StopDatabaseProxy::run($database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -393,6 +414,11 @@ public function handle(Server $server, ?Collection $containers = null, ?Collecti
|
||||||
'last_restart_type' => null,
|
'last_restart_type' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Stop proxy if database was public
|
||||||
|
if ($database->is_public) {
|
||||||
|
StopDatabaseProxy::run($database);
|
||||||
|
}
|
||||||
|
|
||||||
$name = data_get($database, 'name');
|
$name = data_get($database, 'name');
|
||||||
$fqdn = data_get($database, 'fqdn');
|
$fqdn = data_get($database, 'fqdn');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -496,7 +496,14 @@ private function updateDatabaseStatus(string $databaseUuid, string $containerSta
|
||||||
if (! $tcpProxyContainerFound) {
|
if (! $tcpProxyContainerFound) {
|
||||||
StartDatabaseProxy::dispatch($database);
|
StartDatabaseProxy::dispatch($database);
|
||||||
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server));
|
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server));
|
||||||
} else {
|
}
|
||||||
|
} elseif ($this->isRunning($containerStatus) && ! $tcpProxy) {
|
||||||
|
// Clean up orphaned proxy containers when is_public=false
|
||||||
|
$orphanedProxy = $this->containers->filter(function ($value, $key) use ($databaseUuid) {
|
||||||
|
return data_get($value, 'name') === "$databaseUuid-proxy" && data_get($value, 'state') === 'running';
|
||||||
|
})->first();
|
||||||
|
if ($orphanedProxy) {
|
||||||
|
StopDatabaseProxy::dispatch($database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue