From e1a14909118682fd809f22143039416f4e8687f1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 21 Sep 2023 21:30:13 +0200 Subject: [PATCH] wip --- app/Actions/Service/StartService.php | 2 +- app/Actions/Service/StopService.php | 25 +++++++++++++++ app/Http/Livewire/Project/Service/Index.php | 12 +++++-- app/Http/Livewire/Project/Service/Modal.php | 16 ++++++++++ app/Models/EnvironmentVariable.php | 5 ++- app/View/Components/Status/Services.php | 26 +--------------- bootstrap/helpers/services.php | 29 +++++++++++++++++ .../components/services/navbar.blade.php | 31 +++++++++++++++++++ .../livewire/project/service/index.blade.php | 21 ++++++------- .../livewire/project/service/modal.blade.php | 12 +++++++ 10 files changed, 139 insertions(+), 40 deletions(-) create mode 100644 app/Actions/Service/StopService.php create mode 100644 app/Http/Livewire/Project/Service/Modal.php create mode 100644 resources/views/components/services/navbar.blade.php create mode 100644 resources/views/livewire/project/service/modal.blade.php diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php index 1ce7b6470..c89759bf7 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -23,7 +23,7 @@ class StartService } $commands[] = "docker compose pull"; $commands[] = "docker compose up -d"; - $commands[] = "docker network connect $service->uuid coolify-proxy"; + $commands[] = "docker network connect $service->uuid coolify-proxy 2>/dev/null || true"; $activity = remote_process($commands, $service->server); return $activity; } diff --git a/app/Actions/Service/StopService.php b/app/Actions/Service/StopService.php new file mode 100644 index 000000000..821428b28 --- /dev/null +++ b/app/Actions/Service/StopService.php @@ -0,0 +1,25 @@ +applications()->get(); + foreach ($applications as $application) { + instant_remote_process(["docker rm -f {$application->name}-{$service->uuid}"], $service->server); + $application->update(['status' => 'exited']); + } + $dbs = $service->databases()->get(); + foreach ($dbs as $db) { + instant_remote_process(["docker rm -f {$db->name}-{$service->uuid}"], $service->server); + $db->update(['status' => 'exited']); + } + instant_remote_process(["docker network disconnect {$service->uuid} coolify-proxy 2>/dev/null"], $service->server); + } +} diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.php index 348f16f8b..09a0c059f 100644 --- a/app/Http/Livewire/Project/Service/Index.php +++ b/app/Http/Livewire/Project/Service/Index.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire\Project\Service; use App\Actions\Service\StartService; +use App\Actions\Service\StopService; use App\Jobs\ContainerStatusJob; use App\Models\Service; use Illuminate\Support\Collection; @@ -15,7 +16,7 @@ class Index extends Component public array $parameters; public array $query; public Collection $services; - + protected $listeners = ['serviceStatusUpdated']; protected $rules = [ 'services.*.fqdn' => 'nullable', ]; @@ -39,11 +40,14 @@ class Index extends Component { return view('livewire.project.service.index')->layout('layouts.app'); } + public function serviceStatusUpdated() { + ray('serviceStatusUpdated'); + $this->check_status(); + } public function check_status() { dispatch_sync(new ContainerStatusJob($this->service->server)); $this->service->refresh(); - } public function submit() { @@ -76,4 +80,8 @@ class Index extends Component $activity = StartService::run($this->service); $this->emit('newMonitorActivity', $activity->id); } + public function stop() { + StopService::run($this->service); + $this->service->refresh(); + } } diff --git a/app/Http/Livewire/Project/Service/Modal.php b/app/Http/Livewire/Project/Service/Modal.php new file mode 100644 index 000000000..a5fd759e7 --- /dev/null +++ b/app/Http/Livewire/Project/Service/Modal.php @@ -0,0 +1,16 @@ +emit('serviceStatusUpdated'); + } + public function render() + { + return view('livewire.project.service.modal'); + } +} diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index 18b4e5438..37619d190 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -44,9 +44,12 @@ class EnvironmentVariable extends Model ); } - private function get_environment_variables(string $environment_variable): string|null + private function get_environment_variables(?string $environment_variable = null): string|null { // $team_id = currentTeam()->id; + if (!$environment_variable) { + return null; + } $environment_variable = trim(decrypt($environment_variable)); if (Str::startsWith($environment_variable, '{{') && Str::endsWith($environment_variable, '}}') && Str::contains($environment_variable, 'global.')) { $variable = Str::after($environment_variable, 'global.'); diff --git a/app/View/Components/Status/Services.php b/app/View/Components/Status/Services.php index 0db5e1ac3..3fc302acf 100644 --- a/app/View/Components/Status/Services.php +++ b/app/View/Components/Status/Services.php @@ -16,31 +16,7 @@ class Services extends Component public Service $service, public string $complexStatus = 'exited', ) { - $foundRunning = false; - $isDegraded = false; - $applications = $service->applications; - $databases = $service->databases; - foreach ($applications as $application) { - if ($application->status === 'running') { - $foundRunning = true; - } else { - $isDegraded = true; - } - } - foreach ($databases as $database) { - if ($database->status === 'running') { - $foundRunning = true; - } else { - $isDegraded = true; - } - } - if ($foundRunning && !$isDegraded) { - $this->complexStatus = 'running'; - } else if ($foundRunning && $isDegraded) { - $this->complexStatus = 'degraded'; - } else if (!$foundRunning && $isDegraded) { - $this->complexStatus = 'exited'; - } + $this->complexStatus = serviceStatus($service); } /** diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php index 4448d08ac..5e50d96bc 100644 --- a/bootstrap/helpers/services.php +++ b/bootstrap/helpers/services.php @@ -208,3 +208,32 @@ function replaceVariables($variable) { return $variable->replaceFirst('$', '')->replaceFirst('{', '')->replaceLast('}', ''); } + +function serviceStatus(Service $service) +{ + $foundRunning = false; + $isDegraded = false; + $applications = $service->applications; + $databases = $service->databases; + foreach ($applications as $application) { + if ($application->status === 'running') { + $foundRunning = true; + } else { + $isDegraded = true; + } + } + foreach ($databases as $database) { + if ($database->status === 'running') { + $foundRunning = true; + } else { + $isDegraded = true; + } + } + if ($foundRunning && !$isDegraded) { + return 'running'; + } else if ($foundRunning && $isDegraded) { + return 'degraded'; + } else if (!$foundRunning && $isDegraded) { + return 'exited'; + } +} diff --git a/resources/views/components/services/navbar.blade.php b/resources/views/components/services/navbar.blade.php new file mode 100644 index 000000000..da5b47562 --- /dev/null +++ b/resources/views/components/services/navbar.blade.php @@ -0,0 +1,31 @@ + diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 26d73bb3d..b833c8d7f 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -1,16 +1,19 @@
+

Configuration

+

Applications

@foreach ($service->applications as $application) -
-

{{ $application->name }}

-

{{ $application->status }}

- - Save -
+
+

{{ $application->name }}

+ + Save +
@endforeach -

Databases

+ @if ($service->databases->count() > 0) +

Databases

+ @endif @foreach ($service->databases as $database)

{{ $database->name }}

{{ $database->status }}

@@ -19,8 +22,4 @@ @foreach ($service->environment_variables as $variable)

{{ $variable->key }}={{ $variable->value }}

@endforeach - Deploy -
- -
diff --git a/resources/views/livewire/project/service/modal.blade.php b/resources/views/livewire/project/service/modal.blade.php new file mode 100644 index 000000000..8517d3ef1 --- /dev/null +++ b/resources/views/livewire/project/service/modal.blade.php @@ -0,0 +1,12 @@ +
+ + + + + + + Close + + + +