Skip to content

Commit 1b4a8aa

Browse files
Merge branch 'feat/labels-by-proxy-type' of github.com:lorenzomigliorero/coolify into feat/labels-by-proxy-type
2 parents be6d74a + 5aae65f commit 1b4a8aa

File tree

10 files changed

+80
-25
lines changed

10 files changed

+80
-25
lines changed

app/Http/Controllers/Api/ApplicationsController.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,10 @@ private function create_application(Request $request, $type)
732732
$application->environment_id = $environment->id;
733733
$application->save();
734734
$application->refresh();
735-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
736-
$application->save();
735+
if (! $application->settings->is_container_label_readonly_enabled) {
736+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
737+
$application->save();
738+
}
737739
$application->isConfigurationChanged(true);
738740

739741
if ($instantDeploy) {
@@ -826,8 +828,10 @@ private function create_application(Request $request, $type)
826828
$application->source_id = $githubApp->id;
827829
$application->save();
828830
$application->refresh();
829-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
830-
$application->save();
831+
if (! $application->settings->is_container_label_readonly_enabled) {
832+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
833+
$application->save();
834+
}
831835
$application->isConfigurationChanged(true);
832836

833837
if ($instantDeploy) {
@@ -916,8 +920,10 @@ private function create_application(Request $request, $type)
916920
$application->environment_id = $environment->id;
917921
$application->save();
918922
$application->refresh();
919-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
920-
$application->save();
923+
if (! $application->settings->is_container_label_readonly_enabled) {
924+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
925+
$application->save();
926+
}
921927
$application->isConfigurationChanged(true);
922928

923929
if ($instantDeploy) {
@@ -996,8 +1002,10 @@ private function create_application(Request $request, $type)
9961002
$application->git_branch = 'main';
9971003
$application->save();
9981004
$application->refresh();
999-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1000-
$application->save();
1005+
if (! $application->settings->is_container_label_readonly_enabled) {
1006+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1007+
$application->save();
1008+
}
10011009
$application->isConfigurationChanged(true);
10021010

10031011
if ($instantDeploy) {
@@ -1052,8 +1060,10 @@ private function create_application(Request $request, $type)
10521060
$application->git_branch = 'main';
10531061
$application->save();
10541062
$application->refresh();
1055-
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1056-
$application->save();
1063+
if (! $application->settings->is_container_label_readonly_enabled) {
1064+
$application->custom_labels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1065+
$application->save();
1066+
}
10571067
$application->isConfigurationChanged(true);
10581068

10591069
if ($instantDeploy) {
@@ -1494,8 +1504,10 @@ public function update_by_uuid(Request $request)
14941504
$fqdn = str($fqdn)->replaceEnd(',', '')->trim();
14951505
$fqdn = str($fqdn)->replaceStart(',', '')->trim();
14961506
$application->fqdn = $fqdn;
1497-
$customLabels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1498-
$application->custom_labels = base64_encode($customLabels);
1507+
if (! $application->settings->is_container_label_readonly_enabled) {
1508+
$customLabels = str(implode('|coolify|', generateLabelsApplication($application)))->replace('|coolify|', "\n");
1509+
$application->custom_labels = base64_encode($customLabels);
1510+
}
14991511
$request->offsetUnset('domains');
15001512
}
15011513

app/Jobs/ApplicationDeploymentJob.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,9 @@ private function generate_compose_file()
15231523
$this->application->custom_labels = base64_encode($labels->implode("\n"));
15241524
$this->application->save();
15251525
} else {
1526-
$labels = collect(generateLabelsApplication($this->application, $this->preview));
1526+
if (! $this->application->settings->is_container_label_readonly_enabled) {
1527+
$labels = collect(generateLabelsApplication($this->application, $this->preview));
1528+
}
15271529
}
15281530
if ($this->pull_request_id !== 0) {
15291531
$labels = collect(generateLabelsApplication($this->application, $this->preview));

app/Livewire/Project/Application/General.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class General extends Component
8484
'application.settings.is_static' => 'boolean|required',
8585
'application.settings.is_build_server_enabled' => 'boolean|required',
8686
'application.settings.is_container_label_escape_enabled' => 'boolean|required',
87+
'application.settings.is_container_label_readonly_enabled' => 'boolean|required',
8788
'application.watch_paths' => 'nullable',
8889
'application.redirect' => 'string|required',
8990
];
@@ -119,6 +120,7 @@ class General extends Component
119120
'application.settings.is_static' => 'Is static',
120121
'application.settings.is_build_server_enabled' => 'Is build server enabled',
121122
'application.settings.is_container_label_escape_enabled' => 'Is container label escape enabled',
123+
'application.settings.is_container_label_readonly_enabled' => 'Is container label readonly',
122124
'application.watch_paths' => 'Watch paths',
123125
'application.redirect' => 'Redirect',
124126
];
@@ -143,7 +145,7 @@ public function mount()
143145
$this->ports_exposes = $this->application->ports_exposes;
144146
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
145147
$this->customLabels = $this->application->parseContainerLabels();
146-
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
148+
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) {
147149
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
148150
$this->application->custom_labels = base64_encode($this->customLabels);
149151
$this->application->save();
@@ -290,6 +292,9 @@ public function getWildcardDomain()
290292

291293
public function resetDefaultLabels()
292294
{
295+
if ($this->application->settings->is_container_label_readonly_enabled) {
296+
return;
297+
}
293298
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
294299
$this->ports_exposes = $this->application->ports_exposes;
295300
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
@@ -350,7 +355,7 @@ public function submit($showToaster = true)
350355
$this->checkFqdns();
351356

352357
$this->application->save();
353-
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE') {
358+
if (! $this->customLabels && $this->application->destination->server->proxyType() !== 'NONE' && ! $this->application->settings->is_container_label_readonly_enabled) {
354359
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
355360
$this->application->custom_labels = base64_encode($this->customLabels);
356361
$this->application->save();

app/Models/Service.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'destination_id' => ['type' => 'integer', 'description' => 'The unique identifier of the destination where the service is running.'],
2525
'connect_to_docker_network' => ['type' => 'boolean', 'description' => 'The flag to connect the service to the predefined Docker network.'],
2626
'is_container_label_escape_enabled' => ['type' => 'boolean', 'description' => 'The flag to enable the container label escape.'],
27+
'is_container_label_readonly_enabled' => ['type' => 'boolean', 'description' => 'The flag to enable the container label readonly.'],
2728
'config_hash' => ['type' => 'string', 'description' => 'The hash of the service configuration.'],
2829
'service_type' => ['type' => 'string', 'description' => 'The type of the service.'],
2930
'created_at' => ['type' => 'string', 'description' => 'The date and time when the service was created.'],

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// The release version of your application
99
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
10-
'release' => '4.0.0-beta.315',
10+
'release' => '4.0.0-beta.316',
1111
// When left empty or `null` the Laravel environment will be used
1212
'environment' => config('app.env'),
1313

config/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
return '4.0.0-beta.315';
3+
return '4.0.0-beta.316';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('application_settings', function (Blueprint $table) {
15+
$table->boolean('is_container_label_readonly_enabled')->default(false);
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('application_settings', function (Blueprint $table) {
25+
$table->dropColumn('is_container_label_readonly_enabled');
26+
});
27+
}
28+
};

resources/views/livewire/project/application/general.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class="underline" href="https://coolify.io/docs/knowledge-base/docker/registry"
239239
<x-forms.checkbox label="Escape special characters in labels?"
240240
helper="By default, $ (and other chars) is escaped. So if you write $ in the labels, it will be saved as $$.<br><br>If you want to use env variables inside the labels, turn this off."
241241
id="application.settings.is_container_label_escape_enabled" instantSave></x-forms.checkbox>
242+
<x-forms.checkbox label="Readonly Labels"
243+
helper="If you know what are you doing, you can enable this to edit the labels directly. Coolify won't update labels automatically. <br><br>Be careful, it could break the proxy configuration after you restart the container."
244+
id="application.settings.is_container_label_readonly_enabled" instantSave></x-forms.checkbox>
242245
</div>
243246
@endif
244247

@@ -264,10 +267,13 @@ class="underline" href="https://coolify.io/docs/knowledge-base/docker/registry"
264267

265268
<x-forms.textarea label="Container Labels" rows="15" id="customLabels"
266269
monacoEditorLanguage="ini" useMonacoEditor></x-forms.textarea>
267-
<div class="w-72">
270+
<div class="w-96">
268271
<x-forms.checkbox label="Escape special characters in labels?"
269272
helper="By default, $ (and other chars) is escaped. So if you write $ in the labels, it will be saved as $$.<br><br>If you want to use env variables inside the labels, turn this off."
270273
id="application.settings.is_container_label_escape_enabled" instantSave></x-forms.checkbox>
274+
<x-forms.checkbox label="Readonly Labels"
275+
helper="If you know what are you doing, you can enable this to edit the labels directly. Coolify won't update labels automatically. <br><br>Be careful, it could break the proxy configuration after you restart the container."
276+
id="application.settings.is_container_label_readonly_enabled" instantSave></x-forms.checkbox>
271277
</div>
272278
<x-modal-confirmation buttonFullWidth action="resetDefaultLabels"
273279
buttonTitle="Reset to Coolify Generated Labels">

resources/views/livewire/project/service/edit-compose.blade.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
prevent
44
name collision. <br>To see the actual volume names, check the Deployable Compose file, or go to Storage
55
menu.</div>
6-
<div class="pb-2 w-72">
7-
<x-forms.checkbox label="Escape special characters in labels?"
8-
helper="By default, $ (and other chars) is escaped. So if you write $ in the labels, it will be saved as $$.<br><br>If you want to use env variables inside the labels, turn this off."
9-
id="service.is_container_label_escape_enabled" instantSave></x-forms.checkbox>
10-
</div>
6+
117
<div x-cloak x-show="raw" class="font-mono">
128
<x-forms.textarea allowTab useMonacoEditor monacoEditorLanguage="yaml" rows="20"
139
id="service.docker_compose_raw">
@@ -17,6 +13,11 @@
1713
<x-forms.textarea rows="20" readonly id="service.docker_compose">
1814
</x-forms.textarea>
1915
</div>
16+
<div class="pt-2 w-72">
17+
<x-forms.checkbox label="Escape special characters in labels?"
18+
helper="By default, $ (and other chars) is escaped. So if you write $ in the labels, it will be saved as $$.<br><br>If you want to use env variables inside the labels, turn this off."
19+
id="service.is_container_label_escape_enabled" instantSave></x-forms.checkbox>
20+
</div>
2021
<div class="flex justify-end w-full gap-2 pt-4">
2122
<div class="flex items-end gap-2">
2223
<div x-cloak x-show="raw">

versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"coolify": {
33
"v4": {
4-
"version": "4.0.0-beta.315"
4+
"version": "4.0.0-beta.316"
55
}
66
}
7-
}
7+
}

0 commit comments

Comments
 (0)