This commit is contained in:
Bozhidar 2024-09-13 15:22:53 +03:00
parent 8f2db60f28
commit e918c6457e
3 changed files with 12 additions and 6 deletions

View file

@ -33,6 +33,11 @@ class GitRepositoryResource extends Resource
->required()
->columnSpanFull(),
Forms\Components\Select::make('git_ssh_key_id')
->label('SSH Key')
->options(fn () => \App\Models\GitSshKey::pluck('name', 'id'))
->columnSpanFull(),
]);
}

View file

@ -71,10 +71,12 @@ class GitRepository extends Model
return $this->belongsTo(Domain::class);
}
private function _getSSHKey($findHostingSubscription)
private function _getSSHKey($gitSshKeyId, $findHostingSubscription)
{
$gitSSHKey = GitSshKey::where('id', $gitSshKeyId)
->where('hosting_subscription_id', $findHostingSubscription->id)
->first();
$gitSSHKey = GitSshKey::find($this->git_ssh_key_id);
if ($gitSSHKey) {
$sshPath = '/home/'.$findHostingSubscription->system_username .'/.ssh';
$privateKeyFile = $sshPath.'/id_rsa_'. $gitSSHKey->id;
@ -131,12 +133,11 @@ class GitRepository extends Model
$projectDir = $findDomain->domain_root . '/' . $this->dir;
$privateKeyFile = null;
$getSSHKey = $this->_getSSHKey($findHostingSubscription);
$getSSHKey = $this->_getSSHKey($this->git_ssh_key_id, $findHostingSubscription);
if (isset($getSSHKey['privateKeyFile'])) {
$privateKeyFile = $getSSHKey['privateKeyFile'];
}
$gitSSHUrl = GitClient::parseGitUrl($this->url);
if (!isset($gitSSHUrl['provider'])) {
$this->status = self::STATUS_FAILED;
@ -190,7 +191,7 @@ class GitRepository extends Model
$projectDir = $findDomain->domain_root . '/' . $this->dir;
$privateKeyFile = null;
$getSSHKey = $this->_getSSHKey($findHostingSubscription);
$getSSHKey = $this->_getSSHKey($this->git_ssh_key_id, $findHostingSubscription);
if (isset($getSSHKey['privateKeyFile'])) {
$privateKeyFile = $getSSHKey['privateKeyFile'];
}

View file

@ -18,4 +18,4 @@ su -m {{$systemUsername}} -c 'git clone {{$cloneUrl}} {{$projectDir}}'
phyre-php /usr/local/phyre/web/artisan git-repository:mark-as-cloned {{$gitRepositoryId}}
# rm -rf /tmp/git-clone-{{$gitRepositoryId}}.sh
rm -rf /tmp/git-clone-{{$gitRepositoryId}}.sh