From 7a7157c155282ca1408a2bef2f4bc9df86018dbd Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 25 Jan 2024 11:57:47 +0100 Subject: [PATCH] fix: deployment queue fix: cancel deployment ui: changed to simpler toaster --- app/Jobs/ApplicationDeploymentJob.php | 2 +- .../Project/Application/DeploymentNavbar.php | 38 +- app/Livewire/Server/Form.php | 2 +- bootstrap/helpers/applications.php | 10 +- composer.json | 1 - composer.lock | 73 +-- resources/js/app.js | 1 - resources/views/components/toast.blade.php | 439 ++++++++++++++++++ resources/views/layouts/base.blade.php | 38 +- .../views/livewire/server/form.blade.php | 8 +- 10 files changed, 499 insertions(+), 113 deletions(-) create mode 100644 resources/views/components/toast.blade.php diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index a8a94351e..0de41f32a 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -381,7 +381,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } private function just_restart() { - $this->application_deployment_queue->addLogEntry("Starting deployment of {$this->customRepository}:{$this->application->git_branch}.'"); + $this->application_deployment_queue->addLogEntry("Starting deployment of {$this->customRepository}:{$this->application->git_branch}."); $this->prepare_builder_image(); $this->check_git_if_build_needed(); $this->set_base_dir(); diff --git a/app/Livewire/Project/Application/DeploymentNavbar.php b/app/Livewire/Project/Application/DeploymentNavbar.php index aa5ea3a2d..39dee287c 100644 --- a/app/Livewire/Project/Application/DeploymentNavbar.php +++ b/app/Livewire/Project/Application/DeploymentNavbar.php @@ -41,26 +41,22 @@ class DeploymentNavbar extends Component public function cancel() { try { - $kill_command = "kill -9 {$this->application_deployment_queue->current_process_id}"; - 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([$this->server->ip, 'EOF-COOLIFY-SSH'])) { - Process::run($kill_command); - } - $previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR); - $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), - ]); - } + $kill_command = "docker rm -f {$this->application_deployment_queue->deployment_uuid}"; + $previous_logs = json_decode($this->application_deployment_queue->logs, associative: true, flags: JSON_THROW_ON_ERROR); + + $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), + ]); + instant_remote_process([$kill_command], $this->server); } catch (\Throwable $e) { return handleError($e, $this); } finally { @@ -68,7 +64,7 @@ class DeploymentNavbar extends Component 'current_process_id' => null, 'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value, ]); - queue_next_deployment($this->application); + // queue_next_deployment($this->application); } } } diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php index df92ffaa4..8ec31a228 100644 --- a/app/Livewire/Server/Form.php +++ b/app/Livewire/Server/Form.php @@ -27,7 +27,7 @@ class Form extends Component 'server.settings.is_swarm_manager' => 'required|boolean', 'server.settings.is_swarm_worker' => 'required|boolean', 'server.settings.is_build_server' => 'required|boolean', - 'server.settings.concurrent_builds' => 'required|integer', + 'server.settings.concurrent_builds' => 'required|integer|min:1', 'wildcard_domain' => 'nullable|url', ]; protected $validationAttributes = [ diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index 884173ab3..44060421a 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -10,6 +10,9 @@ use Symfony\Component\Yaml\Yaml; function queue_application_deployment(int $application_id, int $server_id, string $deployment_uuid, int | null $pull_request_id = 0, string $commit = 'HEAD', bool $force_rebuild = false, bool $is_webhook = false, bool $restart_only = false, ?string $git_type = null, bool $is_new_deployment = false) { + $server = Application::find($application_id)->destination->server; + $deployments_per_server = ApplicationDeploymentQueue::where('server_id', $server_id)->where('status', 'queued')->orWhere('status', 'in_progress')->get(); + $deployment = ApplicationDeploymentQueue::create([ 'application_id' => $application_id, 'server_id' => $server_id, @@ -21,14 +24,12 @@ function queue_application_deployment(int $application_id, int $server_id, strin 'commit' => $commit, 'git_type' => $git_type ]); - $server = Application::find($application_id)->destination->server; $deployments = ApplicationDeploymentQueue::where('application_id', $application_id); $queued_deployments = $deployments->where('status', 'queued')->get()->sortByDesc('created_at'); $running_deployments = $deployments->where('status', 'in_progress')->get()->sortByDesc('created_at'); - $deployments_per_server = ApplicationDeploymentQueue::where('server_id', $server_id)->where('status', 'queued')->orWhere('status', 'in_progress')->get(); - + ray($deployments_per_server->count(), $server->settings->concurrent_builds); ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '| Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild); if ($queued_deployments->count() > 1) { @@ -58,8 +59,7 @@ function queue_application_deployment(int $application_id, int $server_id, strin function queue_next_deployment(Application $application, bool $isNew = false) { - $next_found = ApplicationDeploymentQueue::where('status', 'queued')->get()->sortByDesc('created_at')->first(); - ray('Next found: ' . $next_found); + $next_found = ApplicationDeploymentQueue::where('status', 'queued')->get()->sortBy('created_at')->first(); if ($next_found) { if ($isNew) { dispatch(new ApplicationDeploymentNewJob( diff --git a/composer.json b/composer.json index e9cf53d10..f762ed579 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,6 @@ "league/flysystem-sftp-v3": "^3.0", "livewire/livewire": "^3.0", "lorisleiva/laravel-actions": "^2.7", - "masmerise/livewire-toaster": "^2.0", "nubs/random-name-generator": "^2.2", "phpseclib/phpseclib": "~3.0", "poliander/cron": "^3.0", diff --git a/composer.lock b/composer.lock index ea7e31647..8dfa5e556 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de3b59fade9b132d2582a40dcf3c00f9", + "content-hash": "19b19082b605e09867e6ae65fb8135f6", "packages": [ { "name": "amphp/amp", @@ -4485,77 +4485,6 @@ ], "time": "2023-02-05T15:03:45+00:00" }, - { - "name": "masmerise/livewire-toaster", - "version": "2.0.3", - "source": { - "type": "git", - "url": "https://github.com/masmerise/livewire-toaster.git", - "reference": "89aa127df5d17b915b0818761bdf83e8915036c2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/masmerise/livewire-toaster/zipball/89aa127df5d17b915b0818761bdf83e8915036c2", - "reference": "89aa127df5d17b915b0818761bdf83e8915036c2", - "shasum": "" - }, - "require": { - "laravel/framework": "^10.0", - "livewire/livewire": "^3.0", - "php": "~8.2" - }, - "conflict": { - "stevebauman/unfinalize": "*" - }, - "require-dev": { - "dive-be/php-crowbar": "^1.0", - "laravel/pint": "^1.0", - "nunomaduro/larastan": "^2.0", - "orchestra/testbench": "^8.0", - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "laravel": { - "aliases": { - "Toaster": "Masmerise\\Toaster\\Toaster" - }, - "providers": [ - "Masmerise\\Toaster\\ToasterServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "Masmerise\\Toaster\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Muhammed Sari", - "email": "support@muhammedsari.me", - "role": "Developer" - } - ], - "description": "Beautiful toast notifications for Laravel / Livewire.", - "homepage": "https://github.com/masmerise/livewire-toaster", - "keywords": [ - "alert", - "laravel", - "livewire", - "toast", - "toaster" - ], - "support": { - "issues": "https://github.com/masmerise/livewire-toaster/issues", - "source": "https://github.com/masmerise/livewire-toaster/tree/2.0.3" - }, - "time": "2023-09-28T12:07:49+00:00" - }, { "name": "monolog/monolog", "version": "3.5.0", diff --git a/resources/js/app.js b/resources/js/app.js index 526e9403e..a49c95e97 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,6 +1,5 @@ import { createApp } from "vue"; import MagicBar from "./components/MagicBar.vue"; -import '../../vendor/masmerise/livewire-toaster/resources/js'; import "../../vendor/wire-elements/modal/resources/js/modal"; const app = createApp({}); diff --git a/resources/views/components/toast.blade.php b/resources/views/components/toast.blade.php new file mode 100644 index 000000000..aa2eefcf3 --- /dev/null +++ b/resources/views/components/toast.blade.php @@ -0,0 +1,439 @@ +
+ +
diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 664ec7568..8154b7828 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -42,7 +42,7 @@ - +