Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

chore: prepare for PR

Andras Bacsaifc229c48893e
diff --git a/app/Actions/Database/StopDatabaseProxy.php b/app/Actions/Database/StopDatabaseProxy.php
index a753153eb5..96a1097662 100644
--- a/app/Actions/Database/StopDatabaseProxy.php
+++ b/app/Actions/Database/StopDatabaseProxy.php
@@ -25,7 +25,6 @@ class StopDatabaseProxy
$server = data_get($database, 'destination.server');
$uuid = $database->uuid;
if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) {
- $uuid = $database->service->uuid;
$server = data_get($database, 'service.server');
}
instant_remote_process(["docker rm -f {$uuid}-proxy"], $server);
diff --git a/app/Actions/Docker/GetContainersStatus.php b/app/Actions/Docker/GetContainersStatus.php
index c8e3162c04..6c9a54f778 100644
--- a/app/Actions/Docker/GetContainersStatus.php
+++ b/app/Actions/Docker/GetContainersStatus.php
@@ -3,6 +3,7 @@
namespace App\Actions\Docker;
use App\Actions\Database\StartDatabaseProxy;
+use App\Actions\Database\StopDatabaseProxy;
use App\Actions\Shared\ComplexStatusCheck;
use App\Events\ServiceChecked;
use App\Models\ApplicationPreview;
@@ -180,21 +181,30 @@ class GetContainersStatus
if ($database_id) {
$service_db = ServiceDatabase::where('id', $database_id)->first();
if ($service_db) {
- $uuid = data_get($service_db, 'service.uuid');
- if ($uuid) {
- $isPublic = data_get($service_db, 'is_public');
- if ($isPublic) {
- $foundTcpProxy = $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 (! $foundTcpProxy) {
- StartDatabaseProxy::run($service_db);
- // $this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$service_db->service->name}", $this->server));
+ $proxyUuid = $service_db->uuid;
+ $isPublic = data_get($service_db, 'is_public');
+ if ($isPublic) {
+ $foundTcpProxy = $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 (! $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 @@ class GetContainersStatus
})->first();
if (! $foundTcpProxy) {
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 {
@@ -393,6 +414,11 @@ class GetContainersStatus
'last_restart_type' => null,
]);
+ // Stop proxy if database was public
+ if ($database->is_public) {
+ StopDatabaseProxy::run($database);
+ }
+
$name = data_get($database, 'name');
$fqdn = data_get($database, 'fqdn');
diff --git a/app/Jobs/PushServerUpdateJob.php b/app/Jobs/PushServerUpdateJob.php
index e5a6e0c993..c02a7e3c5c 100644
--- a/app/Jobs/PushServerUpdateJob.php
+++ b/app/Jobs/PushServerUpdateJob.php
@@ -496,7 +496,14 @@ class PushServerUpdateJob implements ShouldBeEncrypted, ShouldQueue, Silenced
if (! $tcpProxyContainerFound) {
StartDatabaseProxy::dispatch($database);
$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);
}
}
}