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: variabel sync and support shared vars
peaklabs-dev6f97d589aee4
diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.phpindex 56be36202f..3705ce9380 100644--- a/app/Actions/Database/StartRedis.php+++ b/app/Actions/Database/StartRedis.php@@ -159,33 +159,28 @@ class StartRedisprivate function generate_environment_variables(){$environment_variables = collect();- $redis_password = null;- $redis_username = null;foreach ($this->database->runtime_environment_variables as $env) {- $environment_variables->push("$env->key=$env->real_value");+ if ($env->is_shared) {+ $environment_variables->push("$env->key=$env->real_value");- if ($env->key === 'REDIS_PASSWORD') {- $redis_password = $env->real_value;- }+ if ($env->key === 'REDIS_PASSWORD') {+ $this->database->update(['redis_password' => $env->real_value]);+ }- if ($env->key === 'REDIS_USERNAME') {- $redis_username = $env->real_value;+ if ($env->key === 'REDIS_USERNAME') {+ $this->database->update(['redis_username' => $env->real_value]);+ }+ } else {+ if ($env->key === 'REDIS_PASSWORD') {+ $env->update(['value' => $this->database->redis_password]);+ } elseif ($env->key === 'REDIS_USERNAME') {+ $env->update(['value' => $this->database->redis_username]);+ }+ $environment_variables->push("$env->key=$env->real_value");}}- if (is_null($redis_password)) {- $environment_variables->push("REDIS_PASSWORD={$this->database->redis_password}");- } else {- $this->database->update(['redis_password' => $redis_password]);- }-- if (is_null($redis_username)) {- $environment_variables->push("REDIS_USERNAME={$this->database->redis_username}");- } else {- $this->database->update(['redis_username' => $redis_username]);- }-add_coolify_default_environment_variables($this->database, $environment_variables, $environment_variables);return $environment_variables->all();diff --git a/app/Livewire/Project/Database/Redis/General.php b/app/Livewire/Project/Database/Redis/General.phpindex b5b459acb4..ab9b0756d4 100644--- a/app/Livewire/Project/Database/Redis/General.php+++ b/app/Livewire/Project/Database/Redis/General.php@@ -80,14 +80,12 @@ class General extends Component$redis_version = $this->get_redis_version();- if (version_compare($redis_version, '6.0', '>=')) {- if ($this->database->isDirty('redis_username')) {- $this->database->redis_username = $this->database->redis_username;- }+ if (version_compare($redis_version, '6.0', '>=') && $this->database->isDirty('redis_username')) {+ $this->updateEnvironmentVariable('REDIS_USERNAME', $this->database->redis_username);}if ($this->database->isDirty('redis_password')) {- $this->database->redis_password = $this->database->redis_password;+ $this->updateEnvironmentVariable('REDIS_PASSWORD', $this->database->redis_password);}$this->database->save();@@ -101,6 +99,7 @@ class General extends Componentprivate function get_redis_version(){$image_parts = explode(':', $this->database->image);+return $image_parts[1] ?? '0.0';}@@ -144,4 +143,23 @@ class General extends Component{return view('livewire.project.database.redis.general');}-}\ No newline at end of file++ private function updateEnvironmentVariable($key, $value)+ {+ $envVar = $this->database->runtime_environment_variables()+ ->where('key', $key)+ ->first();++ if ($envVar) {+ if (! $envVar->is_shared) {+ $envVar->update(['value' => $value]);+ }+ } else {+ $this->database->runtime_environment_variables()->create([+ 'key' => $key,+ 'value' => $value,+ 'is_shared' => false,+ ]);+ }+ }+}diff --git a/bootstrap/helpers/databases.php b/bootstrap/helpers/databases.phpindex 950eb67b6e..d77327c8f3 100644--- a/bootstrap/helpers/databases.php+++ b/bootstrap/helpers/databases.php@@ -1,5 +1,6 @@<?php+use App\Models\EnvironmentVariable;use App\Models\Server;use App\Models\StandaloneClickhouse;use App\Models\StandaloneDocker;@@ -49,6 +50,7 @@ function create_standalone_redis($environment_id, $destination_uuid, ?array $oth$database = new StandaloneRedis;$database->name = generate_database_name('redis');$database->redis_password = \Illuminate\Support\Str::password(length: 64, symbols: false);+ $database->redis_username = 'default';$database->environment_id = $environment_id;$database->destination_id = $destination->id;$database->destination_type = $destination->getMorphClass();@@ -57,6 +59,20 @@ function create_standalone_redis($environment_id, $destination_uuid, ?array $oth}$database->save();+ EnvironmentVariable::create([+ 'key' => 'REDIS_PASSWORD',+ 'value' => $database->redis_password,+ 'standalone_redis_id' => $database->id,+ 'is_shared' => false,+ ]);++ EnvironmentVariable::create([+ 'key' => 'REDIS_USERNAME',+ 'value' => $database->redis_username,+ 'standalone_redis_id' => $database->id,+ 'is_shared' => false,+ ]);+return $database;}