mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
@ -2,19 +2,9 @@
|
||||
|
||||
namespace App\ServerTypes;
|
||||
|
||||
use App\Facades\Notifier;
|
||||
use App\Jobs\Installation\Initialize;
|
||||
use App\Jobs\Installation\InstallRequirements;
|
||||
use App\Jobs\Installation\Upgrade;
|
||||
use App\Notifications\ServerInstallationFailed;
|
||||
use App\Notifications\ServerInstallationSucceed;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class Database extends AbstractType
|
||||
{
|
||||
public function createValidationRules(array $input): array
|
||||
public function createRules(array $input): array
|
||||
{
|
||||
return [
|
||||
'database' => [
|
||||
@ -32,99 +22,9 @@ public function data(array $input): array
|
||||
public function createServices(array $input): void
|
||||
{
|
||||
$this->server->services()->forceDelete();
|
||||
|
||||
$this->addDatabase($input['database']);
|
||||
$this->addSupervisor();
|
||||
$this->addRedis();
|
||||
$this->addUfw();
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$jobs = [
|
||||
new Initialize($this->server, $this->server->ssh_user, $this->server->provider === 'custom'),
|
||||
$this->progress(15, 'Installing Updates'),
|
||||
new Upgrade($this->server),
|
||||
$this->progress(25, 'Installing Requirements'),
|
||||
new InstallRequirements($this->server),
|
||||
];
|
||||
|
||||
$services = $this->server->services;
|
||||
$currentProgress = 25;
|
||||
$progressPerService = (100 - $currentProgress) / count($services);
|
||||
foreach ($services as $service) {
|
||||
$currentProgress += $progressPerService;
|
||||
$jobs[] = $this->progress($currentProgress, 'Installing '.$service->name);
|
||||
$jobs[] = $service->installer();
|
||||
}
|
||||
|
||||
$jobs[] = function () {
|
||||
$this->server->update([
|
||||
'status' => 'ready',
|
||||
'progress' => 100,
|
||||
]);
|
||||
Notifier::send($this->server, new ServerInstallationSucceed($this->server));
|
||||
};
|
||||
|
||||
Bus::chain($jobs)
|
||||
->catch(function (Throwable $e) {
|
||||
$this->server->update([
|
||||
'status' => 'installation_failed',
|
||||
]);
|
||||
Notifier::send($this->server, new ServerInstallationFailed($this->server));
|
||||
Log::error('server-installation-error', [
|
||||
'error' => (string) $e,
|
||||
]);
|
||||
throw $e;
|
||||
})
|
||||
->onConnection('ssh-long')
|
||||
->dispatch();
|
||||
}
|
||||
|
||||
protected function addDatabase(string $service): void
|
||||
{
|
||||
if ($service != 'none') {
|
||||
$this->server->services()->create([
|
||||
'type' => 'database',
|
||||
'name' => config('core.databases_name.'.$service),
|
||||
'version' => config('core.databases_version.'.$service),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add supervisor
|
||||
*/
|
||||
protected function addSupervisor(): void
|
||||
{
|
||||
$this->server->services()->create([
|
||||
'type' => 'process_manager',
|
||||
'name' => 'supervisor',
|
||||
'version' => 'latest',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* add supervisor
|
||||
*/
|
||||
protected function addRedis(): void
|
||||
{
|
||||
$this->server->services()->create([
|
||||
'type' => 'memory_database',
|
||||
'name' => 'redis',
|
||||
'version' => 'latest',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* add supervisor
|
||||
*/
|
||||
protected function addUfw(): void
|
||||
{
|
||||
$this->server->services()->create([
|
||||
'type' => 'firewall',
|
||||
'name' => 'ufw',
|
||||
'version' => 'latest',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user