2023-04-19 10:42:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
namespace App\Livewire\Project\Application\Deployment;
|
2023-04-19 10:42:15 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
use App\Models\Application;
|
2023-05-30 13:52:17 +00:00
|
|
|
use App\Models\ApplicationDeploymentQueue;
|
2024-01-07 15:23:41 +00:00
|
|
|
use Livewire\Component;
|
2023-04-19 10:42:15 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
class Show extends Component
|
2023-04-19 10:42:15 +00:00
|
|
|
{
|
2024-01-07 15:23:41 +00:00
|
|
|
public Application $application;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public ApplicationDeploymentQueue $application_deployment_queue;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public string $deployment_uuid;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-01-10 17:27:48 +00:00
|
|
|
public string $horizon_job_status;
|
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public $isKeepAliveOn = true;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-12-04 09:57:58 +00:00
|
|
|
public bool $is_debug_enabled = false;
|
|
|
|
|
|
2025-12-15 09:47:03 +00:00
|
|
|
public bool $fullscreen = false;
|
|
|
|
|
|
2025-12-11 08:25:22 +00:00
|
|
|
private bool $deploymentFinishedDispatched = false;
|
|
|
|
|
|
2025-05-19 19:50:32 +00:00
|
|
|
public function getListeners()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'refreshQueue',
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2023-06-15 07:15:41 +00:00
|
|
|
$deploymentUuid = request()->route('deployment_uuid');
|
2023-04-19 10:42:15 +00:00
|
|
|
|
2023-08-22 15:44:49 +00:00
|
|
|
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $project) {
|
2023-04-25 12:43:35 +00:00
|
|
|
return redirect()->route('dashboard');
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
2024-11-22 14:52:36 +00:00
|
|
|
$environment = $project->load(['environments'])->environments->where('uuid', request()->route('environment_uuid'))->first()->load(['applications']);
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $environment) {
|
2023-04-25 12:43:35 +00:00
|
|
|
return redirect()->route('dashboard');
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
|
|
|
|
$application = $environment->applications->where('uuid', request()->route('application_uuid'))->first();
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $application) {
|
2023-04-25 12:43:35 +00:00
|
|
|
return redirect()->route('dashboard');
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
2023-06-30 13:57:40 +00:00
|
|
|
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $application_deployment_queue) {
|
2024-01-07 15:23:41 +00:00
|
|
|
return redirect()->route('project.application.deployment.index', [
|
2023-05-30 13:52:17 +00:00
|
|
|
'project_uuid' => $project->uuid,
|
2024-11-22 14:52:36 +00:00
|
|
|
'environment_uuid' => $environment->uuid,
|
2023-05-30 13:52:17 +00:00
|
|
|
'application_uuid' => $application->uuid,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->application = $application;
|
|
|
|
|
$this->application_deployment_queue = $application_deployment_queue;
|
2025-01-10 17:27:48 +00:00
|
|
|
$this->horizon_job_status = $this->application_deployment_queue->getHorizonJobStatus();
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->deployment_uuid = $deploymentUuid;
|
2025-12-04 09:57:58 +00:00
|
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
2025-01-10 17:27:48 +00:00
|
|
|
$this->isKeepAliveOn();
|
2024-01-07 15:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 09:57:58 +00:00
|
|
|
public function toggleDebug()
|
|
|
|
|
{
|
2025-12-04 10:42:39 +00:00
|
|
|
try {
|
|
|
|
|
$this->authorize('update', $this->application);
|
|
|
|
|
$this->application->settings->is_debug_enabled = ! $this->application->settings->is_debug_enabled;
|
|
|
|
|
$this->application->settings->save();
|
|
|
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
|
|
|
|
$this->application_deployment_queue->refresh();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2025-12-04 09:57:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-07 15:23:41 +00:00
|
|
|
public function refreshQueue()
|
|
|
|
|
{
|
|
|
|
|
$this->application_deployment_queue->refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-10 17:27:48 +00:00
|
|
|
private function isKeepAliveOn()
|
2024-01-07 15:23:41 +00:00
|
|
|
{
|
2024-10-31 14:23:19 +00:00
|
|
|
if (data_get($this->application_deployment_queue, 'status') === 'finished' || data_get($this->application_deployment_queue, 'status') === 'failed') {
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->isKeepAliveOn = false;
|
2025-01-10 17:27:48 +00:00
|
|
|
} else {
|
|
|
|
|
$this->isKeepAliveOn = true;
|
2024-01-07 15:23:41 +00:00
|
|
|
}
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
2024-09-03 18:06:03 +00:00
|
|
|
|
2025-01-10 17:27:48 +00:00
|
|
|
public function polling()
|
|
|
|
|
{
|
|
|
|
|
$this->application_deployment_queue->refresh();
|
|
|
|
|
$this->horizon_job_status = $this->application_deployment_queue->getHorizonJobStatus();
|
|
|
|
|
$this->isKeepAliveOn();
|
2025-12-11 08:14:27 +00:00
|
|
|
|
2025-12-11 08:25:22 +00:00
|
|
|
// Dispatch event when deployment finishes to stop auto-scroll (only once)
|
|
|
|
|
if (! $this->isKeepAliveOn && ! $this->deploymentFinishedDispatched) {
|
|
|
|
|
$this->deploymentFinishedDispatched = true;
|
2025-12-11 08:14:27 +00:00
|
|
|
$this->dispatch('deploymentFinished');
|
|
|
|
|
}
|
2025-01-10 17:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-04 01:39:50 +00:00
|
|
|
public function getLogLinesProperty()
|
2024-09-03 18:06:03 +00:00
|
|
|
{
|
2025-12-18 11:30:26 +00:00
|
|
|
return decode_remote_command_output($this->application_deployment_queue);
|
2024-09-03 18:06:03 +00:00
|
|
|
}
|
2024-09-04 01:39:50 +00:00
|
|
|
|
2025-12-17 19:54:22 +00:00
|
|
|
public function copyLogs(): string
|
|
|
|
|
{
|
|
|
|
|
$logs = decode_remote_command_output($this->application_deployment_queue)
|
|
|
|
|
->map(function ($line) {
|
|
|
|
|
return $line['timestamp'].' '.
|
|
|
|
|
(isset($line['command']) && $line['command'] ? '[CMD]: ' : '').
|
|
|
|
|
trim($line['line']);
|
|
|
|
|
})
|
|
|
|
|
->join("\n");
|
|
|
|
|
|
|
|
|
|
return sanitizeLogsForExport($logs);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-02 11:04:17 +00:00
|
|
|
public function downloadAllLogs(): string
|
|
|
|
|
{
|
|
|
|
|
$logs = decode_remote_command_output($this->application_deployment_queue, includeAll: true)
|
|
|
|
|
->map(function ($line) {
|
|
|
|
|
$prefix = '';
|
|
|
|
|
if ($line['hidden']) {
|
|
|
|
|
$prefix = '[DEBUG] ';
|
|
|
|
|
}
|
|
|
|
|
if (isset($line['command']) && $line['command']) {
|
|
|
|
|
$prefix .= '[CMD]: ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $line['timestamp'].' '.$prefix.trim($line['line']);
|
|
|
|
|
})
|
|
|
|
|
->join("\n");
|
|
|
|
|
|
|
|
|
|
return sanitizeLogsForExport($logs);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 01:39:50 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.project.application.deployment.show');
|
|
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|