An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: cancelling a deployment will check if new could be started.
Andras Bacsaif332a7312288
diff --git a/app/Livewire/Project/Application/DeploymentNavbar.php b/app/Livewire/Project/Application/DeploymentNavbar.phpindex cbbe98d998..b3e39d23de 100644--- a/app/Livewire/Project/Application/DeploymentNavbar.php+++ b/app/Livewire/Project/Application/DeploymentNavbar.php@@ -54,9 +54,9 @@ class DeploymentNavbar extends Componentpublic function cancel(){+ $kill_command = "docker rm -f {$this->application_deployment_queue->deployment_uuid}";+ $server_id = $this->application_deployment_queue->server_id ?? $this->application->destination->server_id;try {- $kill_command = "docker rm -f {$this->application_deployment_queue->deployment_uuid}";- $server_id = $this->application_deployment_queue->server_id ?? $this->application->destination->server_id;$server = Server::find($server_id);if ($this->application_deployment_queue->logs) {$previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR);@@ -84,6 +84,7 @@ class DeploymentNavbar extends Component'current_process_id' => null,'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,]);+ next_after_cancel($server);}}}diff --git a/app/Models/Application.php b/app/Models/Application.phpindex bebf7c61c8..532fc5d4ad 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -531,7 +531,7 @@ class Application extends BaseModelpublic function get_last_successful_deployment(){- return ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', 'finished')->where('pull_request_id', 0)->orderBy('created_at', 'desc')->first();+ return ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', ApplicationDeploymentStatus::FINISHED)->where('pull_request_id', 0)->orderBy('created_at', 'desc')->first();}public function get_last_days_deployments()diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.phpindex 376b0f2aa7..8bfa4eac17 100644--- a/bootstrap/helpers/applications.php+++ b/bootstrap/helpers/applications.php@@ -11,7 +11,7 @@ use Spatie\Url\Url;function queue_application_deployment(Application $application, string $deployment_uuid, ?int $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false, bool $restart_only = false, ?string $git_type = null, bool $no_questions_asked = false, ?Server $server = null, ?StandaloneDocker $destination = null, bool $only_this_server = false, bool $rollback = false){$application_id = $application->id;- $deployment_link = Url::fromString($application->link()."/deployment/{$deployment_uuid}");+ $deployment_link = Url::fromString($application->link() . "/deployment/{$deployment_uuid}");$deployment_url = $deployment_link->getPath();$server_id = $application->destination->server->id;$server_name = $application->destination->server->name;@@ -65,7 +65,7 @@ function force_start_deployment(ApplicationDeploymentQueue $deployment)function queue_next_deployment(Application $application){$server_id = $application->destination->server_id;- $next_found = ApplicationDeploymentQueue::where('server_id', $server_id)->where('status', 'queued')->get()->sortBy('created_at')->first();+ $next_found = ApplicationDeploymentQueue::where('server_id', $server_id)->where('status', ApplicationDeploymentStatus::QUEUED)->get()->sortBy('created_at')->first();if ($next_found) {$next_found->update(['status' => ApplicationDeploymentStatus::IN_PROGRESS->value,@@ -79,7 +79,7 @@ function queue_next_deployment(Application $application)function next_queuable(string $server_id, string $application_id): bool{- $deployments = ApplicationDeploymentQueue::where('server_id', $server_id)->whereIn('status', ['in_progress', 'queued'])->get()->sortByDesc('created_at');+ $deployments = ApplicationDeploymentQueue::where('server_id', $server_id)->whereIn('status', ['in_progress', ApplicationDeploymentStatus::QUEUED])->get()->sortByDesc('created_at');$same_application_deployments = $deployments->where('application_id', $application_id);$in_progress = $same_application_deployments->filter(function ($value, $key) {return $value->status === 'in_progress';@@ -98,3 +98,26 @@ function next_queuable(string $server_id, string $application_id): boolreturn true;}+function next_after_cancel(?Server $server = null)+{+ if ($server) {+ $next_found = ApplicationDeploymentQueue::where('server_id', data_get($server, 'id'))->where('status', ApplicationDeploymentStatus::QUEUED)->get()->sortBy('created_at');+ if ($next_found->count() > 0) {+ foreach ($next_found as $next) {+ $server = Server::find($next->server_id);+ $concurrent_builds = $server->settings->concurrent_builds;+ $inprogress_deployments = ApplicationDeploymentQueue::where('server_id', $next->server_id)->whereIn('status', [ApplicationDeploymentStatus::QUEUED])->get()->sortByDesc('created_at');+ if ($inprogress_deployments->count() < $concurrent_builds) {+ $next->update([+ 'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,+ ]);++ dispatch(new ApplicationDeploymentJob(+ application_deployment_queue_id: $next->id,+ ));+ }+ break;+ }+ }+ }+}