From 12ef88b90f7ed395d37efac99a235af8be420375 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 30 Mar 2023 20:19:11 +0200 Subject: [PATCH] wip --- app/Console/Kernel.php | 2 ++ app/Http/Controllers/ProjectController.php | 10 ++++++++- app/Http/Livewire/DeployApplication.php | 22 ++++++++++++++----- app/Jobs/ContainerStatusJob.php | 4 ++-- .../livewire/deploy-application.blade.php | 3 ++- .../views/livewire/poll-activity.blade.php | 2 +- routes/web.php | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e6b9960ec..c38638275 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,7 @@ namespace App\Console; +use App\Jobs\ContainerStatusJob; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -12,6 +13,7 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule): void { + $schedule->job(new ContainerStatusJob)->everyMinute(); // $schedule->command('inspire')->hourly(); } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index dbca37172..f9bc0e8bb 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -50,7 +50,15 @@ public function deployment() { $deployment_uuid = request()->route('deployment_uuid'); - $application = Application::where('uuid', request()->route('application_uuid'))->first(); + $project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); + if (!$project) { + return redirect()->route('home'); + } + $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']); + if (!$environment) { + return redirect()->route('home'); + } + $application = $environment->applications->where('uuid', request()->route('application_uuid'))->first(); if (!$application) { return redirect()->route('home'); } diff --git a/app/Http/Livewire/DeployApplication.php b/app/Http/Livewire/DeployApplication.php index 5891743c3..fac2c305c 100644 --- a/app/Http/Livewire/DeployApplication.php +++ b/app/Http/Livewire/DeployApplication.php @@ -27,6 +27,13 @@ class DeployApplication extends Component protected $destination; protected $source; + public function mount($application_uuid) { + $this->application_uuid = $application_uuid; + } + public function render() + { + return view('livewire.deploy-application'); + } private function execute_in_builder(string $command) { if ($this->application->settings->is_debug) { @@ -46,7 +53,6 @@ private function generate_docker_compose() 'services' => [ $this->application->uuid => [ 'image' => "{$this->application->uuid}:TAG", - 'expose' => $this->application->ports_exposes, 'container_name' => $this->application->uuid, 'restart' => 'always', 'labels' => $this->set_labels_for_applications(), @@ -234,12 +240,16 @@ public function deploy() $deploymentUrl = "$currentUrl/deployment/$this->deployment_uuid"; return redirect($deploymentUrl); } - public function cancel() + + public function stop() { + $application = Application::where('uuid', $this->application_uuid)->first(); + $destination = $application->destination->getMorphClass()::where('id', $application->destination->id)->first(); + $command[] = "docker rm -f {$application->uuid} >/dev/null 2>&1"; + remoteProcess($command, $destination->server, null, $application); + } + public function checkStatus() { ContainerStatusJob::dispatch(); } - public function render() - { - return view('livewire.deploy-application'); - } + } diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 6ece825ea..d5516cdaa 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -46,13 +46,13 @@ public function handle(): void }); $found_application->status = $container['State']; $found_application->save(); - Log::info('Found application: ' . $found_application->uuid . ' settings status to: ' . $found_application->status); + // Log::info('Found application: ' . $found_application->uuid . ' settings status to: ' . $found_application->status); } } foreach ($not_found_applications as $not_found_application) { $not_found_application->status = 'exited'; $not_found_application->save(); - Log::info('Not found application: ' . $not_found_application->uuid . ' settings status to: ' . $not_found_application->status); + // Log::info('Not found application: ' . $not_found_application->uuid . ' settings status to: ' . $not_found_application->status); } } catch (\Exception $e) { Log::error($e->getMessage()); diff --git a/resources/views/livewire/deploy-application.blade.php b/resources/views/livewire/deploy-application.blade.php index 27d01c442..78ae2df99 100644 --- a/resources/views/livewire/deploy-application.blade.php +++ b/resources/views/livewire/deploy-application.blade.php @@ -1,4 +1,5 @@
- + +
diff --git a/resources/views/livewire/poll-activity.blade.php b/resources/views/livewire/poll-activity.blade.php index fc3eeed34..8c69b96de 100644 --- a/resources/views/livewire/poll-activity.blade.php +++ b/resources/views/livewire/poll-activity.blade.php @@ -1,5 +1,5 @@
@isset($activity?->id) -
{{ data_get($activity, 'description') }}
+
{{ data_get($activity, 'description') ?? 'Logs will be here soon...' }}
@endisset
diff --git a/routes/web.php b/routes/web.php index 17e02d287..c2ce8690b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,7 +24,7 @@ Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources'); Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application'); - // Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment'); + Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment'); // Route::get('/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database'); // Route::get('//service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');