From 97027875bfc64d96a698c70ada10edf85001ae16 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 2 Oct 2023 13:38:16 +0200 Subject: [PATCH] feat: container logs --- app/Http/Livewire/Project/Shared/GetLogs.php | 40 +++++++++ app/Http/Livewire/Project/Shared/Logs.php | 53 ++++++++++++ .../components/applications/navbar.blade.php | 4 + .../components/databases/navbar.blade.php | 4 + .../components/services/navbar.blade.php | 4 + .../livewire/project/service/index.blade.php | 86 +++++++++++-------- .../livewire/project/service/show.blade.php | 7 +- .../project/shared/get-logs.blade.php | 18 ++++ .../livewire/project/shared/logs.blade.php | 41 +++++++++ routes/web.php | 7 ++ 10 files changed, 225 insertions(+), 39 deletions(-) create mode 100644 app/Http/Livewire/Project/Shared/GetLogs.php create mode 100644 app/Http/Livewire/Project/Shared/Logs.php create mode 100644 resources/views/livewire/project/shared/get-logs.blade.php create mode 100644 resources/views/livewire/project/shared/logs.blade.php diff --git a/app/Http/Livewire/Project/Shared/GetLogs.php b/app/Http/Livewire/Project/Shared/GetLogs.php new file mode 100644 index 000000000..aba2e2649 --- /dev/null +++ b/app/Http/Livewire/Project/Shared/GetLogs.php @@ -0,0 +1,40 @@ +outputs .= $output; + } + public function instantSave() + { + } + public function getLogs($refresh = false) + { + if ($this->container) { + $sshCommand = generateSshCommand($this->server, "docker logs -t {$this->container}"); + if ($refresh) { + $this->outputs = ''; + } + Process::run($sshCommand, function (string $type, string $output) { + $this->doSomethingWithThisChunkOfOutput($output); + }); + } + } + public function render() + { + return view('livewire.project.shared.get-logs'); + } +} diff --git a/app/Http/Livewire/Project/Shared/Logs.php b/app/Http/Livewire/Project/Shared/Logs.php new file mode 100644 index 000000000..69848a7c5 --- /dev/null +++ b/app/Http/Livewire/Project/Shared/Logs.php @@ -0,0 +1,53 @@ +parameters = get_route_parameters(); + $this->query = request()->query(); + if (data_get($this->parameters, 'application_uuid')) { + $this->type = 'application'; + $this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail(); + $this->status = $this->resource->status; + $this->server = $this->resource->destination->server; + $containers = getCurrentApplicationContainerStatus($this->server, $this->resource->id); + if ($containers->count() > 0) { + $this->container = data_get($containers[0], 'Names'); + } + } else if (data_get($this->parameters, 'database_uuid')) { + $this->type = 'database'; + $this->resource = StandalonePostgresql::where('uuid', $this->parameters['database_uuid'])->firstOrFail(); + $this->status = $this->resource->status; + $this->server = $this->resource->destination->server; + $this->container = $this->resource->uuid; + } else if (data_get($this->parameters, 'service_uuid')) { + $this->type = 'service'; + $this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail(); + $this->status = $this->resource->status; + $this->server = $this->resource->server; + $this->container = data_get($this->parameters, 'service_name') . '-' . $this->resource->uuid; + } + } + + public function render() + { + return view('livewire.project.shared.logs'); + } +} diff --git a/resources/views/components/applications/navbar.blade.php b/resources/views/components/applications/navbar.blade.php index 00a390826..b84b0bf13 100644 --- a/resources/views/components/applications/navbar.blade.php +++ b/resources/views/components/applications/navbar.blade.php @@ -7,6 +7,10 @@ href="{{ route('project.application.deployments', $parameters) }}"> + + +
diff --git a/resources/views/components/databases/navbar.blade.php b/resources/views/components/databases/navbar.blade.php index 9136220b1..6681565ba 100644 --- a/resources/views/components/databases/navbar.blade.php +++ b/resources/views/components/databases/navbar.blade.php @@ -3,6 +3,10 @@ href="{{ route('project.database.configuration', $parameters) }}"> + + + diff --git a/resources/views/components/services/navbar.blade.php b/resources/views/components/services/navbar.blade.php index 0bf49f3e3..43e16c3df 100644 --- a/resources/views/components/services/navbar.blade.php +++ b/resources/views/components/services/navbar.blade.php @@ -1,4 +1,8 @@ Save - Edit Compose File + Edit Compose + File
@endforeach @foreach ($databases as $database) - Str::of( $database->status)->contains(['exited']), 'border-l border-dashed border-success' => Str::of( $database->status)->contains(['running']), 'border-l border-dashed border-warning' => Str::of( $database->status)->contains(['restarting']), - 'flex flex-col justify-center box', - ]) - href="{{ route('project.service.show', [...$parameters, 'service_name' => $database->name]) }}"> - @if ($database->human_name) - {{ Str::headline($database->human_name) }} - @else - {{ Str::headline($database->name) }} - @endif - @if ($database->configuration_required) - (configuration required) - @endif - @if ($database->description) - {{ Str::limit($database->description, 60) }} - @endif -
{{ $database->status }}
-
+ 'flex gap-2 box group', + ])> + + @if ($database->human_name) + {{ Str::headline($database->human_name) }} + @else + {{ Str::headline($database->name) }} + @endif + @if ($database->configuration_required) + (configuration required) + @endif + @if ($database->description) + {{ Str::limit($database->description, 60) }} + @endif +
{{ $database->status }}
+
+ Logs +
@endforeach diff --git a/resources/views/livewire/project/service/show.blade.php b/resources/views/livewire/project/service/show.blade.php index e0ab934a2..8fcfc008a 100644 --- a/resources/views/livewire/project/service/show.blade.php +++ b/resources/views/livewire/project/service/show.blade.php @@ -11,6 +11,12 @@ Storages + @if (data_get($parameters, 'service_name')) + + + + @endif
@isset($serviceApplication) @@ -32,7 +38,6 @@ @isset($serviceDatabase)
-
diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php new file mode 100644 index 000000000..0551fd5fe --- /dev/null +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -0,0 +1,18 @@ +
+
+

Logs

+ @if ($streamLogs) + + @endif +
+
+ +
+
+
+ +
{{ $outputs }}
+
+
+
diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php new file mode 100644 index 000000000..72c1d3a3f --- /dev/null +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -0,0 +1,41 @@ + + @if ($type === 'application') +

Logs

+ +
+ @if (Str::of($status)->startsWith('running')) + + @else + Application is not running. + @endif +
+ @elseif ($type === 'database') +

Logs

+ +
+ @if (Str::of($status)->startsWith('running')) + + @else + Database is not running. + @endif +
+ @elseif ($type === 'service') + +
+ +
+ @if (Str::of($status)->startsWith('running')) + + @else + Service is not running. + @endif +
+
+ @endif + +
diff --git a/routes/web.php b/routes/web.php index 34adf01b2..8fe8bd1db 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ use App\Http\Livewire\Boarding\Index as BoardingIndex; use App\Http\Livewire\Project\Service\Index as ServiceIndex; use App\Http\Livewire\Project\Service\Show as ServiceShow; use App\Http\Livewire\Dashboard; +use App\Http\Livewire\Project\Shared\Logs; use App\Http\Livewire\Server\All; use App\Http\Livewire\Server\Show; use App\Http\Livewire\Waitlist\Index as WaitlistIndex; @@ -80,14 +81,20 @@ Route::middleware(['auth'])->group(function () { [ApplicationController::class, 'deployment'] )->name('project.application.deployment'); + Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/logs', Logs::class)->name('project.application.logs'); + // Databases Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}', [DatabaseController::class, 'configuration'])->name('project.database.configuration'); Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups', [DatabaseController::class, 'backups'])->name('project.database.backups.all'); Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/backups/{backup_uuid}', [DatabaseController::class, 'executions'])->name('project.database.backups.executions'); + Route::get('/project/{project_uuid}/{environment_name}/database/{database_uuid}/logs', Logs::class)->name('project.database.logs'); + // Services Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', ServiceIndex::class)->name('project.service'); Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}', ServiceShow::class)->name('project.service.show'); + Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}/logs', Logs::class)->name('project.service.logs'); + }); Route::middleware(['auth'])->group(function () {