mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-18 12:33:06 +00:00
fix volume deletion for services
This commit is contained in:
@@ -14,12 +14,10 @@ class DeleteService
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$server = data_get($service, 'server');
|
$server = data_get($service, 'server');
|
||||||
|
if ($deleteVolumes && $server->isFunctional()) {
|
||||||
if ($server->isFunctional()) {
|
|
||||||
$storagesToDelete = collect([]);
|
$storagesToDelete = collect([]);
|
||||||
|
|
||||||
$service->environment_variables()->delete();
|
$service->environment_variables()->delete();
|
||||||
|
|
||||||
$commands = [];
|
$commands = [];
|
||||||
foreach ($service->applications()->get() as $application) {
|
foreach ($service->applications()->get() as $application) {
|
||||||
$storages = $application->persistentStorages()->get();
|
$storages = $application->persistentStorages()->get();
|
||||||
@@ -33,27 +31,33 @@ class DeleteService
|
|||||||
$storagesToDelete->push($storage);
|
$storagesToDelete->push($storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($storagesToDelete as $storage) {
|
||||||
// Delete volumes if the flag is set
|
$commands[] = "docker volume rm -f $storage->name";
|
||||||
if ($deleteVolumes) {
|
|
||||||
foreach ($service->applications()->get() as $application) {
|
|
||||||
$persistentStorages = $application->persistentStorages()->get();
|
|
||||||
$application->delete_volumes($persistentStorages);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// Execute all commands
|
||||||
instant_remote_process($commands, $server, false);
|
if (!empty($commands)) {
|
||||||
|
foreach ($commands as $command) {
|
||||||
|
$result = instant_remote_process([$command], $server, false);
|
||||||
|
if ($result !== 0) {
|
||||||
|
ray("Failed to execute: $command");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
} catch (\Exception $e) {
|
||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
again.</strong><br><br></div>
|
again.</strong><br><br></div>
|
||||||
<h4>Actions</h4>
|
<h4>Actions</h4>
|
||||||
<x-forms.checkbox id="delete_volumes" wire:model="delete_volumes" label="Permanently delete associated volumes?"></x-forms.checkbox>
|
<x-forms.checkbox id="delete_volumes" wire:model="delete_volumes" label="Permanently delete associated volumes?"></x-forms.checkbox>
|
||||||
<x-forms.checkbox id="delete_connected_networks" wire:model="delete_connected_networks" label="Permanently delete all connected networks, this includes predefined ones?"></x-forms.checkbox>
|
<x-forms.checkbox id="delete_connected_networks" wire:model="delete_connected_networks" label="Permanently delete connected networks, predefined Networks are not deleted?"></x-forms.checkbox>
|
||||||
<x-forms.checkbox id="delete_configurations" wire:model="delete_configurations" label="Permanently delete configuration files from the server?"></x-forms.checkbox>
|
<x-forms.checkbox id="delete_configurations" wire:model="delete_configurations" label="Permanently delete configuration files from the server?"></x-forms.checkbox>
|
||||||
<x-forms.checkbox id="delete_images" wire:model="delete_images" label="Permanently delete associated unused images?"></x-forms.checkbox>
|
<x-forms.checkbox id="delete_images" wire:model="delete_images" label="Permanently delete associated unused images?"></x-forms.checkbox>
|
||||||
</x-modal-confirmation>
|
</x-modal-confirmation>
|
||||||
|
|||||||
Reference in New Issue
Block a user