From e052047b04691ae6c167df39f9d29df0e9f2a619 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 31 Mar 2023 09:42:13 +0200 Subject: [PATCH] fix: application view --- app/Http/Livewire/DeployApplication.php | 43 ++++++++++--------- .../livewire/deploy-application.blade.php | 1 + resources/views/project/application.blade.php | 5 +-- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/app/Http/Livewire/DeployApplication.php b/app/Http/Livewire/DeployApplication.php index 82fccd9ad..14401a1fc 100644 --- a/app/Http/Livewire/DeployApplication.php +++ b/app/Http/Livewire/DeployApplication.php @@ -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 @@ class DeployApplication extends Component 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 @@ class DeployApplication extends Component 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(); } - } diff --git a/resources/views/livewire/deploy-application.blade.php b/resources/views/livewire/deploy-application.blade.php index 78ae2df99..21ba7248e 100644 --- a/resources/views/livewire/deploy-application.blade.php +++ b/resources/views/livewire/deploy-application.blade.php @@ -2,4 +2,5 @@ + status: {{ $application->status }} diff --git a/resources/views/project/application.blade.php b/resources/views/project/application.blade.php index 4a87abef2..716fb3765 100644 --- a/resources/views/project/application.blade.php +++ b/resources/views/project/application.blade.php @@ -1,15 +1,14 @@

Application

Name: {{ $application->name }}

-

Application UUID: {{ $application->uuid }}

-

Status: {{ $application->status }}

-

Deployments

+

Deployments

@foreach ($deployments as $deployment)

{{ data_get($deployment->properties, 'deployment_uuid') }} + {{ data_get($deployment->properties, 'status') }}

@endforeach