diff --git a/app/Containers/Dashboard/Actions/Posts/DeploySiteAction.php b/app/Containers/Dashboard/Actions/Posts/DeploySiteAction.php deleted file mode 100644 index 197aeae..0000000 --- a/app/Containers/Dashboard/Actions/Posts/DeploySiteAction.php +++ /dev/null @@ -1,97 +0,0 @@ -deployTask->scriptExists()) { - Log::channel('deploy')->warning('[DeployAction] Script not found'); - return [ - 'success' => false, - 'message' => 'Скрипт деплоя не найден на сервере', - ]; - } - - if ($this->deployTask->isDeployRunning()) { - Log::channel('deploy')->warning('[DeployAction] Deploy already running', [ - 'user_id' => auth()->id(), - ]); - return [ - 'success' => false, - 'message' => 'Деплой уже запущен! Подождите завершения текущего процесса.', - ]; - } - - $started = $this->deployTask->startDeploy(); - - if (!$started) { - Log::channel('deploy')->error('[DeployAction] Failed to start deploy script', [ - 'user_id' => auth()->id(), - ]); - return [ - 'success' => false, - 'message' => 'Скрипт деплоя не запустился. Проверьте лог.', - ]; - } - - Log::channel('deploy')->info('[DeployAction] Deploy triggered successfully', [ - 'user_id' => auth()->id(), - 'user_email' => auth()->user()?->email, - ]); - - return [ - 'success' => true, - 'message' => 'Деплой запущен! Процесс обновления сайта начнётся в течение нескольких секунд.', - ]; - } catch (\Exception $e) { - Log::channel('deploy')->error('[DeployAction] Exception', [ - 'user_id' => auth()->id(), - 'exception' => $e->getMessage(), - 'trace' => $e->getTraceAsString(), - ]); - - return [ - 'success' => false, - 'message' => 'Ошибка при запуске деплоя: ' . $e->getMessage(), - ]; - } - } - - public function getStatus(): array - { - return $this->deployTask->getDeployStatus(); - } - - public function getLog(int $lines = 50): array - { - return [ - 'log' => $this->deployTask->getLogTail($lines), - 'full_log' => $this->deployTask->getLog(), - ]; - } - - public function getHistory(): array - { - return [ - 'history' => $this->deployTask->getHistory(), - ]; - } - - public function clearStatus(): void - { - Log::channel('deploy')->info('[DeployAction] Log cleared', [ - 'user_id' => auth()->id(), - ]); - $this->deployTask->clearLog(); - } -} diff --git a/app/Containers/Dashboard/Tasks/DeployTask.php b/app/Containers/Dashboard/Tasks/DeployTask.php deleted file mode 100644 index 63676ad..0000000 --- a/app/Containers/Dashboard/Tasks/DeployTask.php +++ /dev/null @@ -1,149 +0,0 @@ -deployScript); - $this->phpLog('check_script', $exists ? 'found' : 'not_found'); - - return $exists; - } - - public function isDeployRunning(): bool - { - $output = shell_exec('pgrep -f "deploy\\.sh"'); - $running = !empty(trim($output ?? '')); - - return $running; - } - - public function startDeploy(): bool - { - if ($this->isDeployRunning()) { - $this->phpLog('start', 'already_running'); - return false; - } - - if (file_exists($this->logFile)) { - unlink($this->logFile); - } - - $this->phpLog('start', 'launching deploy.sh'); - - $command = sprintf( - 'bash %s > /dev/null 2>&1 &', - escapeshellarg($this->deployScript) - ); - - shell_exec($command); - usleep(500000); - - $started = $this->isDeployRunning(); - - $this->phpLog('start', $started ? 'process_started' : 'process_failed_to_start'); - - return $started; - } - - public function getDeployStatus(): array - { - if (!$this->isDeployRunning()) { - if (!file_exists($this->logFile)) { - $this->phpLog('status', 'idle'); - return ['status' => 'idle', 'message' => 'Деплой не запущен']; - } - - $log = $this->getLog(); - $lastLines = array_slice(explode("\n", trim($log)), -5); - $lastOutput = implode("\n", $lastLines); - - $isSuccess = stripos($lastOutput, '✅') !== false - || stripos($lastOutput, 'completed successfully') !== false; - - $isFailed = stripos($lastOutput, '❌') !== false - || stripos($lastOutput, 'ERROR') !== false; - - $status = $isSuccess ? 'completed' : ($isFailed ? 'failed' : 'unknown'); - $this->phpLog('status', $status); - - return [ - 'status' => $status, - 'message' => $isSuccess ? 'Деплой завершён успешно!' : 'Деплой завершён', - 'log' => $log, - ]; - } - - $this->phpLog('status', 'running'); - - return [ - 'status' => 'running', - 'message' => 'Деплой выполняется...', - 'log' => $this->getLog(), - ]; - } - - public function getLog(): string - { - if (!file_exists($this->logFile)) { - return ''; - } - return file_get_contents($this->logFile); - } - - public function getLogTail(int $lines = 50): string - { - $log = $this->getLog(); - if (empty($log)) { - return ''; - } - $allLines = explode("\n", trim($log)); - return implode("\n", array_slice($allLines, -$lines)); - } - - public function clearLog(): void - { - if (file_exists($this->logFile)) { - unlink($this->logFile); - } - - $this->phpLog('clear', 'deploy log cleared'); - } - - public function getHistory(): array - { - if (!is_dir($this->historyDir)) { - return []; - } - - $files = glob($this->historyDir . '/*.json'); - usort($files, fn($a, $b) => strcmp($b, $a)); - - $history = []; - foreach (array_slice($files, 0, 50) as $file) { - $content = file_get_contents($file); - $data = json_decode($content, true); - if ($data) { - $history[] = $data; - } - } - - return $history; - } - - private function phpLog(string $event, string $message): void - { - Log::channel('deploy')->info('[Deploy] {event}: {message}', [ - 'event' => $event, - 'message' => $message, - ]); - } -} diff --git a/app/Containers/Dashboard/UI/WEB/Controllers/DeployController.php b/app/Containers/Dashboard/UI/WEB/Controllers/DeployController.php deleted file mode 100644 index 343c04d..0000000 --- a/app/Containers/Dashboard/UI/WEB/Controllers/DeployController.php +++ /dev/null @@ -1,103 +0,0 @@ -deploySiteAction->getHistory(); - $status = $this->deploySiteAction->getStatus(); - - return Inertia::render('Dashboard/Deploy/Index', [ - 'history' => $history['history'], - 'status' => $status, - ]); - } - - public function deploy(Request $request): JsonResponse - { - if (app()->environment() !== 'production') { - return response()->json([ - 'success' => false, - 'message' => 'Деплой доступен только на production', - ], 403); - } - - if (!$request->user()->hasRole('super_admin')) { - return response()->json([ - 'success' => false, - 'message' => 'Недостаточно прав для выполнения этой операции', - ], 403); - } - - $result = $this->deploySiteAction->run(); - - return response()->json($result); - } - - public function status(Request $request): JsonResponse - { - if (app()->environment() !== 'production') { - return response()->json(['status' => 'disabled'], 403); - } - - if (!$request->user()->hasRole('super_admin')) { - return response()->json([ - 'success' => false, - 'message' => 'Недостаточно прав', - ], 403); - } - - $status = $this->deploySiteAction->getStatus(); - - return response()->json($status); - } - - public function log(Request $request): JsonResponse - { - if (!$request->user()->hasRole('super_admin')) { - return response()->json(['success' => false], 403); - } - - $lines = (int) $request->query('lines', 50); - $result = $this->deploySiteAction->getLog($lines); - - return response()->json($result); - } - - public function history(Request $request): JsonResponse - { - if (!$request->user()->hasRole('super_admin')) { - return response()->json(['success' => false], 403); - } - - $result = $this->deploySiteAction->getHistory(); - - return response()->json($result); - } - - public function clear(Request $request): JsonResponse - { - if (!$request->user()->hasRole('super_admin')) { - return response()->json([ - 'success' => false, - 'message' => 'Недостаточно прав', - ], 403); - } - - $this->deploySiteAction->clearStatus(); - - return response()->json(['success' => true]); - } -} diff --git a/app/Containers/Dashboard/UI/WEB/Routes/web.php b/app/Containers/Dashboard/UI/WEB/Routes/web.php index 2e73994..1722e8b 100755 --- a/app/Containers/Dashboard/UI/WEB/Routes/web.php +++ b/app/Containers/Dashboard/UI/WEB/Routes/web.php @@ -10,7 +10,6 @@ use App\Containers\Dashboard\UI\WEB\Controllers\CategoryController as NewsCatego use App\Containers\Dashboard\UI\WEB\Controllers\ContactWidgetController; use App\Containers\Dashboard\UI\WEB\Controllers\CreateSliderController; use App\Containers\Dashboard\UI\WEB\Controllers\CustomFormController; -use App\Containers\Dashboard\UI\WEB\Controllers\DeployController; use App\Containers\Dashboard\UI\WEB\Controllers\DepartmentController; use App\Containers\Dashboard\UI\WEB\Controllers\PageReferenceListController; use App\Containers\Dashboard\UI\WEB\Controllers\DepartmentProgramController; @@ -63,13 +62,6 @@ Route::post('/dashboard/logout', [AuthenticatedSessionController::class, 'destro // Authenticated dashboard routes Route::middleware(['access-check', 'dashboard.auth'])->group(function () { Route::get('/dashboard', IndexDashboardController::class)->name('dashboard.index'); - Route::get('/dashboard/deploy', [DeployController::class, 'index'])->name('dashboard.deploy.index'); - Route::post('/dashboard/deploy', [DeployController::class, 'deploy'])->name('dashboard.deploy'); - Route::get('/dashboard/deploy/status', [DeployController::class, 'status'])->name('dashboard.deploy.status'); - Route::get('/dashboard/deploy/log', [DeployController::class, 'log'])->name('dashboard.deploy.log'); - Route::get('/dashboard/deploy/history', [DeployController::class, 'history'])->name('dashboard.deploy.history'); - Route::post('/dashboard/deploy/clear', [DeployController::class, 'clear'])->name('dashboard.deploy.clear'); - Route::get('/dashboard/sveden', [SvedenController::class, 'index'])->name('dashboard.sveden'); Route::post('/dashboard/sveden', [SvedenController::class, 'store'])->name('dashboard.sveden.store'); diff --git a/config/logging.php b/config/logging.php index 423e7bd..c44d276 100755 --- a/config/logging.php +++ b/config/logging.php @@ -118,13 +118,6 @@ return [ 'replace_placeholders' => true, ], - 'deploy' => [ - 'driver' => 'single', - 'path' => storage_path('logs/deploy.log'), - 'level' => 'info', - 'replace_placeholders' => true, - ], - 'null' => [ 'driver' => 'monolog', 'handler' => NullHandler::class, diff --git a/resources/js/Pages/Dashboard/Components/menuConfig.js b/resources/js/Pages/Dashboard/Components/menuConfig.js index 6b86588..84ba03c 100644 --- a/resources/js/Pages/Dashboard/Components/menuConfig.js +++ b/resources/js/Pages/Dashboard/Components/menuConfig.js @@ -121,13 +121,6 @@ export const menuItems = [ { label: 'Все пользователи', route: 'dashboard.users.index' }, ], }, - { - key: 'deploy', - label: 'Деплой', - icon: 'arrow-up-tray', - route: 'dashboard.deploy.index', - activePrefixes: ['dashboard.deploy'], - }, { key: 'vikon-updates', label: 'Обновления VIKON', diff --git a/resources/js/Pages/Dashboard/Deploy/Index.vue b/resources/js/Pages/Dashboard/Deploy/Index.vue deleted file mode 100644 index d8b600a..0000000 --- a/resources/js/Pages/Dashboard/Deploy/Index.vue +++ /dev/null @@ -1,266 +0,0 @@ - - - diff --git a/resources/js/Pages/Dashboard/Main.vue b/resources/js/Pages/Dashboard/Main.vue index db59fe8..49eacf8 100755 --- a/resources/js/Pages/Dashboard/Main.vue +++ b/resources/js/Pages/Dashboard/Main.vue @@ -6,43 +6,6 @@ - -
-
-
-
- -
-
-

Обновление сайта

-

Запуск скрипта деплоя и пересборка сервера

-
-
- -
- - -
-
- - {{ deployMessage }} -
-
{{ deployOutput }}
-
-
- @@ -124,11 +87,6 @@ export default { }, data() { return { - deploying: false, - deployOutput: null, - deploySuccess: false, - deployStatus: null, - deployPolling: null, domainSections: [ { title: 'Контент сайта', @@ -167,80 +125,7 @@ export default { mounted() { this.SET_DOCUMENT_TITLE('Главная'); }, - beforeUnmount() { - if (this.deployPolling) { - clearInterval(this.deployPolling); - } - }, - computed: { - isProduction() { - return this.$page.props.app?.env === 'production'; - }, - }, methods: { - async deploySite() { - if (!confirm('Вы уверены, что хотите обновить сайт? Это запустит скрипт деплоя.')) { - return; - } - - this.deploying = true; - this.deployOutput = null; - this.deploySuccess = false; - - try { - const response = await fetch(route('dashboard.deploy'), { - method: 'POST', - headers: { - 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, - 'Accept': 'application/json', - }, - }); - - const result = await response.json(); - - this.deploySuccess = result.success; - this.deployOutput = result.message; - - // Если деплой запущен — начинаем polling статуса - if (result.success) { - this.startDeployPolling(); - } - } catch (error) { - this.deploySuccess = false; - this.deployOutput = 'Ошибка при выполнении запроса: ' + error.message; - } finally { - this.deploying = false; - } - }, - - startDeployPolling() { - // Проверяем статус каждые 3 секунды - this.deployPolling = setInterval(async () => { - try { - const response = await fetch(route('dashboard.deploy.status')); - const status = await response.json(); - - this.deployStatus = status; - - if (status.status === 'completed' || status.status === 'failed' || status.status === 'idle') { - clearInterval(this.deployPolling); - this.deployPolling = null; - this.deployOutput = status.message || 'Деплой завершён'; - this.deploySuccess = status.status === 'completed'; - - if (status.log) { - this.deployOutput += '\n\n' + status.log; - } - } - } catch (error) { - console.error('Error polling deploy status:', error); - } - }, 3000); - }, - get deployMessage() { - if (!this.deployOutput) return ''; - return this.deploySuccess ? 'Сайт успешно обновлён!' : 'Ошибка при обновлении сайта'; - }, getBgClass(color) { const map = { primary: 'bg-primary/10',