Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: delete persistent storages on resource deletion

Andras Bacsai9c2fea4b2e8a
diff --git a/app/Http/Livewire/Project/Shared/Danger.php b/app/Http/Livewire/Project/Shared/Danger.php
index c88ade583a..5fc363359b 100644
--- a/app/Http/Livewire/Project/Shared/Danger.php
+++ b/app/Http/Livewire/Project/Shared/Danger.php
@@ -2,6 +2,7 @@
namespace App\Http\Livewire\Project\Shared;
+use App\Actions\Service\StopService;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@@ -22,14 +23,15 @@ class Danger extends Component
try {
if ($this->resource->type() === 'service') {
$server = $this->resource->server;
+ StopService::run($this->resource);
} else {
$destination = data_get($this->resource, 'destination');
if ($destination) {
$destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();
$server = $destination->server;
}
+ instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server);
}
- instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server);
$this->resource->delete();
return redirect()->route('project.resources', [
'project_uuid' => $this->parameters['project_uuid'],
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 8f518efc9f..1cdfdea295 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -4,10 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\HasMany;
-use Illuminate\Support\Collection;
use Spatie\Activitylog\Models\Activity;
-use Symfony\Component\Yaml\Yaml;
-use Illuminate\Support\Str;
class Application extends BaseModel
{
@@ -22,6 +19,10 @@ class Application extends BaseModel
});
static::deleting(function ($application) {
$application->settings()->delete();
+ $storages = $application->persistentStorages()->get();
+ foreach ($storages as $storage) {
+ instant_remote_process(["docker volume rm -f $storage->name"], $application->destination->server);
+ }
$application->persistentStorages()->delete();
$application->environment_variables()->delete();
$application->environment_variables_preview()->delete();
diff --git a/app/Models/Service.php b/app/Models/Service.php
index fb04608b89..4e585aca3e 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -17,15 +17,29 @@ class Service extends BaseModel
protected static function booted()
{
static::deleted(function ($service) {
+ $storagesToDelete = collect([]);
foreach($service->applications()->get() as $application) {
+ $storages = $application->persistentStorages()->get();
+ foreach ($storages as $storage) {
+ $storagesToDelete->push($storage);
+ }
$application->persistentStorages()->delete();
}
foreach($service->databases()->get() as $database) {
+ $storages = $database->persistentStorages()->get();
+ foreach ($storages as $storage) {
+ $storagesToDelete->push($storage);
+ }
$database->persistentStorages()->delete();
}
$service->environment_variables()->delete();
$service->applications()->delete();
$service->databases()->delete();
+ if ($storagesToDelete->count() > 0) {
+ $storagesToDelete->each(function ($storage) use ($service) {
+ instant_remote_process(["docker volume rm -f $storage->name"], $service->server, false);
+ });
+ }
});
}
public function type()
diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php
index afc5cdc910..21ec17e408 100644
--- a/app/Models/StandalonePostgresql.php
+++ b/app/Models/StandalonePostgresql.php
@@ -31,8 +31,8 @@ class StandalonePostgresql extends BaseModel
static::deleted(function ($database) {
$database->scheduledBackups()->delete();
$database->persistentStorages()->delete();
- instant_remote_process(['docker volume rm postgres-data-' . $database->uuid], $database->destination->server, false);
$database->environment_variables()->delete();
+ instant_remote_process(['docker volume rm postgres-data-' . $database->uuid], $database->destination->server, false);
});
}