add logic
This commit is contained in:
@@ -43,8 +43,7 @@ class StopApplication
|
|||||||
}
|
}
|
||||||
if ($application->build_pack === 'dockercompose') {
|
if ($application->build_pack === 'dockercompose') {
|
||||||
$uuid = $application->uuid;
|
$uuid = $application->uuid;
|
||||||
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
|
$application->delete_connected_networks($uuid);
|
||||||
instant_remote_process(["docker network rm {$uuid}"], $server, false);
|
|
||||||
|
|
||||||
CleanupDocker::run($server, true);
|
CleanupDocker::run($server, true);
|
||||||
}
|
}
|
||||||
|
@@ -10,14 +10,16 @@ class DeleteService
|
|||||||
{
|
{
|
||||||
use AsAction;
|
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 {
|
try {
|
||||||
$server = data_get($service, 'server');
|
$server = data_get($service, 'server');
|
||||||
|
|
||||||
if ($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();
|
||||||
@@ -31,21 +33,34 @@ class DeleteService
|
|||||||
$storagesToDelete->push($storage);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete networks if the flag is set
|
||||||
|
if ($deleteConnectedNetworks) {
|
||||||
$uuid = $service->uuid;
|
$uuid = $service->uuid;
|
||||||
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
|
$service->delete_connected_networks($uuid);
|
||||||
instant_remote_process(["docker network rm {$uuid}"], $server, false);
|
}
|
||||||
|
|
||||||
|
// Command to remove the service itself
|
||||||
$commands[] = "docker rm -f $service->uuid";
|
$commands[] = "docker rm -f $service->uuid";
|
||||||
|
|
||||||
|
// Execute all commands
|
||||||
instant_remote_process($commands, $server, false);
|
instant_remote_process($commands, $server, false);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
// Delete configurations if the flag is set
|
||||||
|
if ($deleteConfigurations) {
|
||||||
|
$service->delete_configurations();
|
||||||
|
}
|
||||||
foreach ($service->applications()->get() as $application) {
|
foreach ($service->applications()->get() as $application) {
|
||||||
$application->forceDelete();
|
$application->forceDelete();
|
||||||
}
|
}
|
||||||
@@ -58,7 +73,10 @@ class DeleteService
|
|||||||
$service->tags()->detach();
|
$service->tags()->detach();
|
||||||
$service->forceDelete();
|
$service->forceDelete();
|
||||||
|
|
||||||
|
// Run cleanup if images need to be deleted
|
||||||
|
if ($deleteImages) {
|
||||||
CleanupDocker::run($server, true);
|
CleanupDocker::run($server, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -31,10 +31,10 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource,
|
public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource,
|
||||||
public bool $deleteConfigurations = false,
|
public bool $deleteConfigurations,
|
||||||
public bool $deleteVolumes = false,
|
public bool $deleteVolumes,
|
||||||
public bool $deleteImages = false,
|
public bool $deleteImages,
|
||||||
public bool $deleteNetworks = false
|
public bool $deleteConnectedNetworks
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
break;
|
break;
|
||||||
case 'service':
|
case 'service':
|
||||||
StopService::run($this->resource);
|
StopService::run($this->resource);
|
||||||
DeleteService::run($this->resource);
|
DeleteService::run($this->resource, $this->deleteConfigurations, $this->deleteVolumes, $this->deleteImages, $this->deleteConnectedNetworks);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,20 +72,16 @@ class DeleteResourceJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
$this->resource?->delete_volumes($persistentStorages);
|
$this->resource?->delete_volumes($persistentStorages);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->deleteImages) {
|
|
||||||
// Logic to delete images
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->deleteNetworks) {
|
|
||||||
// Logic to delete networks
|
|
||||||
}
|
|
||||||
|
|
||||||
$server = data_get($this->resource, 'server');
|
$server = data_get($this->resource, 'server');
|
||||||
if ($server) {
|
if ($this->deleteImages && $server) {
|
||||||
CleanupDocker::run($server, true);
|
CleanupDocker::run($server, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->deleteConnectedNetworks) {
|
||||||
|
$uuid = $this->resource->uuid; // Get the UUID from the resource
|
||||||
|
$this->resource?->delete_connected_networks($uuid); // Pass the UUID to the method
|
||||||
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
ray($e->getMessage());
|
|
||||||
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
|
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
|
||||||
throw $e;
|
throw $e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@@ -18,6 +18,10 @@ class Danger extends Component
|
|||||||
|
|
||||||
public bool $delete_volumes = true;
|
public bool $delete_volumes = true;
|
||||||
|
|
||||||
|
public bool $delete_images = true;
|
||||||
|
|
||||||
|
public bool $delete_connected_networks = true;
|
||||||
|
|
||||||
public ?string $modalId = null;
|
public ?string $modalId = null;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
@@ -33,7 +37,13 @@ class Danger extends Component
|
|||||||
try {
|
try {
|
||||||
// $this->authorize('delete', $this->resource);
|
// $this->authorize('delete', $this->resource);
|
||||||
$this->resource->delete();
|
$this->resource->delete();
|
||||||
DeleteResourceJob::dispatch($this->resource, $this->delete_configurations, $this->delete_volumes);
|
DeleteResourceJob::dispatch(
|
||||||
|
$this->resource,
|
||||||
|
$this->delete_configurations,
|
||||||
|
$this->delete_volumes,
|
||||||
|
$this->delete_images,
|
||||||
|
$this->delete_connected_networks
|
||||||
|
);
|
||||||
|
|
||||||
return redirect()->route('project.resource.index', [
|
return redirect()->route('project.resource.index', [
|
||||||
'project_uuid' => $this->projectUuid,
|
'project_uuid' => $this->projectUuid,
|
||||||
|
@@ -173,6 +173,15 @@ class Application extends BaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete_connected_networks($uuid)
|
||||||
|
{
|
||||||
|
$server = data_get($this, 'destination.server');
|
||||||
|
ray($uuid);
|
||||||
|
instant_remote_process(["docker network disconnect {$uuid} coolify-proxy"], $server, false);
|
||||||
|
instant_remote_process(["docker network rm {$uuid}"], $server, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function additional_servers()
|
public function additional_servers()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Server::class, 'additional_destinations')
|
return $this->belongsToMany(Server::class, 'additional_destinations')
|
||||||
@@ -1178,7 +1187,6 @@ class Application extends BaseModel
|
|||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
|
throw new \RuntimeException("Docker Compose file not found at: $workdir$composeFile<br><br>Check if you used the right extension (.yaml or .yml) in the compose file name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseContainerLabels(?ApplicationPreview $preview = null)
|
public function parseContainerLabels(?ApplicationPreview $preview = null)
|
||||||
|
@@ -9,10 +9,9 @@
|
|||||||
<div class="px-2">This resource will be deleted. It is not reversible. <strong class="text-error">Please think
|
<div class="px-2">This resource will be deleted. It is not reversible. <strong class="text-error">Please think
|
||||||
again.</strong><br><br></div>
|
again.</strong><br><br></div>
|
||||||
<h4>Actions</h4>
|
<h4>Actions</h4>
|
||||||
<x-forms.checkbox id="delete_configurations"
|
<x-forms.checkbox id="delete_configurations" wire:model="delete_configurations" label="Permanently delete configuration files from the server?"></x-forms.checkbox>
|
||||||
label="Permanently delete configuration files from the server?"></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_volumes" label="Permanently delete associated volumes?"></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" label="Permanently delete associated unused images?"></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" label="Permanently delete all connected networks, this includes predfined ones?"></x-forms.checkbox>
|
|
||||||
</x-modal-confirmation>
|
</x-modal-confirmation>
|
||||||
</div>
|
</div>
|
Reference in New Issue
Block a user