From c78068466b0471dbf4e1913abd88410ff3dd89d3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 8 Nov 2023 12:40:05 +0100 Subject: [PATCH] Add custom PostgreSQL configuration to StandalonePostgresql --- app/Actions/Database/StartPostgresql.php | 25 ++++++++++++++++ .../Project/Database/Postgresql/General.php | 2 ++ ...dd_custom_config_standalone_postgresql.php | 30 +++++++++++++++++++ .../database/postgresql/general.blade.php | 1 + 4 files changed, 58 insertions(+) create mode 100644 database/migrations/2023_11_08_112815_add_custom_config_standalone_postgresql.php diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 46e410980..2dc9a38b0 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -32,6 +32,8 @@ class StartPostgresql $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); $environment_variables = $this->generate_environment_variables(); $this->generate_init_scripts(); + $this->add_custom_conf(); + $docker_compose = [ 'version' => '3.8', 'services' => [ @@ -96,6 +98,19 @@ class StartPostgresql ]; } } + if (!is_null($this->database->postgres_conf)) { + $docker_compose['services'][$container_name]['volumes'][] = [ + 'type' => 'bind', + 'source' => $this->configuration_dir . '/custom-postgres.conf', + 'target' => '/etc/postgresql/postgresql.conf', + 'read_only' => true, + ]; + $docker_compose['services'][$container_name]['command'] = [ + 'postgres', + '-c', + 'config_file=/etc/postgresql/postgresql.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"; @@ -171,4 +186,14 @@ class StartPostgresql $this->init_scripts[] = "$this->configuration_dir/docker-entrypoint-initdb.d/{$filename}"; } } + private function add_custom_conf() + { + if (is_null($this->database->postgres_conf)) { + return; + } + $filename = 'custom-postgres.conf'; + $content = $this->database->postgres_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/Postgresql/General.php b/app/Http/Livewire/Project/Database/Postgresql/General.php index 7292ec2b2..ebc69a1bc 100644 --- a/app/Http/Livewire/Project/Database/Postgresql/General.php +++ b/app/Http/Livewire/Project/Database/Postgresql/General.php @@ -28,6 +28,7 @@ class General extends Component 'database.postgres_db' => 'required', 'database.postgres_initdb_args' => 'nullable', 'database.postgres_host_auth_method' => 'nullable', + 'database.postgres_conf' => 'nullable', 'database.init_scripts' => 'nullable', 'database.image' => 'required', 'database.ports_mappings' => 'nullable', @@ -42,6 +43,7 @@ class General extends Component 'database.postgres_db' => 'Postgres DB', 'database.postgres_initdb_args' => 'Postgres Initdb Args', 'database.postgres_host_auth_method' => 'Postgres Host Auth Method', + 'database.postgres_conf' => 'Postgres Configuration', 'database.init_scripts' => 'Init Scripts', 'database.image' => 'Image', 'database.ports_mappings' => 'Port Mapping', diff --git a/database/migrations/2023_11_08_112815_add_custom_config_standalone_postgresql.php b/database/migrations/2023_11_08_112815_add_custom_config_standalone_postgresql.php new file mode 100644 index 000000000..c583fb3ff --- /dev/null +++ b/database/migrations/2023_11_08_112815_add_custom_config_standalone_postgresql.php @@ -0,0 +1,30 @@ +longText('postgres_conf')->nullable(); + $table->string('image')->default('postgres:16-alpine')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->dropColumn('postgres_conf'); + $table->string('image')->default('postgres:15-alpine')->change(); + }); + } +}; diff --git a/resources/views/livewire/project/database/postgresql/general.blade.php b/resources/views/livewire/project/database/postgresql/general.blade.php index 368e55906..3116620ea 100644 --- a/resources/views/livewire/project/database/postgresql/general.blade.php +++ b/resources/views/livewire/project/database/postgresql/general.blade.php @@ -72,6 +72,7 @@ type="password" readonly wire:model="db_url_public" /> @endif +