a ton 👷‍♂️

This commit is contained in:
Andras Bacsai
2023-05-24 14:26:50 +02:00
parent 8677b1d85d
commit 6e7ee0ca48
67 changed files with 754 additions and 992 deletions

View File

@@ -12,7 +12,7 @@ class Danger extends Component
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
}
public function delete()
{

View File

@@ -2,10 +2,8 @@
namespace App\Http\Livewire\Project\Application;
use App\Jobs\ContainerStatusJob;
use App\Jobs\DeployApplicationJob;
use App\Jobs\ContainerStopJob;
use App\Models\Application;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@@ -24,52 +22,37 @@ class Deploy extends Component
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
$this->application = Application::where('id', $this->applicationId)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
// dispatch(new ContainerStatusJob($this->application->uuid));
}
protected function setDeploymentUuid()
protected function set_deployment_uuid()
{
// Create Deployment ID
$this->deployment_uuid = new Cuid2(7);
$this->parameters['deployment_uuid'] = $this->deployment_uuid;
}
protected function redirectToDeployment()
public function deploy(bool $force = false)
{
return redirect()->route('project.application.deployment', $this->parameters);
}
public function start()
{
$this->setDeploymentUuid();
$this->set_deployment_uuid();
dispatch(new DeployApplicationJob(
deployment_uuid: $this->deployment_uuid,
application_uuid: $this->application->uuid,
force_rebuild: false,
));
return $this->redirectToDeployment();
}
public function forceRebuild()
{
$this->setDeploymentUuid();
dispatch(new DeployApplicationJob(
deployment_uuid: $this->deployment_uuid,
application_uuid: $this->application->uuid,
force_rebuild: true,
));
return $this->redirectToDeployment();
queue_application_deployment(
application: $this->application,
metadata: [
'deployment_uuid' => $this->deployment_uuid,
'application_uuid' => $this->application->uuid,
'force_rebuild' => $force,
]
);
return redirect()->route('project.application.deployments', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'environment_name' => $this->parameters['environment_name'],
]);
}
public function stop()
{
instantRemoteProcess(["docker rm -f {$this->application->uuid}"], $this->destination->server);
if ($this->application->status != 'exited') {
$this->application->status = 'exited';
$this->application->save();
}
dispatch(new ContainerStopJob($this->application->id, $this->destination->server));
}
}

View File

@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Redis;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
class PollDeployment extends Component
class DeploymentLogs extends Component
{
public $activity;
public $isKeepAliveOn = true;

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Livewire\Project\Application;
use App\Models\Application;
use Livewire\Component;
class Deployments extends Component
{
public int $application_id;
public $deployments = [];
public string $current_url;
public function mount()
{
$this->current_url = url()->current();
}
public function reloadDeployments()
{
$this->loadDeployments();
}
public function loadDeployments()
{
$this->deployments = Application::find($this->application_id)->deployments();
}
}

View File

@@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
}
public function submit()
{

View File

@@ -26,7 +26,7 @@ class All extends Component
$this->application->refresh();
$this->emit('clearAddEnv');
} catch (\Exception $e) {
return generalErrorHandler($e, $this);
return general_error_handler($e, $this);
}
}
}

View File

@@ -17,7 +17,7 @@ class Show extends Component
];
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
}
public function submit()
{

View File

@@ -112,7 +112,7 @@ class General extends Component
$this->application->fqdn = $domains->implode(',');
$this->application->save();
} catch (\Exception $e) {
return generalErrorHandler($e, $this);
return general_error_handler($e, $this);
}
}
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Http\Livewire\Project\Application;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
class GetDeployments extends Component
{
public string $deployment_uuid;
public string $created_at;
public string $status;
public function polling()
{
$activity = Activity::where('properties->type_uuid', '=', $this->deployment_uuid)->first();
$this->created_at = $activity->created_at;
$this->status = data_get($activity, 'properties.status');
}
}

View File

@@ -45,7 +45,7 @@ class ResourceLimits extends Component
$this->validate();
$this->application->save();
} catch (\Exception $e) {
return generalErrorHandler($e, $this);
return general_error_handler($e, $this);
}
}
}

View File

@@ -2,8 +2,6 @@
namespace App\Http\Livewire\Project\Application;
use App\Jobs\DeployApplicationJob;
use App\Jobs\RollbackApplicationJob;
use App\Models\Application;
use Livewire\Component;
use Illuminate\Support\Str;
@@ -18,20 +16,27 @@ class Rollback extends Component
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
}
public function rollbackImage($tag)
{
$deployment_uuid = new Cuid2(7);
dispatch(new RollbackApplicationJob(
deployment_uuid: $deployment_uuid,
application_uuid: $this->application->uuid,
commit: $tag,
));
queue_application_deployment(
application: $this->application,
metadata: [
'deployment_uuid' => $deployment_uuid,
'application_uuid' => $this->application->uuid,
'force_rebuild' => false,
'commit' => $tag,
]
);
$this->parameters['deployment_uuid'] = $deployment_uuid;
return redirect()->route('project.application.deployment', $this->parameters);
return redirect()->route('project.application.deployments', [
'project_uuid' => $this->parameters['project_uuid'],
'application_uuid' => $this->parameters['application_uuid'],
'environment_name' => $this->parameters['environment_name'],
]);
}
public function loadImages()
{
@@ -51,7 +56,7 @@ class Rollback extends Component
})->map(function ($item) {
$item = Str::of($item)->explode('#');
if ($item[1] === $this->current) {
$is_current = true;
// $is_current = true;
}
return [
'tag' => $item[1],
@@ -60,7 +65,7 @@ class Rollback extends Component
];
})->toArray();
} catch (\Throwable $e) {
return generalErrorHandler($e, $this);
return general_error_handler($e, $this);
}
}
}

View File

@@ -8,6 +8,7 @@ use Livewire\Component;
class Status extends Component
{
public Application $application;
public function pollingStatus()
{
$this->application->refresh();

View File

@@ -23,7 +23,7 @@ class Add extends Component
];
public function mount()
{
$this->parameters = getParameters();
$this->parameters = get_parameters();
}
public function submit()
{

View File

@@ -27,7 +27,7 @@ class All extends Component
$this->application->refresh();
$this->emit('clearAddStorage');
} catch (\Exception $e) {
return generalErrorHandler($e, $this);
return general_error_handler($e, $this);
}
}
}