From f042c70b3c34453f62aaff4097dd9ac8cb4cdac1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 15:48:51 +0100 Subject: [PATCH 1/3] fix: labelling --- app/Jobs/ApplicationDeploymentJob.php | 14 ++++++++++-- app/Livewire/Project/Application/General.php | 23 +++++++++++--------- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index cafddfa82..2f38ff2fd 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -267,7 +267,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted "ignore_errors" => true, ] ); - ApplicationStatusChanged::dispatch(data_get($this->application,'environment.project.team.id')); + ApplicationStatusChanged::dispatch(data_get($this->application, 'environment.project.team.id')); } } private function push_to_docker_registry() @@ -874,6 +874,15 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $environment_variables = $this->generate_environment_variables($ports); if (data_get($this->application, 'custom_labels')) { + if (base64_encode(base64_decode(data_get($this->application, 'custom_labels'), true)) === data_get($this->application, 'custom_labels')) { + ray('custom_labels is base64 encoded'); + } else { + ray('custom_labels is not base64 encoded'); + $this->application->custom_labels = str($this->application->custom_labels)->replace(',', "\n"); + $this->application->custom_labels = base64_encode(data_get($this->application, 'custom_labels')); + $this->application->save(); + } + $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels))); $labels = $labels->filter(function ($value, $key) { return !Str::startsWith($value, 'coolify.'); @@ -1247,7 +1256,8 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); } } - private function build_by_compose_file() { + private function build_by_compose_file() + { $this->application_deployment_queue->addLogEntry("Pulling & building required images."); if ($this->application->build_pack === 'dockerimage') { $this->application_deployment_queue->addLogEntry("Pulling latest images from the registry."); diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index 7587031fd..e6cad2eee 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -110,16 +110,18 @@ class General extends Component } $this->isConfigurationChanged = $this->application->isConfigurationChanged(); - if (base64_encode(base64_decode(data_get($this->application, 'custom_labels'), true)) === data_get($this->application, 'custom_labels')) { - ray('custom_labels is base64 encoded'); - } else { - ray('custom_labels is not base64 encoded'); - $this->application->custom_labels = str($this->application->custom_labels)->replace(',', "\n"); - $this->application->custom_labels = base64_encode(data_get($this->application, 'custom_labels')); - $this->application->save(); + if (data_get($this->application, 'custom_labels')) { + if (base64_encode(base64_decode(data_get($this->application, 'custom_labels'), true)) === data_get($this->application, 'custom_labels')) { + ray('custom_labels is base64 encoded'); + } else { + ray('custom_labels is not base64 encoded'); + $this->application->custom_labels = str($this->application->custom_labels)->replace(',', "\n"); + $this->application->custom_labels = base64_encode(data_get($this->application, 'custom_labels')); + $this->application->save(); + } + $this->customLabels = base64_decode(data_get($this->application, 'custom_labels')); } - $this->customLabels = base64_decode(data_get($this->application, 'custom_labels')); $this->initialDockerComposeLocation = $this->application->docker_compose_location; $this->checkLabelUpdates(); } @@ -242,8 +244,9 @@ class General extends Component $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains); $this->parsedServices = $this->application->parseCompose(); } - - $this->application->custom_labels = base64_encode($this->customLabels); + if ($this->customLabels) { + $this->application->custom_labels = base64_encode($this->customLabels); + } $this->application->save(); $showToaster && $this->dispatch('success', 'Application settings updated!'); } catch (\Throwable $e) { diff --git a/config/sentry.php b/config/sentry.php index bf81a36eb..076edb85e 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.160', + 'release' => '4.0.0-beta.161', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 13035a86a..8f7d7b0d4 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Tue, 12 Dec 2023 16:34:05 +0100 Subject: [PATCH 2/3] fix: non-ascii chars in labels --- app/Livewire/Project/Application/General.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index e6cad2eee..a6d82c8ef 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -120,6 +120,11 @@ class General extends Component $this->application->save(); } $this->customLabels = base64_decode(data_get($this->application, 'custom_labels')); + // Fix for non-ascii characters + if (preg_match('~[^\x20-\x7E\t\r\n]~', $this->customLabels) > 0) { + ray('custom_labels contains non-ascii characters'); + $this->resetDefaultLabels(false); + } } $this->initialDockerComposeLocation = $this->application->docker_compose_location; @@ -244,9 +249,7 @@ class General extends Component $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains); $this->parsedServices = $this->application->parseCompose(); } - if ($this->customLabels) { - $this->application->custom_labels = base64_encode($this->customLabels); - } + $this->application->custom_labels = base64_encode($this->customLabels); $this->application->save(); $showToaster && $this->dispatch('success', 'Application settings updated!'); } catch (\Throwable $e) { From d3c989447918b79a1f7f6ea1a7dfa6d8fe5d4e6d Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 12 Dec 2023 16:45:46 +0100 Subject: [PATCH 3/3] fix: labels --- app/Jobs/ApplicationDeploymentJob.php | 5 +++++ app/Livewire/Project/Application/General.php | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 2f38ff2fd..7bb0df489 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -883,6 +883,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->application->save(); } + if (mb_detect_encoding(base64_decode($this->application->custom_labels), 'ASCII', true) === false) { + ray('custom_labels contains non-ascii characters'); + $this->application->custom_labels = base64_encode(str(implode(",", generateLabelsApplication($this->application, $this->preview)))->replace(',', "\n")); + $this->application->save(); + } $labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels))); $labels = $labels->filter(function ($value, $key) { return !Str::startsWith($value, 'coolify.'); diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index a6d82c8ef..279e55651 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -120,8 +120,8 @@ class General extends Component $this->application->save(); } $this->customLabels = base64_decode(data_get($this->application, 'custom_labels')); - // Fix for non-ascii characters - if (preg_match('~[^\x20-\x7E\t\r\n]~', $this->customLabels) > 0) { + // // Fix for non-ascii characters + if (mb_detect_encoding($this->customLabels, 'ASCII', true) === false) { ray('custom_labels contains non-ascii characters'); $this->resetDefaultLabels(false); }