feat: able to delete configuration from server

This commit is contained in:
Andras Bacsai 2024-04-12 10:54:25 +02:00
parent 8b668cf8b7
commit 9032879e20
16 changed files with 127 additions and 10 deletions

View File

@ -28,7 +28,7 @@ class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource) public function __construct(public Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource, public bool $deleteConfigurations = false)
{ {
} }
@ -55,6 +55,9 @@ public function handle()
DeleteService::run($this->resource); DeleteService::run($this->resource);
break; break;
} }
if ($this->deleteConfigurations) {
$this->resource?->delete_configurations();
}
} catch (\Throwable $e) { } catch (\Throwable $e) {
ray($e->getMessage()); ray($e->getMessage());
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage()); send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());

View File

@ -11,6 +11,7 @@ class Danger extends Component
public $resource; public $resource;
public $projectUuid; public $projectUuid;
public $environmentName; public $environmentName;
public bool $delete_configurations = false;
public ?string $modalId = null; public ?string $modalId = null;
public function mount() public function mount()
@ -25,7 +26,7 @@ public function delete()
{ {
try { try {
$this->resource->delete(); $this->resource->delete();
DeleteResourceJob::dispatch($this->resource); DeleteResourceJob::dispatch($this->resource, $this->delete_configurations);
return redirect()->route('project.resource.index', [ return redirect()->route('project.resource.index', [
'project_uuid' => $this->projectUuid, 'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName 'environment_name' => $this->environmentName

View File

@ -57,6 +57,15 @@ protected static function booted()
}); });
} }
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
ray('Deleting workdir');
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function additional_servers() public function additional_servers()
{ {
return $this->belongsToMany(Server::class, 'additional_destinations') return $this->belongsToMany(Server::class, 'additional_destinations')

View File

@ -27,6 +27,14 @@ public function tags()
{ {
return $this->morphToMany(Tag::class, 'taggable'); return $this->morphToMany(Tag::class, 'taggable');
} }
public function delete_configurations()
{
$server = data_get($this, 'server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function status() public function status()
{ {
$applications = $this->applications; $applications = $this->applications;

View File

@ -44,7 +44,15 @@ protected static function booted()
} }
public function workdir() public function workdir()
{ {
return database_configuration_dir() . '/' . $this->uuid; return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
} }
public function realStatus() public function realStatus()
{ {

View File

@ -42,6 +42,18 @@ protected static function booted()
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -42,6 +42,19 @@ protected static function booted()
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -43,6 +43,18 @@ protected static function booted()
$database->tags()->detach(); $database->tags()->detach();
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -46,6 +46,18 @@ protected static function booted()
$database->tags()->detach(); $database->tags()->detach();
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -43,6 +43,18 @@ protected static function booted()
$database->tags()->detach(); $database->tags()->detach();
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -43,6 +43,18 @@ protected static function booted()
$database->tags()->detach(); $database->tags()->detach();
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -38,6 +38,18 @@ protected static function booted()
$database->tags()->detach(); $database->tags()->detach();
}); });
} }
public function workdir()
{
return database_configuration_dir() . "/{$this->uuid}";
}
public function delete_configurations()
{
$server = data_get($this, 'destination.server');
$workdir = $this->workdir();
if (str($workdir)->endsWith($this->uuid)) {
instant_remote_process(["rm -rf " . $this->workdir()], $server, false);
}
}
public function realStatus() public function realStatus()
{ {
return $this->getRawOriginal('status'); return $this->getRawOriginal('status');

View File

@ -64,7 +64,7 @@
$wire.$call('start'); $wire.$call('start');
}); });
$wire.$on('stopEvent', () => { $wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping database.'); $wire.$dispatch('info', 'Stopping database.');
$wire.$call('stop'); $wire.$call('stop');
}); });
</script> </script>

View File

@ -114,7 +114,7 @@
@script @script
<script> <script>
$wire.$on('stopEvent', () => { $wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping service.'); $wire.$dispatch('info', 'Stopping service.');
$wire.$call('stop'); $wire.$call('stop');
}); });
$wire.$on('startEvent', () => { $wire.$on('startEvent', () => {
@ -122,12 +122,12 @@
$wire.$call('start'); $wire.$call('start');
}); });
$wire.$on('restartEvent', () => { $wire.$on('restartEvent', () => {
$wire.$dispatch('warning', 'Pulling new images.'); $wire.$dispatch('info', 'Pulling new images.');
$wire.$call('restart'); $wire.$call('restart');
}); });
$wire.on('imagePulled', () => { $wire.on('imagePulled', () => {
window.dispatchEvent(new CustomEvent('startservice')); window.dispatchEvent(new CustomEvent('startservice'));
$wire.$dispatch('warning', 'Restarting service.'); $wire.$dispatch('info', 'Restarting service.');
}); });
</script> </script>
@endscript @endscript

View File

@ -6,6 +6,9 @@
back! back!
</div> </div>
<x-modal-confirmation isErrorButton buttonTitle="Delete"> <x-modal-confirmation isErrorButton buttonTitle="Delete">
This resource will be deleted. It is not reversible. <br>Please think again. <div class="px-2">This resource will be deleted. It is not reversible. <strong class="text-error">Please think
again.</strong><br><br></div>
<x-forms.checkbox class="px-0" id="delete_configurations"
label="Also delete configuration files from the server (/data/coolify/...)?"></x-forms.checkbox>
</x-modal-confirmation> </x-modal-confirmation>
</div> </div>

View File

@ -62,7 +62,7 @@
@script @script
<script> <script>
$wire.$on('restartEvent', () => { $wire.$on('restartEvent', () => {
$wire.$dispatch('warning', 'Restarting proxy.'); $wire.$dispatch('info', 'Restarting proxy.');
$wire.$call('restart'); $wire.$call('restart');
}); });
$wire.$on('proxyChecked', () => { $wire.$on('proxyChecked', () => {
@ -71,7 +71,7 @@
}); });
$wire.$on('stopEvent', () => { $wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping proxy.'); $wire.$dispatch('info', 'Stopping proxy.');
$wire.$call('stop'); $wire.$call('stop');
}); });
</script> </script>