Skip to content

Commit

Permalink
feat: able to delete configuration from server
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Apr 12, 2024
1 parent 8b668cf commit 9032879
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 10 deletions.
5 changes: 4 additions & 1 deletion app/Jobs/DeleteResourceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted
{
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)
{
}

Expand All @@ -55,6 +55,9 @@ public function handle()
DeleteService::run($this->resource);
break;
}
if ($this->deleteConfigurations) {
$this->resource?->delete_configurations();
}
} catch (\Throwable $e) {
ray($e->getMessage());
send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Project/Shared/Danger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Danger extends Component
public $resource;
public $projectUuid;
public $environmentName;
public bool $delete_configurations = false;
public ?string $modalId = null;

public function mount()
Expand All @@ -25,7 +26,7 @@ public function delete()
{
try {
$this->resource->delete();
DeleteResourceJob::dispatch($this->resource);
DeleteResourceJob::dispatch($this->resource, $this->delete_configurations);
return redirect()->route('project.resource.index', [
'project_uuid' => $this->projectUuid,
'environment_name' => $this->environmentName
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
return $this->belongsToMany(Server::class, 'additional_destinations')
Expand Down
8 changes: 8 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function tags()
{
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()
{
$applications = $this->applications;
Expand Down
10 changes: 9 additions & 1 deletion app/Models/StandaloneClickhouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ protected static function booted()
}
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()
{
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandaloneDragonfly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
return $this->getRawOriginal('status');
Expand Down
13 changes: 13 additions & 0 deletions app/Models/StandaloneKeydb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
return $this->getRawOriginal('status');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandaloneMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ protected static function booted()
$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()
{
return $this->getRawOriginal('status');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandaloneMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ protected static function booted()
$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()
{
return $this->getRawOriginal('status');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandaloneMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ protected static function booted()
$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()
{
return $this->getRawOriginal('status');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandalonePostgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ protected static function booted()
$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()
{
return $this->getRawOriginal('status');
Expand Down
12 changes: 12 additions & 0 deletions app/Models/StandaloneRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ protected static function booted()
$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()
{
return $this->getRawOriginal('status');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
$wire.$call('start');
});
$wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping database.');
$wire.$dispatch('info', 'Stopping database.');
$wire.$call('stop');
});
</script>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/livewire/project/service/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@
@script
<script>
$wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping service.');
$wire.$dispatch('info', 'Stopping service.');
$wire.$call('stop');
});
$wire.$on('startEvent', () => {
window.dispatchEvent(new CustomEvent('startservice'));
$wire.$call('start');
});
$wire.$on('restartEvent', () => {
$wire.$dispatch('warning', 'Pulling new images.');
$wire.$dispatch('info', 'Pulling new images.');
$wire.$call('restart');
});
$wire.on('imagePulled', () => {
window.dispatchEvent(new CustomEvent('startservice'));
$wire.$dispatch('warning', 'Restarting service.');
$wire.$dispatch('info', 'Restarting service.');
});
</script>
@endscript
Expand Down
5 changes: 4 additions & 1 deletion resources/views/livewire/project/shared/danger.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
back!
</div>
<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>
</div>
4 changes: 2 additions & 2 deletions resources/views/livewire/server/proxy/deploy.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
@script
<script>
$wire.$on('restartEvent', () => {
$wire.$dispatch('warning', 'Restarting proxy.');
$wire.$dispatch('info', 'Restarting proxy.');
$wire.$call('restart');
});
$wire.$on('proxyChecked', () => {
Expand All @@ -71,7 +71,7 @@
});
$wire.$on('stopEvent', () => {
$wire.$dispatch('warning', 'Stopping proxy.');
$wire.$dispatch('info', 'Stopping proxy.');
$wire.$call('stop');
});
</script>
Expand Down

0 comments on commit 9032879

Please sign in to comment.