add logic

This commit is contained in:
ayntk-ai
2024-08-09 00:30:11 +02:00
parent 2f95349888
commit 0135e2b5c0
7 changed files with 94 additions and 64 deletions

View File

@@ -43,8 +43,7 @@ class StopApplication
}
if ($application->build_pack === 'dockercompose') {
$uuid = $application->uuid;
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
instant_remote_process(["docker network rm {$uuid}"], $server, false);
$application->delete_connected_networks($uuid);
CleanupDocker::run($server, true);
}

View File

@@ -10,14 +10,16 @@ class DeleteService
{
use AsAction;
public function handle(Service $service, bool $deleteConfigurations, bool $deleteVolumes, bool $deleteImages, bool $deleteNetworks)
public function handle(Service $service, bool $deleteConfigurations, bool $deleteVolumes, bool $deleteImages, bool $deleteConnectedNetworks)
{
try {
$server = data_get($service, 'server');
if ($server->isFunctional()) {
$storagesToDelete = collect([]);
$service->environment_variables()->delete();
$commands = [];
foreach ($service->applications()->get() as $application) {
$storages = $application->persistentStorages()->get();
@@ -31,21 +33,34 @@ class DeleteService
$storagesToDelete->push($storage);
}
}
foreach ($storagesToDelete as $storage) {
$commands[] = "docker volume rm -f $storage->name";
// Delete volumes if the flag is set
if ($deleteVolumes) {
foreach ($service->applications()->get() as $application) {
$persistentStorages = $application->persistentStorages()->get();
$application->delete_volumes($persistentStorages);
}
}
$uuid = $service->uuid;
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
instant_remote_process(["docker network rm {$uuid}"], $server, false);
// Delete networks if the flag is set
if ($deleteConnectedNetworks) {
$uuid = $service->uuid;
$service->delete_connected_networks($uuid);
}
// Command to remove the service itself
$commands[] = "docker rm -f $service->uuid";
// Execute all commands
instant_remote_process($commands, $server, false);
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
} finally {
// Delete configurations if the flag is set
if ($deleteConfigurations) {
$service->delete_configurations();
}
foreach ($service->applications()->get() as $application) {
$application->forceDelete();
}
@@ -58,7 +73,10 @@ class DeleteService
$service->tags()->detach();
$service->forceDelete();
CleanupDocker::run($server, true);
// Run cleanup if images need to be deleted
if ($deleteImages) {
CleanupDocker::run($server, true);
}
}
}
}
}