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
feat(Service): Add functionality to convert between applications and databases in docker-compose based applications fix(ui): Fix service layout refresh on compose change
Andras Bacsaid8c3418e72e2
diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.phpindex da49dcae98..20067b1f98 100644--- a/app/Livewire/Project/Service/Configuration.php+++ b/app/Livewire/Project/Service/Configuration.php@@ -31,8 +31,9 @@ class Configuration extends Componentreturn ["echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',- 'check_status','refreshStatus' => '$refresh',+ 'check_status',+ 'refreshServices',];}@@ -63,6 +64,13 @@ class Configuration extends Component$this->databases = $this->service->databases->sort();}+ public function refreshServices()+ {+ $this->service->refresh();+ $this->applications = $this->service->applications->sort();+ $this->databases = $this->service->databases->sort();+ }+public function restartApplication($id){try {diff --git a/app/Livewire/Project/Service/Database.php b/app/Livewire/Project/Service/Database.phpindex c3b7577e9d..28e3d3a264 100644--- a/app/Livewire/Project/Service/Database.php+++ b/app/Livewire/Project/Service/Database.php@@ -6,6 +6,7 @@ use App\Actions\Database\StartDatabaseProxy;use App\Actions\Database\StopDatabaseProxy;use App\Models\InstanceSettings;use App\Models\ServiceDatabase;+use DB;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\Hash;use Livewire\Component;@@ -83,6 +84,33 @@ class Database extends Component$this->dispatch('success', 'You need to restart the service for the changes to take effect.');}+ public function convertToApplication()+ {+ try {+ $service = $this->database->service;+ $serviceDatabase = $this->database;+ DB::beginTransaction();+ $service->applications()->create([+ 'name' => $serviceDatabase->name,+ 'human_name' => $serviceDatabase->human_name,+ 'description' => $serviceDatabase->description,+ 'exclude_from_status' => $serviceDatabase->exclude_from_status,+ 'is_log_drain_enabled' => $serviceDatabase->is_log_drain_enabled,+ 'image' => $serviceDatabase->image,+ 'service_id' => $service->id,+ ]);+ $serviceDatabase->delete();+ DB::commit();++ return redirect()->route('project.service.configuration', $this->parameters);+ } catch (\Throwable $e) {+ DB::rollBack();+ dd($e);++ return handleError($e, $this);+ }+ }+public function instantSave(){if ($this->database->is_public && ! $this->database->public_port) {diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.phpindex f1d08ee139..24f218057b 100644--- a/app/Livewire/Project/Service/ServiceApplicationView.php+++ b/app/Livewire/Project/Service/ServiceApplicationView.php@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Service;use App\Models\InstanceSettings;use App\Models\ServiceApplication;+use DB;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\Hash;use Livewire\Component;@@ -73,6 +74,32 @@ class ServiceApplicationView extends Component$this->parameters = get_route_parameters();}+ public function convertToDatabase()+ {+ try {+ $service = $this->application->service;+ $serviceApplication = $this->application;+ DB::beginTransaction();+ $service->databases()->create([+ 'name' => $serviceApplication->name,+ 'human_name' => $serviceApplication->human_name,+ 'description' => $serviceApplication->description,+ 'exclude_from_status' => $serviceApplication->exclude_from_status,+ 'is_log_drain_enabled' => $serviceApplication->is_log_drain_enabled,+ 'image' => $serviceApplication->image,+ 'service_id' => $service->id,+ ]);+ $serviceApplication->delete();+ DB::commit();++ return redirect()->route('project.service.configuration', $this->parameters);+ } catch (\Throwable $e) {+ DB::rollBack();++ return handleError($e, $this);+ }+ }+public function submit(){try {diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.phpindex 3685984660..a67bd92100 100644--- a/app/Livewire/Project/Service/StackForm.php+++ b/app/Livewire/Project/Service/StackForm.php@@ -82,6 +82,7 @@ class StackForm extends Component$this->service->refresh();$this->service->saveComposeConfigs();$this->dispatch('refreshEnvs');+ $this->dispatch('refreshServices');$notify && $this->dispatch('success', 'Service saved.');} catch (\Throwable $e) {return handleError($e, $this);diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 44e20c9b39..8b2d9fb6a3 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -2990,12 +2990,12 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int$applicationFound = ServiceApplication::where('name', $serviceName)->where('service_id', $resource->id)->first();if ($applicationFound) {$savedService = $applicationFound;- $savedService = ServiceDatabase::firstOrCreate([- 'name' => $applicationFound->name,- 'image' => $applicationFound->image,- 'service_id' => $applicationFound->service_id,- ]);- $applicationFound->delete();+ // $savedService = ServiceDatabase::firstOrCreate([+ // 'name' => $applicationFound->name,+ // 'image' => $applicationFound->image,+ // 'service_id' => $applicationFound->service_id,+ // ]);+ // $applicationFound->delete();} else {$savedService = ServiceDatabase::firstOrCreate(['name' => $serviceName,@@ -3248,12 +3248,12 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int$applicationFound = ServiceApplication::where('name', $serviceName)->where('image', $image)->where('service_id', $resource->id)->first();if ($applicationFound) {$savedService = $applicationFound;- $savedService = ServiceDatabase::firstOrCreate([- 'name' => $applicationFound->name,- 'image' => $applicationFound->image,- 'service_id' => $applicationFound->service_id,- ]);- $applicationFound->delete();+ // $savedService = ServiceDatabase::firstOrCreate([+ // 'name' => $applicationFound->name,+ // 'image' => $applicationFound->image,+ // 'service_id' => $applicationFound->service_id,+ // ]);+ // $applicationFound->delete();} else {$savedService = ServiceDatabase::firstOrCreate(['name' => $serviceName,diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.phpindex 1e287356b0..15ab6fbde1 100644--- a/resources/views/livewire/project/service/configuration.blade.php+++ b/resources/views/livewire/project/service/configuration.blade.php@@ -39,7 +39,7 @@<div class="grid grid-cols-1 gap-2 pt-4 xl:grid-cols-1" wire:poll.10000ms="check_status">@foreach ($applications as $application)<div @class([- 'border-l border-dashed border-red-500 ' => str(+ 'border-l border-dashed border-red-500' => str($application->status)->contains(['exited']),'border-l border-dashed border-success' => str($application->status)->contains(['running']),diff --git a/resources/views/livewire/project/service/database.blade.php b/resources/views/livewire/project/service/database.blade.phpindex 8ec73b4de9..df787d7835 100644--- a/resources/views/livewire/project/service/database.blade.php+++ b/resources/views/livewire/project/service/database.blade.php@@ -7,6 +7,11 @@<h2>{{ Str::headline($database->name) }}</h2>@endif<x-forms.button type="submit">Save</x-forms.button>+ <x-modal-confirmation wire:click="convertToApplication" title="Convert to Application"+ buttonTitle="Convert to Application" submitAction="convertToApplication" :actions="['The selected resource will be converted to an application.']"+ confirmationText="{{ Str::headline($database->name) }}"+ confirmationLabel="Please confirm the execution of the actions by entering the Service Database Name below"+ shortConfirmationLabel="Service Database Name" step3ButtonText="Permanently Delete" /><x-modal-confirmation title="Confirm Service Database Deletion?" buttonTitle="Delete" isErrorButtonsubmitAction="delete" :actions="['The selected service database container will be stopped and permanently deleted.']" confirmationText="{{ Str::headline($database->name) }}"confirmationLabel="Please confirm the execution of the actions by entering the Service Database Name below"diff --git a/resources/views/livewire/project/service/service-application-view.blade.php b/resources/views/livewire/project/service/service-application-view.blade.phpindex a523f5396a..1c0a6d4780 100644--- a/resources/views/livewire/project/service/service-application-view.blade.php+++ b/resources/views/livewire/project/service/service-application-view.blade.php@@ -7,6 +7,11 @@<h2>{{ Str::headline($application->name) }}</h2>@endif<x-forms.button type="submit">Save</x-forms.button>+ <x-modal-confirmation wire:click="convertToDatabase" title="Convert to Database"+ buttonTitle="Convert to Database" submitAction="convertToDatabase" :actions="['The selected resource will be converted to a service database.']"+ confirmationText="{{ Str::headline($application->name) }}"+ confirmationLabel="Please confirm the execution of the actions by entering the Service Application Name below"+ shortConfirmationLabel="Service Application Name" step3ButtonText="Permanently Delete" /><x-modal-confirmation title="Confirm Service Application Deletion?" buttonTitle="Delete" isErrorButtonsubmitAction="delete" {{-- :checkboxes="$checkboxes" --}} :actions="['The selected service application container will be stopped and permanently deleted.']"confirmationText="{{ Str::headline($application->name) }}"