feat: variabel sync and support shared vars
This commit is contained in:
parent
b9c9c1041a
commit
6f97d589ae
3 changed files with 56 additions and 27 deletions
|
|
@ -159,31 +159,26 @@ private function generate_local_persistent_volumes_only_volume_names()
|
|||
private 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') {
|
||||
$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 ($env->key === 'REDIS_USERNAME') {
|
||||
$redis_username = $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);
|
||||
|
|
|
|||
|
|
@ -80,14 +80,12 @@ public function submit()
|
|||
|
||||
$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 @@ public function submit()
|
|||
private function get_redis_version()
|
||||
{
|
||||
$image_parts = explode(':', $this->database->image);
|
||||
|
||||
return $image_parts[1] ?? '0.0';
|
||||
}
|
||||
|
||||
|
|
@ -144,4 +143,23 @@ public function render()
|
|||
{
|
||||
return view('livewire.project.database.redis.general');
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue