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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: literal env variables
Andras Bacsai5b36f0749354
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex d4650002f4..df034a2f70 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -1129,7 +1129,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted$persistent_storages = $this->generate_local_persistent_volumes();$volume_names = $this->generate_local_persistent_volumes_only_volume_names();$environment_variables = $this->generate_environment_variables($ports);-if (data_get($this->application, 'custom_labels')) {$this->application->parseContainerLabels();$labels = collect(preg_split("/\r\n|\n|\r/", base64_decode($this->application->custom_labels)));@@ -1419,6 +1418,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted} else {$real_value = escapeEnvVariables($env->real_value);}+ if ($env->is_literal) {+ $real_value = escapeDollarSign($real_value);+ }$environment_variables->push("$env->key=$real_value");}foreach ($this->application->nixpacks_environment_variables as $env) {@@ -1427,6 +1429,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted} else {$real_value = escapeEnvVariables($env->real_value);}+ if ($env->is_literal) {+ $real_value = escapeDollarSign($real_value);+ }$environment_variables->push("$env->key=$real_value");}} else {@@ -1436,6 +1441,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted} else {$real_value = escapeEnvVariables($env->real_value);}+ if ($env->is_literal) {+ $real_value = escapeDollarSign($real_value);+ }$environment_variables->push("$env->key=$real_value");}foreach ($this->application->nixpacks_environment_variables_preview as $env) {@@ -1444,6 +1452,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted} else {$real_value = escapeEnvVariables($env->real_value);}+ if ($env->is_literal) {+ $real_value = escapeDollarSign($real_value);+ }$environment_variables->push("$env->key=$real_value");}}diff --git a/app/Livewire/Project/Edit.php b/app/Livewire/Project/Edit.phpindex 17cb6902be..d222917a66 100644--- a/app/Livewire/Project/Edit.php+++ b/app/Livewire/Project/Edit.php@@ -25,6 +25,7 @@ class Edit extends Component'key' => $data['key'],'value' => $data['value'],'is_multiline' => $data['is_multiline'],+ 'is_literal' => $data['is_literal'],'type' => 'project','team_id' => currentTeam()->id,]);diff --git a/app/Livewire/Project/EnvironmentEdit.php b/app/Livewire/Project/EnvironmentEdit.phpindex c5e4ccf117..173d946f3e 100644--- a/app/Livewire/Project/EnvironmentEdit.php+++ b/app/Livewire/Project/EnvironmentEdit.php@@ -29,6 +29,7 @@ class EnvironmentEdit extends Component'key' => $data['key'],'value' => $data['value'],'is_multiline' => $data['is_multiline'],+ 'is_literal' => $data['is_literal'],'type' => 'environment','team_id' => currentTeam()->id,]);diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Livewire/Project/Shared/EnvironmentVariable/Add.phpindex c042429631..df808ba52f 100644--- a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php@@ -7,11 +7,13 @@ use Livewire\Component;class Add extends Component{public $parameters;+ public bool $shared = false;public bool $is_preview = false;public string $key;public ?string $value = null;public bool $is_build_time = false;public bool $is_multiline = false;+ public bool $is_literal = false;protected $listeners = ['clearAddEnv' => 'clear'];protected $rules = [@@ -19,12 +21,14 @@ class Add extends Component'value' => 'nullable','is_build_time' => 'required|boolean','is_multiline' => 'required|boolean',+ 'is_literal' => 'required|boolean',];protected $validationAttributes = ['key' => 'key','value' => 'value','is_build_time' => 'build','is_multiline' => 'multiline',+ 'is_literal' => 'literal',];public function mount()@@ -47,6 +51,7 @@ class Add extends Component'value' => $this->value,'is_build_time' => $this->is_build_time,'is_multiline' => $this->is_multiline,+ 'is_literal' => $this->is_literal,'is_preview' => $this->is_preview,]);$this->clear();@@ -58,5 +63,6 @@ class Add extends Component$this->value = '';$this->is_build_time = false;$this->is_multiline = false;+ $this->is_literal = false;}}diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.phpindex 7903e8e516..a9854c196d 100644--- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php@@ -22,6 +22,7 @@ class Show extends Component'env.value' => 'nullable','env.is_build_time' => 'required|boolean','env.is_multiline' => 'required|boolean',+ 'env.is_literal' => 'required|boolean','env.is_shown_once' => 'required|boolean','env.real_value' => 'nullable',];@@ -30,6 +31,7 @@ class Show extends Component'env.value' => 'Value','env.is_build_time' => 'Build Time','env.is_multiline' => 'Multiline',+ 'env.is_literal' => 'Literal','env.is_shown_once' => 'Shown Once',];@@ -41,6 +43,7 @@ class Show extends Component$this->modalId = new Cuid2(7);$this->parameters = get_route_parameters();$this->checkEnvs();+ ray($this->env);}public function checkEnvs(){diff --git a/app/Livewire/TeamSharedVariablesIndex.php b/app/Livewire/TeamSharedVariablesIndex.phpindex dbb64ab65b..eeee30ab93 100644--- a/app/Livewire/TeamSharedVariablesIndex.php+++ b/app/Livewire/TeamSharedVariablesIndex.php@@ -21,6 +21,7 @@ class TeamSharedVariablesIndex extends Component'key' => $data['key'],'value' => $data['value'],'is_multiline' => $data['is_multiline'],+ 'is_literal' => $data['is_literal'],'type' => 'team','team_id' => currentTeam()->id,]);diff --git a/app/Models/SharedEnvironmentVariable.php b/app/Models/SharedEnvironmentVariable.phpindex 260f16afbd..5fad8fd96c 100644--- a/app/Models/SharedEnvironmentVariable.php+++ b/app/Models/SharedEnvironmentVariable.php@@ -2,6 +2,7 @@namespace App\Models;+use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Model;class SharedEnvironmentVariable extends Modeldiff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex afcc4622b3..14ea491eeb 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -586,3 +586,9 @@ function escapeEnvVariables($value)$replace = array("\\\\", "\\r", "\\t", "\\0", '\"', "\'");return str_replace($search, $replace, $value);}+function escapeDollarSign($value)+{+ $search = array('$');+ $replace = array('$$');+ return str_replace($search, $replace, $value);+}diff --git a/database/migrations/2024_04_15_094703_add_literal_variables.php b/database/migrations/2024_04_15_094703_add_literal_variables.phpnew file mode 100644index 0000000000..c03194975c--- /dev/null+++ b/database/migrations/2024_04_15_094703_add_literal_variables.php@@ -0,0 +1,34 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('environment_variables', function (Blueprint $table) {+ $table->boolean('is_literal')->default(false);+ });+ Schema::table('shared_environment_variables', function (Blueprint $table) {+ $table->boolean('is_literal')->default(false);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('environment_variables', function (Blueprint $table) {+ $table->dropColumn('is_literal');+ });+ Schema::table('shared_environment_variables', function (Blueprint $table) {+ $table->dropColumn('is_literal');+ });+ }+};diff --git a/resources/views/livewire/project/edit.blade.php b/resources/views/livewire/project/edit.blade.phpindex c8fd27f9cc..9fd47a70a9 100644--- a/resources/views/livewire/project/edit.blade.php+++ b/resources/views/livewire/project/edit.blade.php@@ -17,7 +17,7 @@<div class="flex gap-2"><h2>Shared Variables</h2><x-modal-input buttonTitle="+ Add" title="New Shared Variable">- <livewire:project.shared.environment-variable.add />+ <livewire:project.shared.environment-variable.add :shared="true" /></x-modal-input></div><div class="pb-4 lg:flex lg:gap-1">diff --git a/resources/views/livewire/project/environment-edit.blade.php b/resources/views/livewire/project/environment-edit.blade.phpindex 02fbb1c690..23bb8748bc 100644--- a/resources/views/livewire/project/environment-edit.blade.php+++ b/resources/views/livewire/project/environment-edit.blade.php@@ -45,7 +45,7 @@<div class="flex gap-2 pt-10"><h2>Shared Variables</h2><x-modal-input buttonTitle="+ Add" title="New Shared Variable">- <livewire:project.shared.environment-variable.add />+ <livewire:project.shared.environment-variable.add :shared="true" /></x-modal-input></div><div class="flex items-center gap-2 pb-4">You can use these variables anywhere with <span class="dark:text-warning text-coollabs">@{{environment.VARIABLENAME}}</span><x-helperdiff --git a/resources/views/livewire/project/shared/environment-variable/add.blade.php b/resources/views/livewire/project/shared/environment-variable/add.blade.phpindex 271dcda03b..4f118b779d 100644--- a/resources/views/livewire/project/shared/environment-variable/add.blade.php+++ b/resources/views/livewire/project/shared/environment-variable/add.blade.php@@ -7,6 +7,11 @@<x-forms.checkbox id="is_build_time" label="Build Variable?" />@endif<x-forms.checkbox id="is_multiline" label="Is Multiline?" />+ @if (!$shared)+ <x-forms.checkbox id="is_literal"+ helper="This means that when you use $VARIABLES, it should be interpreted as the actual characters '$VARIABLES' and not as the value of a variable named VARIABLE.<br><br>Useful if you have $ sign in your value and there are some characters after it, but you would not like to interpolate it form another value. In this case, you should set this to true."+ label="Is Literal?" />+ @endif<x-forms.button type="submit" @click="slideOverOpen=false">Save</x-forms.button>diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.phpindex 68e728f7e2..fca2d2bf43 100644--- a/resources/views/livewire/project/shared/environment-variable/show.blade.php+++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php@@ -45,9 +45,19 @@@else@if ($env->is_shared)<x-forms.checkbox instantSave id="env.is_build_time" label="Build Variable?" />+ <x-forms.checkbox instantSave id="env.is_literal"+ helper="This means that when you use $VARIABLES, it should be interpreted as the actual characters '$VARIABLES' and not as the value of a variable named VARIABLE.<br><br>Useful if you have $ sign in your value and there are some characters after it, but you would not like to interpolate it form another value. In this case, you should set this to true."+ label="Is Literal?" />@else- <x-forms.checkbox instantSave id="env.is_multiline" label="Is Multiline?" />- <x-forms.checkbox instantSave id="env.is_build_time" label="Build Variable?" />+ @if ($type === 'team' || $type === 'environment' || $type === 'project')+ <x-forms.checkbox instantSave id="env.is_multiline" label="Is Multiline?" />+ @else+ <x-forms.checkbox instantSave id="env.is_build_time" label="Build Variable?" />+ <x-forms.checkbox instantSave id="env.is_multiline" label="Is Multiline?" />+ <x-forms.checkbox instantSave id="env.is_literal"+ helper="This means that when you use $VARIABLES, it should be interpreted as the actual characters '$VARIABLES' and not as the value of a variable named VARIABLE.<br><br>Useful if you have $ sign in your value and there are some characters after it, but you would not like to interpolate it form another value. In this case, you should set this to true."+ label="Is Literal?" />+ @endif@endif@endif<div class="flex-1"></div>diff --git a/resources/views/livewire/team-shared-variables-index.blade.php b/resources/views/livewire/team-shared-variables-index.blade.phpindex 9f8a709f03..4d36dc9507 100644--- a/resources/views/livewire/team-shared-variables-index.blade.php+++ b/resources/views/livewire/team-shared-variables-index.blade.php@@ -3,7 +3,7 @@<div class="flex gap-2"><h2>Shared Variables</h2><x-modal-input buttonTitle="+ Add" title="New Shared Variable">- <livewire:project.shared.environment-variable.add />+ <livewire:project.shared.environment-variable.add :shared="true" /></x-modal-input></div><div class="flex items-center gap-2 pb-4">You can use these variables anywhere with <span