Skip to content

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.

refactor: custom labels

Andras Bacsaif3b04c1ef987
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 7bb0df4891..9e9725bd11 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -874,20 +874,7 @@ 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();
- }
-
- 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();
- }
+ $this->application->parseContainerLabels();
$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 279e556510..d27fcff541 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -109,24 +109,7 @@ class General extends Component
$this->application->isConfigurationChanged(true);
}
$this->isConfigurationChanged = $this->application->isConfigurationChanged();
-
- 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'));
- // // Fix for non-ascii characters
- if (mb_detect_encoding($this->customLabels, 'ASCII', true) === false) {
- ray('custom_labels contains non-ascii characters');
- $this->resetDefaultLabels(false);
- }
- }
-
+ $this->customLabels = $this->application->parseContainerLabels();
$this->initialDockerComposeLocation = $this->application->docker_compose_location;
$this->checkLabelUpdates();
}
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 10f27e2078..d56be8f0a5 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -1024,4 +1024,24 @@ class Application extends BaseModel
];
}
}
+ function parseContainerLabels(?ApplicationPreview $preview = null)
+ {
+ $customLabels = data_get($this, 'custom_labels');
+ if (!$customLabels) {
+ return;
+ }
+ if (base64_encode(base64_decode($customLabels, true)) !== $customLabels) {
+ ray('custom_labels is not base64 encoded');
+ $this->custom_labels = str($customLabels)->replace(',', "\n");
+ $this->custom_labels = base64_encode($customLabels);
+ }
+ $customLabels = base64_decode($this->custom_labels);
+ if (mb_detect_encoding($customLabels, 'ASCII', true) === false) {
+ ray('custom_labels contains non-ascii characters');
+ $customLabels = str(implode(",", generateLabelsApplication($this, $preview)))->replace(',', "\n");
+ }
+ $this->custom_labels = base64_encode($customLabels);
+ $this->save();
+ return $customLabels;
+ }
}
diff --git a/config/sentry.php b/config/sentry.php
index 076edb85e1..ca9e80d7ca 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.161',
+ 'release' => '4.0.0-beta.162',
// 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 8f7d7b0d45..bf223006f3 100644
--- a/config/version.php
+++ b/config/version.php
@@ -1,3 +1,3 @@
<?php
-return '4.0.0-beta.161';
+return '4.0.0-beta.162';
diff --git a/versions.json b/versions.json
index ea172ee96a..b594596bff 100644
--- a/versions.json
+++ b/versions.json
@@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
- "version": "4.0.0-beta.161"
+ "version": "4.0.0-beta.162"
}
}
}