From daf59985686cae8a9ea97d3c2cb1600e0eecba1b Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 19 Sep 2024 18:10:55 +0300 Subject: [PATCH] update --- .../App/Filament/Resources/GitRepositoryResource.php | 4 ++++ web/app/Models/GitRepository.php | 12 +++++++++--- web/resources/views/actions/git/pull-repo.blade.php | 11 ++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php index 7495185..dfa0d04 100644 --- a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php +++ b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php @@ -47,6 +47,10 @@ class GitRepositoryResource extends Resource return $table ->columns([ + Tables\Columns\TextColumn::make('id') + ->label('#') + ->sortable(), + Tables\Columns\TextColumn::make('domain.domain'), // Tables\Columns\TextColumn::make('name') diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php index 2c8b3a5..8e17b14 100644 --- a/web/app/Models/GitRepository.php +++ b/web/app/Models/GitRepository.php @@ -148,8 +148,11 @@ class GitRepository extends Model $cloneUrl = 'git@'.$gitSSHUrl['provider'].':'.$gitSSHUrl['owner'].'/'.$gitSSHUrl['name'].'.git'; - $shellFile = '/tmp/git-pull-' . $this->id . '.sh'; - $shellLog = '/tmp/git-pull-' . $this->id . '.log'; + $shellFile = $findDomain->domain_root . '/git/tmp/git-pull-' . $this->id . '.sh'; + $shellLog = $findDomain->domain_root . '/git/tmp/git-pull-' . $this->id . '.log'; + + shell_exec('mkdir -p ' . dirname($shellFile)); + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' -R ' . dirname(dirname($shellFile))); $shellContent = view('actions.git.pull-repo', [ 'gitProvider' => $gitSSHUrl['provider'], @@ -158,12 +161,15 @@ class GitRepository extends Model 'cloneUrl' => $cloneUrl, 'projectDir' => $projectDir, 'privateKeyFile' => $privateKeyFile, + 'selfFile' => $shellFile, ])->render(); file_put_contents($shellFile, $shellContent); shell_exec('chmod +x ' . $shellFile); - shell_exec('bash '.$shellFile.' >> ' . $shellLog . ' &'); + shell_exec('chown '.$findHostingSubscription->system_username.':'.$findHostingSubscription->system_username.' ' . $shellFile); + + shell_exec('su -m ' . $findHostingSubscription->system_username . ' -c "bash '.$shellFile.' >> ' . $shellLog . ' &"'); } diff --git a/web/resources/views/actions/git/pull-repo.blade.php b/web/resources/views/actions/git/pull-repo.blade.php index d69ab02..f296106 100644 --- a/web/resources/views/actions/git/pull-repo.blade.php +++ b/web/resources/views/actions/git/pull-repo.blade.php @@ -1,6 +1,6 @@ echo "Pull started at {{ date('Y-m-d H:i:s') }}" -su -m {{$systemUsername}} -c "export HOME=/home/{{$systemUsername}}" +cd {{$projectDir}} @if($privateKeyFile) @@ -8,15 +8,12 @@ ssh-keyscan {{$gitProvider}} >> /home/{{$systemUsername}}/.ssh/known_hosts chmod 0600 /home/{{$systemUsername}}/.ssh/known_hosts chown {{$systemUsername}}:{{$systemUsername}} /home/{{$systemUsername}}/.ssh/known_hosts -su -m {{$systemUsername}} -c 'cd {{$projectDir}} && git -c core.sshCommand="ssh -i {{$privateKeyFile}}" pull' +git -c core.sshCommand="ssh -i {{$privateKeyFile}}" pull @else -su -m {{$systemUsername}} -c 'cd {{$projectDir}} && git pull' +git pull @endif -phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-pulled {{$gitRepositoryId}} - - -rm -rf /tmp/git-pull-{{$gitRepositoryId}}.sh +rm -rf {{$selfFile}}