Skip to content

Commit

Permalink
Merge pull request #3502 from coollabsio/fix-#2546-deletion-issues
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
andrasbacsai committed Sep 19, 2024
2 parents 4b02deb + 636de24 commit eb10bbb
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 315 deletions.
7 changes: 3 additions & 4 deletions app/Actions/Database/StopDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Database;

use App\Actions\Server\CleanupDocker;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
Expand All @@ -12,7 +13,6 @@
use App\Models\StandaloneRedis;
use Illuminate\Support\Facades\Process;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Actions\Server\CleanupDocker;

class StopDatabase
{
Expand All @@ -21,13 +21,12 @@ class StopDatabase
public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $database, bool $isDeleteOperation = false, bool $dockerCleanup = true)
{
$server = $database->destination->server;
if (!$server->isFunctional()) {
if (! $server->isFunctional()) {
return 'Server is not functional';
}

$this->stopContainer($database, $database->uuid, 300);
if (!$isDeleteOperation) {
$this->deleteConnectedNetworks($database->uuid, $server); //Probably not needed as DBs do not have a network normally
if (! $isDeleteOperation) {
if ($dockerCleanup) {
CleanupDocker::run($server, true);
}
Expand Down
9 changes: 4 additions & 5 deletions app/Jobs/DeleteResourceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Actions\Application\StopApplication;
use App\Actions\Database\StopDatabase;
use App\Actions\Server\CleanupDocker;
use App\Actions\Service\DeleteService;
use App\Actions\Service\StopService;
use App\Actions\Server\CleanupDocker;
use App\Models\Application;
use App\Models\Service;
use App\Models\StandaloneClickhouse;
Expand Down Expand Up @@ -35,8 +35,7 @@ public function __construct(
public bool $deleteVolumes,
public bool $dockerCleanup,
public bool $deleteConnectedNetworks
) {
}
) {}

public function handle()
{
Expand Down Expand Up @@ -84,11 +83,11 @@ public function handle()
CleanupDocker::run($server, true);
}

if ($this->deleteConnectedNetworks) {
if ($this->deleteConnectedNetworks && ! $isDatabase) {
$this->resource?->delete_connected_networks($this->resource->uuid);
}
} catch (\Throwable $e) {
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
send_internal_notification('ContainerStoppingJob failed with: '.$e->getMessage());
throw $e;
} finally {
$this->resource->forceDelete();
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/Project/Application/Heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function render()
{
return view('livewire.project.application.heading', [
'checkboxes' => [
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'],
]
['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')],
],
]);
}
}
4 changes: 2 additions & 2 deletions app/Livewire/Project/Database/Heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function render()
{
return view('livewire.project.database.heading', [
'checkboxes' => [
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'],
]
['id' => 'docker_cleanup', 'label' => 'Cleanup docker build cache and unused images (next deployment could take longer).'],
],
]);
}
}
6 changes: 3 additions & 3 deletions app/Livewire/Project/Service/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Navbar extends Component
public $isDeploymentProgress = false;

public $docker_cleanup = true;

public $title = 'Configuration';

public function mount()
Expand Down Expand Up @@ -119,9 +120,8 @@ public function render()
{
return view('livewire.project.service.navbar', [
'checkboxes' => [
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images (the next deployment will take longer as the images have to be pulled again)'],
]
['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')],
],
]);
}

}
17 changes: 9 additions & 8 deletions app/Livewire/Project/Service/ServiceApplicationView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Livewire\Project\Service;

use App\Models\ServiceApplication;
use Livewire\Component;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;

class ServiceApplicationView extends Component
{
Expand All @@ -14,8 +14,8 @@ class ServiceApplicationView extends Component
public $parameters;

public $docker_cleanup = true;

public $delete_volumes = true;


protected $rules = [
'application.human_name' => 'nullable',
Expand All @@ -29,7 +29,7 @@ class ServiceApplicationView extends Component
'application.is_stripprefix_enabled' => 'nullable|boolean',
];

public function updatedApplicationFqdn()
public function updatedApplicationFqdn()
{
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
Expand Down Expand Up @@ -59,8 +59,9 @@ public function instantSaveAdvanced()

public function delete($password)
{
if (!Hash::check($password, Auth::user()->password)) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');

return;
}

Expand Down Expand Up @@ -102,12 +103,12 @@ public function render()
{
return view('livewire.project.service.service-application-view', [
'checkboxes' => [
['id' => 'delete_volumes', 'label' => 'All associated volumes with this resource will be permanently deleted'],
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images'],
['id' => 'delete_volumes', 'label' => __('resource.delete_volumes')],
['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')],
// ['id' => 'delete_associated_backups_locally', 'label' => 'All backups associated with this Ressource will be permanently deleted from local storage.'],
// ['id' => 'delete_associated_backups_s3', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected S3 Storage.'],
// ['id' => 'delete_associated_backups_sftp', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected SFTP Storage.']
]
],
]);
}
}
35 changes: 24 additions & 11 deletions app/Livewire/Project/Shared/Danger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@

use App\Jobs\DeleteResourceJob;
use App\Models\Service;
use App\Models\ServiceDatabase;
use App\Models\ServiceApplication;
use App\Models\ServiceDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;

class Danger extends Component
{
public $resource;

public $resourceName;

public $projectUuid;

public $environmentName;

public bool $delete_configurations = true;

public bool $delete_volumes = true;

public bool $docker_cleanup = true;

public bool $delete_connected_networks = true;

public ?string $modalId = null;

public string $resourceDomain = '';

public function mount()
Expand All @@ -42,11 +51,13 @@ public function mount()

if ($this->resource === null) {
$this->resourceName = 'Unknown Resource';

return;
}

if (!method_exists($this->resource, 'type')) {
if (! method_exists($this->resource, 'type')) {
$this->resourceName = 'Unknown Resource';

return;
}

Expand Down Expand Up @@ -80,13 +91,15 @@ public function mount()

public function delete($password)
{
if (!Hash::check($password, Auth::user()->password)) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');

return;
}

if (!$this->resource) {
if (! $this->resource) {
$this->addError('resource', 'Resource not found.');

return;
}

Expand All @@ -113,14 +126,14 @@ public function render()
{
return view('livewire.project.shared.danger', [
'checkboxes' => [
['id' => 'delete_volumes', 'label' => 'All associated volumes with this resource will be permanently deleted'],
['id' => 'delete_connected_networks', 'label' => 'All connected networks with this resource will be permanently deleted (predefined networks will not be deleted)'],
['id' => 'delete_configurations', 'label' => 'All configuration files will be permanently deleted form the server'],
['id' => 'docker_cleanup', 'label' => 'Docker cleanup will be run on the server which removes builder cache and unused images'],
['id' => 'delete_volumes', 'label' => __('resource.delete_volumes')],
['id' => 'delete_connected_networks', 'label' => __('resource.delete_connected_networks')],
['id' => 'delete_configurations', 'label' => __('resource.delete_configurations')],
['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')],
// ['id' => 'delete_associated_backups_locally', 'label' => 'All backups associated with this Ressource will be permanently deleted from local storage.'],
// ['id' => 'delete_associated_backups_s3', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected S3 Storage.'],
// ['id' => 'delete_associated_backups_sftp', 'label' => 'All backups associated with this Ressource will be permanently deleted from the selected SFTP Storage.']
]
],
]);
}
}
8 changes: 7 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
"input.code": "One-time code",
"input.recovery_code": "Recovery code",
"button.save": "Save",
"repository.url": "<span class='text-helper'>Examples</span><br>For Public repositories, use <span class='text-helper'>https://...</span>.<br>For Private repositories, use <span class='text-helper'>git@...</span>.<br><br>https://github.com/coollabsio/coolify-examples <span class='text-helper'>main</span> branch will be selected<br>https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify <span class='text-helper'>nodejs-fastify</span> branch will be selected.<br>https://gitea.com/sedlav/expressjs.git <span class='text-helper'>main</span> branch will be selected.<br>https://gitlab.com/andrasbacsai/nodejs-example.git <span class='text-helper'>main</span> branch will be selected."
"repository.url": "<span class='text-helper'>Examples</span><br>For Public repositories, use <span class='text-helper'>https://...</span>.<br>For Private repositories, use <span class='text-helper'>git@...</span>.<br><br>https://github.com/coollabsio/coolify-examples <span class='text-helper'>main</span> branch will be selected<br>https://github.com/coollabsio/coolify-examples/tree/nodejs-fastify <span class='text-helper'>nodejs-fastify</span> branch will be selected.<br>https://gitea.com/sedlav/expressjs.git <span class='text-helper'>main</span> branch will be selected.<br>https://gitlab.com/andrasbacsai/nodejs-example.git <span class='text-helper'>main</span> branch will be selected.",
"service.stop": "This service will be stopped.",
"resource.docker_cleanup": "Run Docker Cleanup (remove unused images and builder cache).",
"resource.non_persistent": "All non-persistent data will be deleted.",
"resource.delete_volumes": "All volumes associated with this resource will be permanently deleted.",
"resource.delete_connected_networks": "All non-predefined networks associated with this resource will be permanently deleted.",
"resource.delete_configurations": "All configuration files will be permanently deleted from the server."
}
Loading

0 comments on commit eb10bbb

Please sign in to comment.