From d1feb95eef175a984ab71178928b9715fe023c49 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 19 Sep 2024 18:53:28 +0300 Subject: [PATCH] update --- .../Resources/GitRepositoryResource.php | 8 +++++++ web/app/Models/GitRepository.php | 21 +++++++++++++++++-- .../views/actions/git/git-executor.blade.php | 2 +- .../resources/git-repositories/log.blade.php | 10 +++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 web/resources/views/filament/resources/git-repositories/log.blade.php diff --git a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php index dfa0d04..57dc1dc 100644 --- a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php +++ b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php @@ -87,6 +87,14 @@ class GitRepositoryResource extends Resource ]) ->actions([ Tables\Actions\EditAction::make(), + + Tables\Actions\Action::make('log') + ->label('Log') + ->form([ + Forms\Components\View::make('log') + ->view('filament.resources.git-repositories.log') + ]), + Tables\Actions\Action::make('pull') // ->hidden(fn (GitRepository $record) => $record->status !== 'cloned') ->icon('heroicon-o-arrow-down-tray') diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php index f068203..5460b40 100644 --- a/web/app/Models/GitRepository.php +++ b/web/app/Models/GitRepository.php @@ -149,7 +149,7 @@ class GitRepository extends Model $cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git'; $shellFile = $findDomain->domain_root . '/git/tmp/git-pull-' . $this->id . '.sh'; - $shellLog = $findDomain->domain_root . '/git/tmp/git-pull-' . $this->id . '.log'; + $shellLog = $findDomain->domain_root . '/git/tmp/git-action-' . $this->id . '.log'; shell_exec('mkdir -p ' . dirname($shellFile)); shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname(dirname($shellFile))); @@ -175,6 +175,7 @@ class GitRepository extends Model $gitExecutorContent = view('actions.git.git-executor', [ 'shellFile' => $shellFile, + 'shellLog' => $shellLog, 'systemUsername' => $findHostingSubscription->system_username, 'selfFile' => $gitExecutorShellFile, 'afterCommand' => 'phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-pulled '.$this->id, @@ -228,7 +229,7 @@ class GitRepository extends Model $cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git'; $shellFile = $findDomain->domain_root . '/git/tmp/git-clone-' . $this->id . '.sh'; - $shellLog = $findDomain->domain_root . '/git/tmp/git-clone-' . $this->id . '.log'; + $shellLog = $findDomain->domain_root . '/git/tmp/git-action-' . $this->id . '.log'; shell_exec('mkdir -p ' . dirname($shellFile)); shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname(dirname($shellFile))); @@ -252,4 +253,20 @@ class GitRepository extends Model } + public function getLog() + { + $findDomain = Domain::find($this->domain_id); + if (!$findDomain) { + return 'Domain not found'; + } + + $shellLog = $findDomain->domain_root . '/git/tmp/git-action-' . $this->id . '.log'; + if (file_exists($shellLog)) { + $content = file_get_contents($shellLog); + return nl2br($content); + } + + return 'No logs'; + } + } diff --git a/web/resources/views/actions/git/git-executor.blade.php b/web/resources/views/actions/git/git-executor.blade.php index 94ad7e0..2ca7905 100644 --- a/web/resources/views/actions/git/git-executor.blade.php +++ b/web/resources/views/actions/git/git-executor.blade.php @@ -1,7 +1,7 @@ chmod +x {{$shellFile}} chown {{$systemUsername}}:{{$systemUsername}} {{$shellFile}} -sudo -m {{$systemUsername}} -c "bash {{$shellFile}}" +su -m {{$systemUsername}} -c "bash {{$shellFile}} > {{$shellLog}}" @if ($afterCommand) diff --git a/web/resources/views/filament/resources/git-repositories/log.blade.php b/web/resources/views/filament/resources/git-repositories/log.blade.php new file mode 100644 index 0000000..822accf --- /dev/null +++ b/web/resources/views/filament/resources/git-repositories/log.blade.php @@ -0,0 +1,10 @@ +
+ + @php + $record = $getRecord(); + @endphp + + {!! $record->getLog() !!} + + +