mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Closes #9408 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.2 KiB
PHP
96 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project\Application;
|
|
|
|
use App\Actions\Application\CleanupCancelledDeployment;
|
|
use App\Enums\ApplicationDeploymentStatus;
|
|
use App\Models\Application;
|
|
use App\Models\ApplicationDeploymentQueue;
|
|
use App\Models\Server;
|
|
use App\Traits\AuditsApplicationSettings;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Component;
|
|
|
|
class DeploymentNavbar extends Component
|
|
{
|
|
use AuditsApplicationSettings, AuthorizesRequests;
|
|
|
|
public ApplicationDeploymentQueue $application_deployment_queue;
|
|
|
|
public Application $application;
|
|
|
|
public Server $server;
|
|
|
|
public bool $is_debug_enabled = false;
|
|
|
|
protected $listeners = ['deploymentFinished'];
|
|
|
|
public function mount()
|
|
{
|
|
$this->application = Application::ownedByCurrentTeam()->find($this->application_deployment_queue->application_id);
|
|
$this->server = $this->application->destination->server;
|
|
$this->is_debug_enabled = auth()->user()->isMember()
|
|
? false
|
|
: $this->application->settings->is_debug_enabled;
|
|
}
|
|
|
|
public function deploymentFinished()
|
|
{
|
|
$this->application_deployment_queue->refresh();
|
|
}
|
|
|
|
public function show_debug()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->application);
|
|
$this->application->settings->is_debug_enabled = ! $this->application->settings->is_debug_enabled;
|
|
$this->saveApplicationSettingsWithAudit($this->application);
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
|
$this->dispatch('refreshQueue');
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function force_start()
|
|
{
|
|
try {
|
|
$this->authorize('deploy', $this->application);
|
|
$started = force_start_deployment($this->application_deployment_queue);
|
|
$this->application_deployment_queue->refresh();
|
|
|
|
if (! $started) {
|
|
$this->dispatch('info', 'This deployment is no longer queued, so it was not started again.');
|
|
}
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function cancel()
|
|
{
|
|
try {
|
|
$this->authorize('deploy', $this->application);
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
$teamId = $this->application->team()->id;
|
|
$server_id = $this->application_deployment_queue->server_id ?? $this->application->destination->server_id;
|
|
$server = Server::where('team_id', $teamId)->find($server_id);
|
|
|
|
// First, mark the deployment as cancelled to prevent further processing
|
|
$this->application_deployment_queue->update([
|
|
'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
|
|
]);
|
|
try {
|
|
$this->application_deployment_queue->addLogEntry('Deployment cancelled by user.', 'stderr');
|
|
CleanupCancelledDeployment::run($this->application_deployment_queue, $teamId);
|
|
} catch (\Throwable $e) {
|
|
// Still mark as cancelled even if cleanup fails
|
|
return handleError($e, $this);
|
|
} finally {
|
|
next_after_cancel($server, $this->application);
|
|
}
|
|
}
|
|
}
|