diff --git a/app/Livewire/Project/Application/Deployment/Show.php b/app/Livewire/Project/Application/Deployment/Show.php index 84a24255c..4b2904594 100644 --- a/app/Livewire/Project/Application/Deployment/Show.php +++ b/app/Livewire/Project/Application/Deployment/Show.php @@ -4,6 +4,7 @@ namespace App\Livewire\Project\Application\Deployment; use App\Models\Application; use App\Models\ApplicationDeploymentQueue; +use Illuminate\Support\Collection; use Livewire\Component; class Show extends Component @@ -12,6 +13,8 @@ class Show extends Component public ApplicationDeploymentQueue $application_deployment_queue; + public Collection $logLines; + public string $deployment_uuid; public $isKeepAliveOn = true; @@ -53,11 +56,13 @@ class Show extends Component $this->application = $application; $this->application_deployment_queue = $application_deployment_queue; $this->deployment_uuid = $deploymentUuid; + $this->buildLogLines(); } public function refreshQueue() { $this->application_deployment_queue->refresh(); + $this->buildLogLines(); } public function polling() @@ -67,10 +72,25 @@ class Show extends Component if (data_get($this->application_deployment_queue, 'status') == 'finished' || data_get($this->application_deployment_queue, 'status') == 'failed') { $this->isKeepAliveOn = false; } + $this->buildLogLines(); } public function render() { return view('livewire.project.application.deployment.show'); } + + private function buildLogLines() + { + $this->logLines = decode_remote_command_output($this->application_deployment_queue)->map(function ($logLine) { + $logLine['line'] = e($logLine['line']); + $logLine['line'] = preg_replace( + '/(https?:\/\/[^\s]+)/', + '$1', + $logLine['line'], + ); + + return $logLine; + }); + } } diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index 6ba7caeef..c3f8316e7 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -234,6 +234,7 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d return collect([]); } // ray($decoded ); + $seenCommands = collect(); $formatted = collect($decoded); if (! $is_debug_enabled) { $formatted = $formatted->filter(fn ($i) => $i['hidden'] === false ?? false); @@ -244,7 +245,36 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d data_set($i, 'timestamp', Carbon::parse(data_get($i, 'timestamp'))->format('Y-M-d H:i:s.u')); return $i; - }); + }) + ->reduce(function ($deploymentLogLines, $logItem) use ($seenCommands) { + $command = $logItem['command']; + $isStderr = $logItem['type'] === 'stderr'; + + if (! is_null($command) && ! $seenCommands->contains($command)) { + $deploymentLogLines->push([ + 'line' => $command, + 'timestamp' => $logItem['timestamp'], + 'stderr' => $isStderr, + 'hidden' => $logItem['hidden'], + 'command' => true, + ]); + + $seenCommands->push($command); + } + + $lines = explode(PHP_EOL, $logItem['output']); + + foreach ($lines as $line) { + $deploymentLogLines->push([ + 'line' => $line, + 'timestamp' => $logItem['timestamp'], + 'stderr' => $isStderr, + 'hidden' => $logItem['hidden'], + ]); + } + + return $deploymentLogLines; + }, collect()); return $formatted; } diff --git a/resources/views/livewire/project/application/deployment/show.blade.php b/resources/views/livewire/project/application/deployment/show.blade.php index f97914ec2..bc8ab3f34 100644 --- a/resources/views/livewire/project/application/deployment/show.blade.php +++ b/resources/views/livewire/project/application/deployment/show.blade.php @@ -9,6 +9,7 @@ fullscreen: false, alwaysScroll: false, intervalId: null, + showTimestamps: false, makeFullscreen() { this.fullscreen = !this.fullscreen; if (this.fullscreen === false) { @@ -53,63 +54,65 @@ class="dark:text-warning">{{ Str::headline(data_get($application_deployment_queue, 'status')) }}. @endif -
+
- - - + class="flex flex-col-reverse w-full p-2 px-4 mt-4 overflow-y-auto bg-white dark:text-white dark:bg-coolgray-100 scrollbar dark:border-coolgray-300" + :class="fullscreen ? '' : 'min-h-14 max-h-[40rem] border border-dotted rounded'" + > +
+
+ + + + + +
+
-
- @if (decode_remote_command_output($application_deployment_queue)->count() > 0) - @foreach (decode_remote_command_output($application_deployment_queue) as $line) - $line['hidden'], - 'text-red-500 font-bold whitespace-pre-line' => $line['type'] == 'stderr', - ])>[{{ $line['timestamp'] }}] @if ($line['hidden']) -

[COMMAND] {{ $line['command'] }}
[OUTPUT] - @endif @if (str($line['output'])->contains('http://') || str($line['output'])->contains('https://')) - @php - $line['output'] = preg_replace( - '/(https?:\/\/[^\s]+)/', - '$1', - $line['output'], - ); - @endphp {!! $line['output'] !!} - @else - {{ $line['output'] }} - - @endif -
- @endforeach - @else - No logs yet. - @endif + @forelse ($logLines as $line) +
$line['command'] ?? false, + 'flex gap-2 dark:hover:bg-coolgray-500 hover:bg-gray-100' + ]) + > + {{ $line['timestamp'] }} + $line['hidden'], + 'text-red-500' => $line['stderr'], + 'font-bold' => $line['command'] ?? false, + 'whitespace-pre-wrap', + ]) + >{!! $line['line'] !!} +
+ @empty + No logs yet. + @endforelse