fix: remove networks when deleting a docker compose based app
This commit is contained in:
parent
6b08100819
commit
b37dc4c73e
@ -38,6 +38,11 @@ public function handle(Application $application)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($application->build_pack === 'dockercompose') {
|
||||
$uuid = $application->uuid;
|
||||
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server);
|
||||
instant_remote_process(["docker network rm {$uuid}"], $server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,18 +19,16 @@ public function handle(Service $service)
|
||||
ray('Stopping service: '.$service->name);
|
||||
$applications = $service->applications()->get();
|
||||
foreach ($applications as $application) {
|
||||
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server);
|
||||
instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server, false);
|
||||
$application->update(['status' => 'exited']);
|
||||
}
|
||||
$dbs = $service->databases()->get();
|
||||
foreach ($dbs as $db) {
|
||||
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server);
|
||||
instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server, false);
|
||||
$db->update(['status' => 'exited']);
|
||||
}
|
||||
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server, false);
|
||||
instant_remote_process(["docker network rm {$service->uuid} 2>/dev/null"], $service->server, false);
|
||||
// TODO: make notification for databases
|
||||
// $service->environment->project->team->notify(new StatusChanged($service));
|
||||
instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy"], $service->server);
|
||||
instant_remote_process(["docker network rm {$service->uuid}"], $service->server);
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
ray($e->getMessage());
|
||||
|
@ -5,7 +5,24 @@
|
||||
use App\Models\Server;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
function connectProxyToNetworks(Server $server)
|
||||
function collectProxyDockerNetworksByServer(Server $server)
|
||||
{
|
||||
if (! $server->isFunctional()) {
|
||||
return collect();
|
||||
}
|
||||
$proxyType = $server->proxyType();
|
||||
if (is_null($proxyType) || $proxyType === 'NONE') {
|
||||
return collect();
|
||||
}
|
||||
$networks = instant_remote_process(['docker inspect --format="{{json .NetworkSettings.Networks }}" coolify-proxy'], $server, false);
|
||||
$networks = collect($networks)->map(function ($network) {
|
||||
return collect(json_decode($network))->keys();
|
||||
})->flatten()->unique();
|
||||
|
||||
return $networks;
|
||||
|
||||
}
|
||||
function collectDockerNetworksByServer(Server $server)
|
||||
{
|
||||
if ($server->isSwarm()) {
|
||||
$networks = collect($server->swarmDockers)->map(function ($docker) {
|
||||
@ -43,6 +60,18 @@ function connectProxyToNetworks(Server $server)
|
||||
if ($networks->count() === 0) {
|
||||
$networks = collect(['coolify-overlay']);
|
||||
}
|
||||
} else {
|
||||
if ($networks->count() === 0) {
|
||||
$networks = collect(['coolify']);
|
||||
}
|
||||
}
|
||||
|
||||
return $networks;
|
||||
}
|
||||
function connectProxyToNetworks(Server $server)
|
||||
{
|
||||
$networks = collectDockerNetworksByServer($server);
|
||||
if ($server->isSwarm()) {
|
||||
$commands = $networks->map(function ($network) {
|
||||
return [
|
||||
"echo 'Connecting coolify-proxy to $network network...'",
|
||||
@ -51,9 +80,6 @@ function connectProxyToNetworks(Server $server)
|
||||
];
|
||||
});
|
||||
} else {
|
||||
if ($networks->count() === 0) {
|
||||
$networks = collect(['coolify']);
|
||||
}
|
||||
$commands = $networks->map(function ($network) {
|
||||
return [
|
||||
"echo 'Connecting coolify-proxy to $network network...'",
|
||||
|
Loading…
Reference in New Issue
Block a user