fix: application view

This commit is contained in:
Andras Bacsai 2023-03-31 09:42:13 +02:00
parent 47d3ac3ef5
commit e052047b04
3 changed files with 25 additions and 24 deletions

View File

@ -21,15 +21,19 @@ class DeployApplication extends Component
{
public string $application_uuid;
public $activity;
public $status;
public Application $application;
public $destination;
protected string $deployment_uuid;
protected array $command = [];
protected Application $application;
protected $destination;
protected $source;
public function mount($application_uuid) {
public function mount($application_uuid)
{
$this->application_uuid = $application_uuid;
$this->application = Application::where('uuid', $this->application_uuid)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
}
public function render()
{
@ -152,7 +156,6 @@ private function generate_jwt_token_for_github()
public function deploy()
{
$coolify_instance_settings = CoolifyInstanceSettings::find(1);
$this->application = Application::where('uuid', $this->application_uuid)->first();
$this->destination = $this->application->destination->getMorphClass()::where('id', $this->application->destination->id)->first();
$this->source = $this->application->source->getMorphClass()::where('id', $this->application->source->id)->first();
@ -244,26 +247,24 @@ public function deploy()
public function stop()
{
$application = Application::where('uuid', $this->application_uuid)->first();
$destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first();
$command[] = "docker rm -f {$application->uuid} >/dev/null 2>&1";
remoteProcess($command, $destination->server, null, $application);
$output = runRemoteCommandSync($this->destination->server, ["docker rm -f {$this->application_uuid} >/dev/null 2>&1"]);
$this->application->status = 'exited';
$this->application->save();
// $this->application->refresh();
}
public function checkStatus() {
$application = Application::where('uuid', $this->application_uuid)->first();
$destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first();
$private_key_location = savePrivateKey($destination->server);
$ssh_command = generateSshCommand($private_key_location, $destination->server->ip, $destination->server->user, $destination->server->port, "docker ps -a --format '{{.State}}' --filter 'name={$application->uuid}'");
$process = Process::run($ssh_command);
$output = trim($process->output());
public function pollingStatus()
{
$this->application->refresh();
}
public function checkStatus()
{
$output = runRemoteCommandSync($this->destination->server, ["docker ps -a --format '{{.State}}' --filter 'name={$this->application->uuid}'"]);
if ($output == '') {
$application->status = 'exited';
$application->save();
$this->application->status = 'exited';
$this->application->save();
} else {
$application->status = $output;
$application->save();
$this->application->status = $output;
$this->application->save();
}
// ContainerStatusJob::dispatch();
}
}

View File

@ -2,4 +2,5 @@
<button wire:click='deploy'>Deploy</button>
<button wire:click='stop'>Stop</button>
<button wire:click='checkStatus'>CheckStatus</button>
<span wire:poll='pollingStatus'>status: {{ $application->status }}</span>
</div>

View File

@ -1,15 +1,14 @@
<x-layout>
<h1>Application</h1>
<p>Name: {{ $application->name }}</p>
<p>Application UUID: {{ $application->uuid }}</p>
<p>Status: {{ $application->status }}</p>
<livewire:deploy-application :application_uuid="$application->uuid" />
<div>
<h1>Deployments</h1>
<h2>Deployments</h2>
@foreach ($deployments as $deployment)
<p>
<a href="{{ url()->current() }}/deployment/{{ data_get($deployment->properties, 'deployment_uuid') }}">
{{ data_get($deployment->properties, 'deployment_uuid') }}</a>
{{ data_get($deployment->properties, 'status') }}
</p>
@endforeach
</div>