This commit is contained in:
Andras Bacsai
2023-06-30 15:57:40 +02:00
parent b370826624
commit 55d5b1e8da
13 changed files with 560 additions and 75 deletions

View File

@@ -61,16 +61,16 @@ class ApplicationController extends Controller
if (!$application) {
return redirect()->route('dashboard');
}
$activity = Activity::where('properties->type_uuid', '=', $deploymentUuid)->first();
if (!$activity) {
return redirect()->route('project.application.deployments', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
'application_uuid' => $application->uuid,
]);
}
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (!$deployment) {
// $activity = Activity::where('properties->type_uuid', '=', $deploymentUuid)->first();
// if (!$activity) {
// return redirect()->route('project.application.deployments', [
// 'project_uuid' => $project->uuid,
// 'environment_name' => $environment->name,
// 'application_uuid' => $application->uuid,
// ]);
// }
$application_deployment_queue = ApplicationDeploymentQueue::where('deployment_uuid', $deploymentUuid)->first();
if (!$application_deployment_queue) {
return redirect()->route('project.application.deployments', [
'project_uuid' => $project->uuid,
'environment_name' => $environment->name,
@@ -79,8 +79,8 @@ class ApplicationController extends Controller
}
return view('project.application.deployment', [
'application' => $application,
'activity' => $activity,
'deployment' => $deployment,
// 'activity' => $activity,
'application_deployment_queue' => $application_deployment_queue,
'deployment_uuid' => $deploymentUuid,
]);
}

View File

@@ -2,31 +2,23 @@
namespace App\Http\Livewire\Project\Application;
use App\Enums\ActivityTypes;
use App\Models\Application;
use Illuminate\Support\Facades\Redis;
use App\Models\ApplicationDeploymentQueue;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
class DeploymentLogs extends Component
{
public Application $application;
public $activity;
public ApplicationDeploymentQueue $application_deployment_queue;
public $isKeepAliveOn = true;
public $deployment_uuid;
protected $listeners = ['refreshQueue'];
public function refreshQueue()
{
$this->application_deployment_queue->refresh();
}
public function polling()
{
$this->emit('deploymentFinished');
if (is_null($this->activity) && isset($this->deployment_uuid)) {
$this->activity = Activity::query()
->where('properties->type', '=', ActivityTypes::DEPLOYMENT->value)
->where('properties->type_uuid', '=', $this->deployment_uuid)
->first();
} else {
$this->activity?->refresh();
}
if (data_get($this->activity, 'properties.status') == 'finished' || data_get($this->activity, 'properties.status') == 'failed') {
$this->application_deployment_queue->refresh();
if (data_get($this->application_deployment_queue, 'status') == 'finished' || data_get($this->application_deployment_queue, 'status') == 'failed') {
$this->isKeepAliveOn = false;
}
}

View File

@@ -2,41 +2,46 @@
namespace App\Http\Livewire\Project\Application;
use App\Enums\ProcessStatus;
use App\Enums\ApplicationDeploymentStatus;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
use Illuminate\Support\Str;
class DeploymentNavbar extends Component
{
public Application $application;
public $activity;
public string $deployment_uuid;
protected $listeners = ['deploymentFinished'];
public ApplicationDeploymentQueue $application_deployment_queue;
public function deploymentFinished()
{
$this->activity->refresh();
$this->application_deployment_queue->refresh();
}
public function show_debug()
{
$application = Application::find($this->application_deployment_queue->application_id);
$application->settings->is_debug_enabled = !$application->settings->is_debug_enabled;
$application->settings->save();
$this->emit('refreshQueue');
}
public function cancel()
{
try {
ray('Cancelling deployment: ' . $this->deployment_uuid . ' of application: ' . $this->application->uuid);
// Update deployment queue
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $this->deployment_uuid)->first();
$deployment->status = 'cancelled by user';
$deployment->save();
// Update activity
$this->activity->properties = $this->activity->properties->merge([
'exitCode' => 1,
'status' => ProcessStatus::CANCELLED->value,
]);
$this->activity->save();
// Remove builder container
instant_remote_process(["docker rm -f {$this->deployment_uuid}"], $this->application->destination->server, throwError: false, repeat: 25);
queue_next_deployment($this->application);
$application = Application::find($this->application_deployment_queue->application_id);
$server = $application->destination->server;
if ($this->application_deployment_queue->current_process_id) {
$process = Process::run("ps -p {$this->application_deployment_queue->current_process_id} -o command --no-headers");
if (Str::of($process->output())->contains([$server->ip, 'EOF-COOLIFY-SSH'])) {
Process::run("kill -9 {$this->application_deployment_queue->current_process_id}");
}
// TODO: Cancelling text in logs
$this->application_deployment_queue->update([
'current_process_id' => null,
'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
]);
}
} catch (\Throwable $e) {
return general_error_handler(err: $e, that: $this);
}