Merge pull request #3302 from mahansky/deployment-logs-improvements
deployment log improvements
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Application\Deployment;
|
|||||||
|
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
use App\Models\ApplicationDeploymentQueue;
|
use App\Models\ApplicationDeploymentQueue;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Show extends Component
|
class Show extends Component
|
||||||
@@ -69,6 +70,20 @@ class Show extends Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLogLinesProperty()
|
||||||
|
{
|
||||||
|
return decode_remote_command_output($this->application_deployment_queue)->map(function ($logLine) {
|
||||||
|
$logLine['line'] = e($logLine['line']);
|
||||||
|
$logLine['line'] = preg_replace(
|
||||||
|
'/(https?:\/\/[^\s]+)/',
|
||||||
|
'<a href="$1" target="_blank" rel="noopener noreferrer" class="underline text-neutral-400">$1</a>',
|
||||||
|
$logLine['line'],
|
||||||
|
);
|
||||||
|
|
||||||
|
return $logLine;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.project.application.deployment.show');
|
return view('livewire.project.application.deployment.show');
|
||||||
|
@@ -234,6 +234,7 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d
|
|||||||
return collect([]);
|
return collect([]);
|
||||||
}
|
}
|
||||||
// ray($decoded );
|
// ray($decoded );
|
||||||
|
$seenCommands = collect();
|
||||||
$formatted = collect($decoded);
|
$formatted = collect($decoded);
|
||||||
if (! $is_debug_enabled) {
|
if (! $is_debug_enabled) {
|
||||||
$formatted = $formatted->filter(fn ($i) => $i['hidden'] === false ?? false);
|
$formatted = $formatted->filter(fn ($i) => $i['hidden'] === false ?? false);
|
||||||
@@ -244,7 +245,42 @@ 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'));
|
data_set($i, 'timestamp', Carbon::parse(data_get($i, 'timestamp'))->format('Y-M-d H:i:s.u'));
|
||||||
|
|
||||||
return $i;
|
return $i;
|
||||||
});
|
})
|
||||||
|
->reduce(function ($deploymentLogLines, $logItem) use ($seenCommands) {
|
||||||
|
$command = $logItem['command'];
|
||||||
|
$isStderr = $logItem['type'] === 'stderr';
|
||||||
|
$isNewCommand = ! is_null($command) && ! $seenCommands->first(function ($seenCommand) use ($logItem) {
|
||||||
|
return $seenCommand['command'] === $logItem['command'] && $seenCommand['batch'] === $logItem['batch'];
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($isNewCommand) {
|
||||||
|
$deploymentLogLines->push([
|
||||||
|
'line' => $command,
|
||||||
|
'timestamp' => $logItem['timestamp'],
|
||||||
|
'stderr' => $isStderr,
|
||||||
|
'hidden' => $logItem['hidden'],
|
||||||
|
'command' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$seenCommands->push([
|
||||||
|
'command' => $command,
|
||||||
|
'batch' => $logItem['batch'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
return $formatted;
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
alwaysScroll: false,
|
alwaysScroll: false,
|
||||||
intervalId: null,
|
intervalId: null,
|
||||||
|
showTimestamps: false,
|
||||||
makeFullscreen() {
|
makeFullscreen() {
|
||||||
this.fullscreen = !this.fullscreen;
|
this.fullscreen = !this.fullscreen;
|
||||||
if (this.fullscreen === false) {
|
if (this.fullscreen === false) {
|
||||||
@@ -53,63 +54,65 @@
|
|||||||
class="dark:text-warning">{{ Str::headline(data_get($application_deployment_queue, 'status')) }}</span>.
|
class="dark:text-warning">{{ Str::headline(data_get($application_deployment_queue, 'status')) }}</span>.
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
<div id="screen" :class="fullscreen ? 'fullscreen' : ''">
|
<div id="screen" :class="fullscreen ? 'fullscreen' : 'relative'">
|
||||||
<div @if ($isKeepAliveOn) wire:poll.2000ms="polling" @endif
|
<div @if ($isKeepAliveOn) wire:poll.2000ms="polling" @endif
|
||||||
class="relative 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="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 ? '' : 'max-h-[40rem] border border-dotted rounded'">
|
:class="fullscreen ? '' : 'min-h-14 max-h-[40rem] border border-dotted rounded'"
|
||||||
<button title="Minimize" x-show="fullscreen" class="fixed top-4 right-4"
|
>
|
||||||
x-on:click="makeFullscreen"><svg class="icon" viewBox="0 0 24 24"
|
<div :class="fullscreen ? 'fixed' : 'absolute'" class="top-4 right-6">
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
<div class="flex justify-end gap-4 fixed -translate-x-full">
|
||||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
|
<button title="Toggle timestamps" x-on:click="showTimestamps = !showTimestamps">
|
||||||
stroke-width="2" d="M6 14h4m0 0v4m0-4l-6 6m14-10h-4m0 0V6m0 4l6-6" />
|
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
</svg></button>
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
|
||||||
<button title="Go Top" x-show="fullscreen" class="fixed top-4 right-28" x-on:click="goTop"> <svg
|
</svg>
|
||||||
class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
</button>
|
||||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
|
<button title="Go Top" x-show="fullscreen" x-on:click="goTop">
|
||||||
stroke-width="2" d="M12 5v14m4-10l-4-4M8 9l4-4" />
|
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
</svg></button>
|
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v14m4-10l-4-4M8 9l4-4" />
|
||||||
<button title="Follow Logs" x-show="fullscreen" :class="alwaysScroll ? 'dark:text-warning' : ''"
|
</svg>
|
||||||
class="fixed top-4 right-16" x-on:click="toggleScroll"><svg class="icon" viewBox="0 0 24 24"
|
</button>
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
<button title="Follow Logs" x-show="fullscreen" :class="alwaysScroll ? 'dark:text-warning' : ''" x-on:click="toggleScroll">
|
||||||
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
|
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
stroke-width="2" d="M12 5v14m4-4l-4 4m-4-4l4 4" />
|
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 5v14m4-4l-4 4m-4-4l4 4" />
|
||||||
</svg></button>
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button title="Fullscreen" x-show="!fullscreen" x-on:click="makeFullscreen">
|
||||||
|
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<g fill="none">
|
||||||
|
<path d="M24 0v24H0V0h24ZM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427c-.002-.01-.009-.017-.017-.018Zm.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093c.012.004.023 0 .029-.008l.004-.014l-.034-.614c-.003-.012-.01-.02-.02-.022Zm-.715.002a.023.023 0 0 0-.027.006l-.006.014l-.034.614c0 .012.007.02.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01l-.184-.092Z" />
|
||||||
|
<path fill="currentColor" d="M9.793 12.793a1 1 0 0 1 1.497 1.32l-.083.094L6.414 19H9a1 1 0 0 1 .117 1.993L9 21H4a1 1 0 0 1-.993-.883L3 20v-5a1 1 0 0 1 1.993-.117L5 15v2.586l4.793-4.793ZM20 3a1 1 0 0 1 .993.883L21 4v5a1 1 0 0 1-1.993.117L19 9V6.414l-4.793 4.793a1 1 0 0 1-1.497-1.32l.083-.094L17.586 5H15a1 1 0 0 1-.117-1.993L15 3h5Z" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button title="Minimize" x-show="fullscreen" x-on:click="makeFullscreen">
|
||||||
|
<svg class="icon" viewBox="0 0 24 24"xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 14h4m0 0v4m0-4l-6 6m14-10h-4m0 0V6m0 4l6-6" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button title="Fullscreen" x-show="!fullscreen" class="absolute top-2 right-8"
|
|
||||||
x-on:click="makeFullscreen"><svg class="fixed icon" viewBox="0 0 24 24"
|
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<g fill="none">
|
|
||||||
<path
|
|
||||||
d="M24 0v24H0V0h24ZM12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035c-.01-.004-.019-.001-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427c-.002-.01-.009-.017-.017-.018Zm.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093c.012.004.023 0 .029-.008l.004-.014l-.034-.614c-.003-.012-.01-.02-.02-.022Zm-.715.002a.023.023 0 0 0-.027.006l-.006.014l-.034.614c0 .012.007.02.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01l-.184-.092Z" />
|
|
||||||
<path fill="currentColor"
|
|
||||||
d="M9.793 12.793a1 1 0 0 1 1.497 1.32l-.083.094L6.414 19H9a1 1 0 0 1 .117 1.993L9 21H4a1 1 0 0 1-.993-.883L3 20v-5a1 1 0 0 1 1.993-.117L5 15v2.586l4.793-4.793ZM20 3a1 1 0 0 1 .993.883L21 4v5a1 1 0 0 1-1.993.117L19 9V6.414l-4.793 4.793a1 1 0 0 1-1.497-1.32l.083-.094L17.586 5H15a1 1 0 0 1-.117-1.993L15 3h5Z" />
|
|
||||||
</g>
|
|
||||||
</svg></button>
|
|
||||||
<div id="logs" class="flex flex-col font-mono">
|
<div id="logs" class="flex flex-col font-mono">
|
||||||
@if (decode_remote_command_output($application_deployment_queue)->count() > 0)
|
@forelse ($this->logLines as $line)
|
||||||
@foreach (decode_remote_command_output($application_deployment_queue) as $line)
|
<div
|
||||||
<span @class([
|
@class([
|
||||||
'text-coollabs dark:text-warning whitespace-pre-line' => $line['hidden'],
|
'mt-2' => $line['command'] ?? false,
|
||||||
'text-red-500 font-bold whitespace-pre-line' => $line['type'] == 'stderr',
|
'flex gap-2 dark:hover:bg-coolgray-500 hover:bg-gray-100'
|
||||||
])>[{{ $line['timestamp'] }}] @if ($line['hidden'])
|
])
|
||||||
<br><br>[COMMAND] {{ $line['command'] }}<br>[OUTPUT]
|
>
|
||||||
@endif @if (str($line['output'])->contains('http://') || str($line['output'])->contains('https://'))
|
<span x-show="showTimestamps" class="shrink-0 text-gray-500">{{ $line['timestamp'] }}</span>
|
||||||
@php
|
<span
|
||||||
$line['output'] = preg_replace(
|
@class([
|
||||||
'/(https?:\/\/[^\s]+)/',
|
'text-coollabs dark:text-warning' => $line['hidden'],
|
||||||
'<a href="$1" target="_blank" class="underline text-neutral-400">$1</a>',
|
'text-red-500' => $line['stderr'],
|
||||||
$line['output'],
|
'font-bold' => $line['command'] ?? false,
|
||||||
);
|
'whitespace-pre-wrap',
|
||||||
@endphp {!! $line['output'] !!}
|
])
|
||||||
@else
|
>{!! $line['line'] !!}</span>
|
||||||
{{ $line['output'] }}
|
</div>
|
||||||
|
@empty
|
||||||
@endif
|
<span class="font-mono text-neutral-400 mb-2">No logs yet.</span>
|
||||||
</span>
|
@endforelse
|
||||||
@endforeach
|
|
||||||
@else
|
|
||||||
<span class="font-mono text-neutral-400">No logs yet.</span>
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user