diff --git a/app/Livewire/Project/Shared/Logs.php b/app/Livewire/Project/Shared/Logs.php index 2d760fae2..0629e9787 100644 --- a/app/Livewire/Project/Shared/Logs.php +++ b/app/Livewire/Project/Shared/Logs.php @@ -25,6 +25,8 @@ class Logs extends Component public Collection $containers; + public array $serverContainers = []; + public $container = []; public $parameters; @@ -37,6 +39,8 @@ class Logs extends Component public $cpu; + public bool $containersLoaded = false; + public function getListeners() { $teamId = auth()->user()->currentTeam()->id; @@ -46,25 +50,77 @@ class Logs extends Component ]; } - public function loadContainers($server_id) + public function loadAllContainers() { try { - $server = $this->servers->firstWhere('id', $server_id); - if (! $server->isFunctional()) { - return; + foreach ($this->servers as $server) { + $this->serverContainers[$server->id] = $this->getContainersForServer($server); } + $this->containersLoaded = true; + } catch (\Exception $e) { + $this->containersLoaded = true; // Set to true to stop loading spinner + + return handleError($e, $this); + } + } + + private function getContainersForServer($server) + { + if (! $server->isFunctional()) { + return []; + } + + try { if ($server->isSwarm()) { $containers = collect([ [ + 'ID' => $this->resource->uuid, 'Names' => $this->resource->uuid.'_'.$this->resource->uuid, ], ]); + + return $containers->toArray(); } else { $containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true); + if ($containers && $containers->count() > 0) { + return $containers->sort()->toArray(); + } + + return []; } - $server->containers = $containers->sort(); } catch (\Exception $e) { - return handleError($e, $this); + // Log error but don't fail the entire operation + ray("Error loading containers for server {$server->name}: ".$e->getMessage()); + + return []; + } + } + + public function getServerContainers($serverId) + { + return $this->serverContainers[$serverId] ?? []; + } + + public function hasContainersForServer($serverId) + { + return isset($this->serverContainers[$serverId]) && count($this->serverContainers[$serverId]) > 0; + } + + public function debugContainers() + { + ray([ + 'containersLoaded' => $this->containersLoaded, + 'serversCount' => $this->servers->count(), + 'serverContainers' => $this->serverContainers, + 'servers' => $this->servers->map(fn ($s) => ['id' => $s->id, 'name' => $s->name, 'functional' => $s->isFunctional()])->toArray(), + ]); + } + + public function loadContainers($server_id = null) + { + // Keep for backward compatibility, but redirect to loadAllContainers + if (! $this->containersLoaded) { + $this->loadAllContainers(); } } @@ -73,6 +129,7 @@ class Logs extends Component try { $this->containers = collect(); $this->servers = collect(); + $this->serverContainers = []; $this->parameters = get_route_parameters(); $this->query = request()->query(); if (data_get($this->parameters, 'application_uuid')) { @@ -80,7 +137,8 @@ class Logs extends Component $this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail(); $this->status = $this->resource->status; if ($this->resource->destination->server->isFunctional()) { - $this->servers = $this->servers->push($this->resource->destination->server); + $server = $this->resource->destination->server; + $this->servers = $this->servers->push($server); } foreach ($this->resource->additional_servers as $server) { if ($server->isFunctional()) { @@ -96,7 +154,8 @@ class Logs extends Component $this->resource = $resource; $this->status = $this->resource->status; if ($this->resource->destination->server->isFunctional()) { - $this->servers = $this->servers->push($this->resource->destination->server); + $server = $this->resource->destination->server; + $this->servers = $this->servers->push($server); } $this->container = $this->resource->uuid; $this->containers->push($this->container); @@ -110,7 +169,8 @@ class Logs extends Component $this->containers->push(data_get($database, 'name').'-'.data_get($this->resource, 'uuid')); }); if ($this->resource->server->isFunctional()) { - $this->servers = $this->servers->push($this->resource->server); + $server = $this->resource->server; + $this->servers = $this->servers->push($server); } } $this->containers = $this->containers->sort(); diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.php index 23969a985..9bcf50edc 100644 --- a/resources/views/livewire/project/application/deployment/index.blade.php +++ b/resources/views/livewire/project/application/deployment/index.blade.php @@ -9,13 +9,13 @@

Deployments ({{ $deployments_count }})

@if ($deployments_count > 0) - + - + @@ -45,11 +45,16 @@
data_get($deployment, 'status') === 'in_progress', - 'bg-purple-100/80 text-purple-700 dark:bg-purple-500/20 dark:text-purple-300' => data_get($deployment, 'status') === 'queued', - 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-200' => data_get($deployment, 'status') === 'failed', - 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-200' => data_get($deployment, 'status') === 'finished', - 'bg-gray-100 text-gray-700 dark:bg-gray-600/30 dark:text-gray-300' => data_get($deployment, 'status') === 'cancelled-by-user', + 'bg-blue-100/80 text-blue-700 dark:bg-blue-500/20 dark:text-blue-300' => + data_get($deployment, 'status') === 'in_progress', + 'bg-purple-100/80 text-purple-700 dark:bg-purple-500/20 dark:text-purple-300' => + data_get($deployment, 'status') === 'queued', + 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-200' => + data_get($deployment, 'status') === 'failed', + 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-200' => + data_get($deployment, 'status') === 'finished', + 'bg-gray-100 text-gray-700 dark:bg-gray-600/30 dark:text-gray-300' => + data_get($deployment, 'status') === 'cancelled-by-user', ])> @php $statusText = match (data_get($deployment, 'status')) { diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index f007c3cbb..2b05fcdb9 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -17,6 +17,7 @@ @endif +

Terminal

@if (!$hasShell)
diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php index 5a7dcca76..4a55bb019 100644 --- a/resources/views/livewire/project/shared/get-logs.blade.php +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -37,7 +37,7 @@ @if ($resource?->type() === 'application' || str($resource?->type())->startsWith('standalone'))

{{ $container }}

@else -

{{ str($container)->beforeLast('-')->headline() }}

+

{{ str($container)->beforeLast('-')->headline() }}

@endif @if ($pull_request)
({{ $pull_request }})
diff --git a/resources/views/livewire/project/shared/logs.blade.php b/resources/views/livewire/project/shared/logs.blade.php index 78f871a96..23083aeb0 100644 --- a/resources/views/livewire/project/shared/logs.blade.php +++ b/resources/views/livewire/project/shared/logs.blade.php @@ -6,56 +6,86 @@ @if ($type === 'application')

Logs

-
-
Here you can see the logs of the application.
-
- Loading containers... -
- @forelse ($servers as $server) -
-

Server: {{ $server->name }}

-
- @forelse (data_get($server,'containers',[]) as $container) - - @empty -
No containers are running on server: {{ $server->name }}
- @endforelse -
+
+

Logs

+ @if (str($status)->contains('exited')) +
The resource is not running.
+ @else +
+ Loading containers...
- @empty -
No functional server found for the application.
- @endforelse +
+ @forelse ($servers as $server) +
+

Server: {{ $server->name }}

+ @if ($server->isFunctional()) + @if (isset($serverContainers[$server->id]) && count($serverContainers[$server->id]) > 0) + @foreach ($serverContainers[$server->id] as $container) + + @endforeach + @else +
No containers are running on server: {{ $server->name }}
+ @endif + @else +
Server {{ $server->name }} is not functional.
+ @endif +
+ @empty +
No functional server found for the application.
+ @endforelse +
+ @endif
@elseif ($type === 'database')

Logs

-
Here you can see the logs of the database.
- @forelse ($containers as $container) - @if (data_get($servers, '0')) - - @else -
No functional server found for the database.
- @endif - @empty -
No containers are running.
- @endforelse +

Logs

+ @if (str($status)->contains('exited')) +
The resource is not running.
+ @else +
+ Loading containers... +
+
+ @forelse ($containers as $container) + @if (data_get($servers, '0')) + + @else +
No functional server found for the database.
+ @endif + @empty +
No containers are running.
+ @endforelse +
+ @endif
@elseif ($type === 'service')
-

Logs

-
Here you can see the logs of the containers.
- @forelse ($containers as $container) - @if (data_get($servers, '0')) - - @else -
No functional server found for the service.
- @endif - @empty -
No containers are running.
- @endforelse +

Logs

+ @if (str($status)->contains('exited')) +
The resource is not running.
+ @else +
+ Loading containers... +
+
+ @forelse ($containers as $container) + @if (data_get($servers, '0')) + + @else +
No functional server found for the service.
+ @endif + @empty +
No containers are running.
+ @endforelse +
+ @endif
@endif
diff --git a/resources/views/livewire/project/shared/terminal.blade.php b/resources/views/livewire/project/shared/terminal.blade.php index a45920ccd..3f930f4fd 100644 --- a/resources/views/livewire/project/shared/terminal.blade.php +++ b/resources/views/livewire/project/shared/terminal.blade.php @@ -1,14 +1,16 @@
- @if(!$hasShell) + @if (!$hasShell)
- +

Terminal Not Available

-

No shell (bash/sh) is available in this container. Please ensure either bash or sh is installed to use the terminal.

+

No shell (bash/sh) is available in this container. Please + ensure either bash or sh is installed to use the terminal.

@@ -17,8 +19,9 @@
-