From 8f9949160c208ef658dadae34a065f445d2eb667 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 12 Oct 2023 17:29:29 +0200 Subject: [PATCH] feat: add custom redis conf --- app/Actions/Database/StartRedis.php | 37 +++++++++++++------ .../Project/Database/Redis/General.php | 7 +++- .../project/database/redis/general.blade.php | 1 + 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index 575240869..fe02b113e 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -20,6 +20,9 @@ class StartRedis public function handle(Server $server, StandaloneRedis $database) { $this->database = $database; + + $startCommand = "redis-server --requirepass {$this->database->redis_password} --appendonly yes"; + $container_name = $this->database->uuid; $this->configuration_dir = database_configuration_dir() . '/' . $container_name; @@ -31,12 +34,14 @@ class StartRedis $persistent_storages = $this->generate_local_persistent_volumes(); $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); $environment_variables = $this->generate_environment_variables(); + $this->add_custom_redis(); + $docker_compose = [ 'version' => '3.8', 'services' => [ $container_name => [ 'image' => $this->database->image, - 'command' => "redis-server --requirepass {$this->database->redis_password} --appendonly yes", + 'command' => $startCommand, 'container_name' => $container_name, 'environment' => $environment_variables, 'restart' => RESTART_MODE, @@ -80,16 +85,15 @@ class StartRedis if (count($volume_names) > 0) { $docker_compose['volumes'] = $volume_names; } - // if (count($this->init_scripts) > 0) { - // foreach ($this->init_scripts as $init_script) { - // $docker_compose['services'][$container_name]['volumes'][] = [ - // 'type' => 'bind', - // 'source' => $init_script, - // 'target' => '/docker-entrypoint-initdb.d/' . basename($init_script), - // 'read_only' => true, - // ]; - // } - // } + if (!is_null($this->database->redis_conf)) { + $docker_compose['services'][$container_name]['volumes'][] = [ + 'type' => 'bind', + 'source' => $this->configuration_dir . '/redis.conf', + 'target' => '/usr/local/etc/redis/redis.conf', + 'read_only' => true, + ]; + $docker_compose['services'][$container_name]['command'] = $startCommand . ' /usr/local/etc/redis/redis.conf'; + } $docker_compose = Yaml::dump($docker_compose, 10); $docker_compose_base64 = base64_encode($docker_compose); $this->commands[] = "echo '{$docker_compose_base64}' | base64 -d > $this->configuration_dir/docker-compose.yml"; @@ -141,4 +145,15 @@ class StartRedis return $environment_variables->all(); } + private function add_custom_redis() + { + if (is_null($this->database->redis_conf)) { + return; + } + $filename = 'redis.conf'; + $content = $this->database->redis_conf; + $content_base64 = base64_encode($content); + $this->commands[] = "echo '{$content_base64}' | base64 -d > $this->configuration_dir/{$filename}"; + + } } diff --git a/app/Http/Livewire/Project/Database/Redis/General.php b/app/Http/Livewire/Project/Database/Redis/General.php index 446d720c0..c8e15062a 100644 --- a/app/Http/Livewire/Project/Database/Redis/General.php +++ b/app/Http/Livewire/Project/Database/Redis/General.php @@ -16,6 +16,7 @@ class General extends Component protected $rules = [ 'database.name' => 'required', 'database.description' => 'nullable', + 'database.redis_conf' => 'nullable', 'database.redis_password' => 'required', 'database.image' => 'required', 'database.ports_mappings' => 'nullable', @@ -25,7 +26,8 @@ class General extends Component protected $validationAttributes = [ 'database.name' => 'Name', 'database.description' => 'Description', - 'database.redis_password' => 'Postgres User', + 'database.redis_conf' => 'Redis Configuration', + 'database.redis_password' => 'Redis Password', 'database.image' => 'Image', 'database.ports_mappings' => 'Port Mapping', 'database.is_public' => 'Is Public', @@ -34,6 +36,9 @@ class General extends Component public function submit() { try { $this->validate(); + if ($this->database->redis_conf === "") { + $this->database->redis_conf = null; + } $this->database->save(); $this->emit('success', 'Database updated successfully.'); } catch (Exception $e) { diff --git a/resources/views/livewire/project/database/redis/general.blade.php b/resources/views/livewire/project/database/redis/general.blade.php index 952e48bef..a8a44b251 100644 --- a/resources/views/livewire/project/database/redis/general.blade.php +++ b/resources/views/livewire/project/database/redis/general.blade.php @@ -23,5 +23,6 @@ +