lasthourcloud/app/Http/Livewire/DeployApplication.php

69 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Livewire;
2023-03-31 11:32:07 +00:00
use App\Jobs\DeployApplicationJob;
use App\Models\Application;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
class DeployApplication extends Component
{
public string $applicationId;
public $activity;
2023-03-31 07:42:13 +00:00
public $status;
public Application $application;
public $destination;
protected string $deployment_uuid;
protected array $command = [];
protected $source;
public function mount($applicationId)
2023-03-31 07:42:13 +00:00
{
$this->application = Application::find($applicationId)->first();
2023-03-31 07:42:13 +00:00
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
2023-03-30 18:19:11 +00:00
}
2023-03-31 11:32:07 +00:00
2023-03-30 18:19:11 +00:00
public function render()
{
return view('livewire.deploy-application');
}
2023-04-14 09:24:58 +00:00
public function start()
2023-03-31 11:32:07 +00:00
{
// Create Deployment ID
$this->deployment_uuid = new Cuid2(7);
2023-03-29 13:47:56 +00:00
2023-03-31 11:32:07 +00:00
dispatch(new DeployApplicationJob(
deployment_uuid: $this->deployment_uuid,
application_uuid: $this->application->uuid,
2023-03-31 11:32:07 +00:00
));
$currentUrl = url()->previous();
$deploymentUrl = "$currentUrl/deployment/$this->deployment_uuid";
return redirect($deploymentUrl);
}
2023-03-30 18:19:11 +00:00
public function stop()
2023-03-29 13:47:56 +00:00
{
2023-05-03 05:15:45 +00:00
instantRemoteProcess($this->destination->server, ["docker stop -t 0 {$this->application->uuid} >/dev/null 2>&1"]);
2023-04-14 09:24:58 +00:00
$this->application->status = 'stopped';
2023-03-31 07:42:13 +00:00
$this->application->save();
}
2023-04-14 11:18:55 +00:00
public function kill()
{
2023-05-03 05:15:45 +00:00
instantRemoteProcess($this->destination->server, ["docker rm -f {$this->application->uuid}"]);
2023-04-14 11:18:55 +00:00
if ($this->application->status != 'exited') {
$this->application->status = 'exited';
$this->application->save();
}
}
2023-03-31 11:32:07 +00:00
2023-03-31 07:42:13 +00:00
public function pollingStatus()
{
$this->application->refresh();
2023-03-29 13:47:56 +00:00
}
}