From 561e424a7dc9e65b5f568566ee81ec14e1a9f132 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sat, 27 Jan 2024 18:44:40 +0100 Subject: [PATCH] feat: dashboard live deployment view --- app/Livewire/Dashboard.php | 19 ++++++- app/Livewire/Project/Application/Heading.php | 12 ++--- app/Livewire/Project/Application/Previews.php | 3 +- app/Livewire/Project/Application/Rollback.php | 3 +- bootstrap/helpers/applications.php | 11 +++- ...ation_name_and_deployment_url_to_queue.php | 32 +++++++++++ resources/css/app.css | 2 +- resources/views/layouts/app.blade.php | 2 +- resources/views/livewire/dashboard.blade.php | 54 +++++++++++++++---- routes/api.php | 3 +- routes/webhooks.php | 18 +++---- 11 files changed, 118 insertions(+), 41 deletions(-) create mode 100644 database/migrations/2024_01_27_164724_add_application_name_and_deployment_url_to_queue.php diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index 51d964a29..a4bcbe8f6 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -2,18 +2,35 @@ namespace App\Livewire; +use App\Models\ApplicationDeploymentQueue; use App\Models\Project; use App\Models\Server; +use Illuminate\Support\Collection; use Livewire\Component; class Dashboard extends Component { public $projects = []; - public $servers = []; + public Collection $servers; + public Collection $deployments_per_server; public function mount() { $this->servers = Server::ownedByCurrentTeam()->get(); $this->projects = Project::ownedByCurrentTeam()->get(); + $this->get_deployments(); + } + public function get_deployments() + { + $this->deployments_per_server = ApplicationDeploymentQueue::whereIn("status", ["in_progress", "queued"])->whereIn("server_id", $this->servers->pluck("id"))->get([ + "id", + "application_id", + "application_name", + "deployment_url", + "pull_request_id", + "server_name", + "server_id", + "status" + ])->sortBy('id'); } // public function getIptables() // { diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php index fd01790c3..afac72d85 100644 --- a/app/Livewire/Project/Application/Heading.php +++ b/app/Livewire/Project/Application/Heading.php @@ -54,8 +54,7 @@ public function deployNew() } $this->setDeploymentUuid(); queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $this->deploymentUuid, force_rebuild: false, is_new_deployment: true, @@ -83,8 +82,7 @@ public function deploy(bool $force_rebuild = false) } $this->setDeploymentUuid(); queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $this->deploymentUuid, force_rebuild: $force_rebuild, ); @@ -113,8 +111,7 @@ public function restartNew() { $this->setDeploymentUuid(); queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $this->deploymentUuid, restart_only: true, is_new_deployment: true, @@ -130,8 +127,7 @@ public function restart() { $this->setDeploymentUuid(); queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $this->deploymentUuid, restart_only: true, ); diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.php index bd5206100..d057479ea 100644 --- a/app/Livewire/Project/Application/Previews.php +++ b/app/Livewire/Project/Application/Previews.php @@ -47,8 +47,7 @@ public function deploy(int $pull_request_id, string|null $pull_request_html_url ]); } queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $this->deployment_uuid, force_rebuild: false, pull_request_id: $pull_request_id, diff --git a/app/Livewire/Project/Application/Rollback.php b/app/Livewire/Project/Application/Rollback.php index 042812760..7bd2d069b 100644 --- a/app/Livewire/Project/Application/Rollback.php +++ b/app/Livewire/Project/Application/Rollback.php @@ -24,8 +24,7 @@ public function rollbackImage($commit) $deployment_uuid = new Cuid2(7); queue_application_deployment( - application_id: $this->application->id, - server_id: $this->application->destination->server->id, + application: $this->application, deployment_uuid: $deployment_uuid, commit: $commit, force_rebuild: false, diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index fd3abad48..079c1add8 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -6,14 +6,23 @@ use App\Models\ApplicationDeploymentQueue; use App\Models\ApplicationPreview; use App\Models\Server; +use Spatie\Url\Url; 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) +function queue_application_deployment(Application $application, 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) { + $application_id = $application->id; + $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; $deployment = ApplicationDeploymentQueue::create([ 'application_id' => $application_id, + 'application_name' => $application->name, 'server_id' => $server_id, + 'server_name' => $server_name, 'deployment_uuid' => $deployment_uuid, + 'deployment_url' => $deployment_url, 'pull_request_id' => $pull_request_id, 'force_rebuild' => $force_rebuild, 'is_webhook' => $is_webhook, diff --git a/database/migrations/2024_01_27_164724_add_application_name_and_deployment_url_to_queue.php b/database/migrations/2024_01_27_164724_add_application_name_and_deployment_url_to_queue.php new file mode 100644 index 000000000..9d4f24a32 --- /dev/null +++ b/database/migrations/2024_01_27_164724_add_application_name_and_deployment_url_to_queue.php @@ -0,0 +1,32 @@ +string('application_name')->nullable(); + $table->string('server_name')->nullable(); + $table->string('deployment_url')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('application_deployment_queues', function (Blueprint $table) { + $table->dropColumn('application_name'); + $table->dropColumn('server_name'); + $table->dropColumn('deployment_url'); + }); + } +}; diff --git a/resources/css/app.css b/resources/css/app.css index 5778b9529..38a452d85 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -19,7 +19,7 @@ .scrollbar { } .main { - @apply pt-4 pl-24 pr-10 mx-auto; + @apply pt-4 pl-24 pr-10 lg:pr-32 lg:pl-44; } .custom-modal { diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index ee2101449..a5fd6d0e6 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -11,7 +11,7 @@ @auth @endauth -
+
{{ $slot }}
@endsection diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index 022a58ff2..29efd46d9 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -11,7 +11,8 @@ - Your subscription has been activated! Welcome onboard!
It could take a few seconds before your subscription is activated.
Please be patient.
+ Your subscription has been activated! Welcome onboard!
It could take a few seconds before your + subscription is activated.
Please be patient.
@endif @if ($projects->count() === 0 && $servers->count() === 0) @@ -29,14 +30,14 @@ @foreach ($projects as $project)
@if (data_get($project, 'environments.0.name')) -
{{ $project->name }}
{{ $project->description }}
@else -
{{ $project->name }}
@@ -44,11 +45,11 @@ @endif
- + New Resource - @endif @foreach ($servers as $server) - $server->settings->is_reachable, - 'border-red-500' => !$server->settings->is_reachable, - ])> + $server->settings->is_reachable, + 'border-red-500' => !$server->settings->is_reachable, + ])>