feat(Service): Add functionality to convert between applications and databases in docker-compose based applications

fix(ui): Fix service layout refresh on compose change
This commit is contained in:
Andras Bacsai
2025-04-29 14:27:17 +02:00
parent 1f7f267d60
commit d8c3418e72
8 changed files with 88 additions and 14 deletions

View File

@@ -31,8 +31,9 @@ class Configuration extends Component
return [
"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 {

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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);