refactoring

This commit is contained in:
Saeed Vaziry
2023-08-04 18:28:04 +02:00
parent 8444323cf4
commit 643318fcfc
349 changed files with 3189 additions and 2729 deletions

View File

@ -4,7 +4,7 @@
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\CloneRepositoryCommand;
use App\SSHCommands\Website\CloneRepositoryCommand;
use Throwable;
class CloneRepository extends Job
@ -25,7 +25,8 @@ public function handle(): void
new CloneRepositoryCommand(
$this->site->full_repository_url,
$this->site->path,
$this->site->branch
$this->site->branch,
$this->site->ssh_key_name
),
'clone-repository',
$this->site->id

View File

@ -5,7 +5,7 @@
use App\Exceptions\ComposerInstallFailed;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\ComposerInstallCommand;
use App\SSHCommands\Website\ComposerInstallCommand;
use Throwable;
class ComposerInstall extends Job

View File

@ -7,7 +7,7 @@
use App\Helpers\SSH;
use App\Jobs\Job;
use App\Models\Deployment;
use App\SSHCommands\RunScript;
use App\SSHCommands\System\RunScript;
use Throwable;
class Deploy extends Job

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\EditFileCommand;
use App\SSHCommands\System\EditFileCommand;
use Throwable;
class DeployEnv extends Job

42
app/Jobs/Site/DeployKey.php Executable file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\System\GenerateSshKeyCommand;
use App\SSHCommands\System\ReadSshKeyCommand;
use Throwable;
class DeployKey extends Job
{
protected Site $site;
public function __construct(Site $site)
{
$this->site = $site;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$this->site->server->ssh()->exec(
new GenerateSshKeyCommand($this->site->ssh_key_name),
'generate-ssh-key',
$this->site->id
);
$this->site->ssh_key = $this->site->server->ssh()->exec(
new ReadSshKeyCommand($this->site->ssh_key_name),
'read-public-key',
$this->site->id
);
$this->site->save();
$this->site->sourceControl()->provider()->deployKey(
$this->site->domain.'-key-' . $this->site->id,
$this->site->repository,
$this->site->ssh_key
);
}
}

View File

@ -7,7 +7,7 @@
use App\Models\Database;
use App\Models\DatabaseUser;
use App\Models\Site;
use App\SSHCommands\InstallWordpressCommand;
use App\SSHCommands\Wordpress\InstallWordpressCommand;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Throwable;

View File

@ -5,7 +5,7 @@
use App\Events\Broadcast;
use App\Jobs\Job;
use App\Models\Site;
use App\SSHCommands\UpdateBranchCommand;
use App\SSHCommands\Website\UpdateBranchCommand;
use Throwable;
class UpdateBranch extends Job

View File

@ -1,41 +0,0 @@
<?php
namespace App\Jobs\Site;
use App\Jobs\Job;
use App\Models\Site;
use App\Models\SourceControl;
use Throwable;
class UpdateSourceControlsRemote extends Job
{
protected SourceControl $sourceControl;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(SourceControl $sourceControl)
{
$this->sourceControl = $sourceControl;
}
/**
* Execute the job.
*
* @throws Throwable
*/
public function handle(): void
{
$sites = Site::query()
->where('user_id', $this->sourceControl->user_id)
->where('source_control', $this->sourceControl->provider)
->get();
foreach ($sites as $site) {
$site->server->ssh()->exec(
'cd '.$site->path.' && git remote set-url origin '.$site->full_repository_url
);
}
}
}