This commit is contained in:
Bozhidar 2024-09-19 18:53:28 +03:00
parent 058b71631e
commit d1feb95eef
4 changed files with 38 additions and 3 deletions

View file

@ -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')

View file

@ -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';
}
}

View file

@ -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)

View file

@ -0,0 +1,10 @@
<div>
@php
$record = $getRecord();
@endphp
{!! $record->getLog() !!}
</div>