2023-05-30 13:52:17 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Application;
|
2023-05-30 13:52:17 +00:00
|
|
|
|
2023-06-30 13:57:40 +00:00
|
|
|
use App\Enums\ApplicationDeploymentStatus;
|
2023-05-30 13:52:17 +00:00
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\ApplicationDeploymentQueue;
|
2023-07-04 12:29:52 +00:00
|
|
|
use App\Models\Server;
|
2023-06-30 19:22:14 +00:00
|
|
|
use Illuminate\Support\Carbon;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\Component;
|
2023-05-30 13:52:17 +00:00
|
|
|
|
2023-05-31 10:38:36 +00:00
|
|
|
class DeploymentNavbar extends Component
|
2023-05-30 13:52:17 +00:00
|
|
|
{
|
2023-06-30 13:57:40 +00:00
|
|
|
public ApplicationDeploymentQueue $application_deployment_queue;
|
2023-07-06 06:27:22 +00:00
|
|
|
public Application $application;
|
|
|
|
public Server $server;
|
2023-07-04 10:38:22 +00:00
|
|
|
public bool $is_debug_enabled = false;
|
2023-12-04 19:47:32 +00:00
|
|
|
protected $listeners = ['deploymentFinished'];
|
2023-07-04 12:29:52 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->application = Application::find($this->application_deployment_queue->application_id);
|
|
|
|
$this->server = $this->application->destination->server;
|
|
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-31 12:42:37 +00:00
|
|
|
public function deploymentFinished()
|
|
|
|
{
|
2023-06-30 13:57:40 +00:00
|
|
|
$this->application_deployment_queue->refresh();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-30 13:57:40 +00:00
|
|
|
public function show_debug()
|
|
|
|
{
|
2023-07-04 12:29:52 +00:00
|
|
|
$this->application->settings->is_debug_enabled = !$this->application->settings->is_debug_enabled;
|
|
|
|
$this->application->settings->save();
|
|
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('refreshQueue');
|
2023-05-31 12:42:37 +00:00
|
|
|
}
|
2024-02-05 13:40:54 +00:00
|
|
|
public function force_start()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
force_start_deployment($this->application_deployment_queue);
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
ray($e);
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
2023-05-30 13:52:17 +00:00
|
|
|
public function cancel()
|
|
|
|
{
|
|
|
|
try {
|
2024-01-25 10:57:47 +00:00
|
|
|
$kill_command = "docker rm -f {$this->application_deployment_queue->deployment_uuid}";
|
2024-02-07 13:55:06 +00:00
|
|
|
$server_id = $this->application_deployment_queue->server_id ?? $this->application->destination->server_id;
|
|
|
|
$server = Server::find($server_id);
|
2024-01-25 12:45:17 +00:00
|
|
|
if ($this->application_deployment_queue->logs) {
|
|
|
|
$previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR);
|
2024-01-25 10:57:47 +00:00
|
|
|
|
2024-01-25 12:45:17 +00:00
|
|
|
$new_log_entry = [
|
|
|
|
'command' => $kill_command,
|
|
|
|
'output' => "Deployment cancelled by user.",
|
|
|
|
'type' => 'stderr',
|
|
|
|
'order' => count($previous_logs) + 1,
|
|
|
|
'timestamp' => Carbon::now('UTC'),
|
|
|
|
'hidden' => false,
|
|
|
|
];
|
|
|
|
$previous_logs[] = $new_log_entry;
|
|
|
|
$this->application_deployment_queue->update([
|
|
|
|
'logs' => json_encode($previous_logs, flags: JSON_THROW_ON_ERROR),
|
|
|
|
]);
|
|
|
|
}
|
2024-02-07 13:55:06 +00:00
|
|
|
instant_remote_process([$kill_command], $server);
|
2023-06-09 13:55:21 +00:00
|
|
|
} catch (\Throwable $e) {
|
2024-01-25 12:45:17 +00:00
|
|
|
ray($e);
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-10-17 09:10:33 +00:00
|
|
|
} finally {
|
|
|
|
$this->application_deployment_queue->update([
|
|
|
|
'current_process_id' => null,
|
|
|
|
'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
|
|
|
|
]);
|
2023-05-30 13:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|