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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Refactor service and resource deletion logic
Andras Bacsai795c8abf6458
diff --git a/app/Actions/Service/DeleteService.php b/app/Actions/Service/DeleteService.phpindex 743158c2df..a70adfecf6 100644--- a/app/Actions/Service/DeleteService.php+++ b/app/Actions/Service/DeleteService.php@@ -10,36 +10,43 @@ class DeleteServiceuse AsAction;public function handle(Service $service){- $server = data_get($service, 'server');- if ($server->isFunctional()) {- StopService::run($service);- }- $storagesToDelete = collect([]);+ try {+ $server = data_get($service, 'server');+ if ($server->isFunctional()) {+ StopService::run($service);+ $storagesToDelete = collect([]);++ $service->environment_variables()->delete();+ $commands = [];+ foreach ($service->applications()->get() as $application) {+ $storages = $application->persistentStorages()->get();+ foreach ($storages as $storage) {+ $storagesToDelete->push($storage);+ }+ }+ foreach ($service->databases()->get() as $database) {+ $storages = $database->persistentStorages()->get();+ foreach ($storages as $storage) {+ $storagesToDelete->push($storage);+ }+ }+ foreach ($storagesToDelete as $storage) {+ $commands[] = "docker volume rm -f $storage->name";+ }+ $commands[] = "docker rm -f $service->uuid";- $service->environment_variables()->delete();- $commands = [];- foreach ($service->applications()->get() as $application) {- $storages = $application->persistentStorages()->get();- foreach ($storages as $storage) {- $storagesToDelete->push($storage);+ instant_remote_process($commands, $server, false);}- $application->forceDelete();- }- foreach ($service->databases()->get() as $database) {- $storages = $database->persistentStorages()->get();- foreach ($storages as $storage) {- $storagesToDelete->push($storage);+ } catch (\Exception $e) {+ throw new \Exception($e->getMessage());+ } finally {+ foreach ($service->applications()->get() as $application) {+ $application->forceDelete();}- $database->forceDelete();- }- if ($server->isFunctional()) {- foreach ($storagesToDelete as $storage) {- $commands[] = "docker volume rm -f $storage->name";+ foreach ($service->databases()->get() as $database) {+ $database->forceDelete();}- $commands[] = "docker rm -f $service->uuid";-- instant_remote_process($commands, $server, false);+ $service->forceDelete();}- $service->forceDelete();}}diff --git a/app/Jobs/DeleteResourceJob.php b/app/Jobs/DeleteResourceJob.phpindex 0a9ac112cf..a22b97819d 100644--- a/app/Jobs/DeleteResourceJob.php+++ b/app/Jobs/DeleteResourceJob.php@@ -30,25 +30,30 @@ class DeleteResourceJob implements ShouldQueue, ShouldBeEncryptedpublic function handle(){try {- $this->resource->delete();switch ($this->resource->type()) {case 'application':StopApplication::run($this->resource);+ $this->resource->forceDelete();break;case 'standalone-postgresql':StopDatabase::run($this->resource);+ $this->resource->forceDelete();break;case 'standalone-redis':StopDatabase::run($this->resource);+ $this->resource->forceDelete();break;case 'standalone-mongodb':StopDatabase::run($this->resource);+ $this->resource->forceDelete();break;case 'standalone-mysql':StopDatabase::run($this->resource);+ $this->resource->forceDelete();break;case 'standalone-mariadb':StopDatabase::run($this->resource);+ $this->resource->forceDelete();break;case 'service':DeleteService::dispatch($this->resource);@@ -57,8 +62,6 @@ class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted} catch (\Throwable $e) {send_internal_notification('ContainerStoppingJob failed with: ' . $e->getMessage());throw $e;- } finally {- $this->resource->forceDelete();}}}diff --git a/app/Livewire/Project/Shared/Danger.php b/app/Livewire/Project/Shared/Danger.phpindex 37664c870f..b0f1c97c79 100644--- a/app/Livewire/Project/Shared/Danger.php+++ b/app/Livewire/Project/Shared/Danger.php@@ -24,7 +24,8 @@ class Danger extends Componentpublic function delete(){try {- DeleteResourceJob::dispatchSync($this->resource);+ $this->resource->delete();+ DeleteResourceJob::dispatch($this->resource);return redirect()->route('project.resource.index', ['project_uuid' => $this->projectUuid,'environment_name' => $this->environmentName