From 2578cd7a6d4c516319c4b0d6881b4c67fd6652b1 Mon Sep 17 00:00:00 2001 From: Artur Gurgul1 Date: Wed, 6 Aug 2025 16:50:03 +0200 Subject: [PATCH] add postgresql --- home/.config/nvim/lua/plugins.lua | 15 +++++- lib/data/templates/nginx/proxy.erb | 2 +- lib/data/templates/postgresql/pg_hba.conf.erb | 2 + .../templates/postgresql/postgresql.conf.erb | 52 +++++++++++++++++++ lib/data/templates/postgresql/test.erb | 4 ++ lib/setup/postgresql.rb | 23 ++++++++ lib/templates.rb | 20 +++++++ recipes/forgejo-recipe/debian.yml | 3 ++ recipes/postgresql/debian-setup.yml | 24 +++++++++ recipes/postgresql/debian.yml | 21 ++++++++ 10 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 lib/data/templates/postgresql/pg_hba.conf.erb create mode 100644 lib/data/templates/postgresql/postgresql.conf.erb create mode 100644 lib/data/templates/postgresql/test.erb create mode 100644 lib/setup/postgresql.rb create mode 100644 lib/templates.rb create mode 100644 recipes/postgresql/debian-setup.yml create mode 100644 recipes/postgresql/debian.yml diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 8ecfd76..fe363a7 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -33,7 +33,20 @@ require("lazy").setup({ { "hrsh7th/vim-vsnip" }, -- Treesitter - { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { "ruby", "lua", "vim", "bash", "json" }, -- include ruby + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + }) + end + }, + -- Appearance { "tomasiser/vim-code-dark" }, diff --git a/lib/data/templates/nginx/proxy.erb b/lib/data/templates/nginx/proxy.erb index 81c813b..061b96a 100644 --- a/lib/data/templates/nginx/proxy.erb +++ b/lib/data/templates/nginx/proxy.erb @@ -26,4 +26,4 @@ server { ssl_certificate_key /etc/letsencrypt/live/<%= domain %>/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; -} \ No newline at end of file +} diff --git a/lib/data/templates/postgresql/pg_hba.conf.erb b/lib/data/templates/postgresql/pg_hba.conf.erb new file mode 100644 index 0000000..1afb456 --- /dev/null +++ b/lib/data/templates/postgresql/pg_hba.conf.erb @@ -0,0 +1,2 @@ +local all all peer +hostssl all all 0.0.0.0/0 scram-sha-256 diff --git a/lib/data/templates/postgresql/postgresql.conf.erb b/lib/data/templates/postgresql/postgresql.conf.erb new file mode 100644 index 0000000..c0617d1 --- /dev/null +++ b/lib/data/templates/postgresql/postgresql.conf.erb @@ -0,0 +1,52 @@ + +data_directory = '/var/lib/postgresql/15/main' +hba_file = '/etc/postgresql/15/main/pg_hba.conf' +ident_file = '/etc/postgresql/15/main/pg_ident.conf' + + +#listen_addresses = 'localhost' +listen_addresses = '*' +port = 5432 +max_connections = 100 +unix_socket_directories = '/var/run/postgresql' +password_encryption = scram-sha-256 + +ssl = on +#ssl_ca_file = '' +ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' +#ssl_crl_file = '' +#ssl_crl_dir = '' +ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key' +#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers +#ssl_prefer_server_ciphers = on +#ssl_ecdh_curve = 'prime256v1' +#ssl_min_protocol_version = 'TLSv1.2' +#ssl_max_protocol_version = '' +#ssl_dh_params_file = '' +#ssl_passphrase_command = '' +#ssl_passphrase_command_supports_reload = off + +shared_buffers = 128MB +dynamic_shared_memory_type = posix # the default is usually the first option + +max_wal_size = 1GB +min_wal_size = 80MB + +log_line_prefix = '%m [%p] %q%u@%d ' +log_timezone = 'Etc/UTC' + + +cluster_name = '15/main' + +datestyle = 'iso, mdy' +timezone = 'Etc/UTC' +lc_messages = 'C.UTF-8' +lc_monetary = 'C.UTF-8' +lc_numeric = 'C.UTF-8' +lc_time = 'C.UTF-8' + +default_text_search_config = 'pg_catalog.english' + +# include files ending in '.conf' from +include_dir = 'conf.d' + diff --git a/lib/data/templates/postgresql/test.erb b/lib/data/templates/postgresql/test.erb new file mode 100644 index 0000000..b0a5afa --- /dev/null +++ b/lib/data/templates/postgresql/test.erb @@ -0,0 +1,4 @@ + + + +<%= te %> diff --git a/lib/setup/postgresql.rb b/lib/setup/postgresql.rb new file mode 100644 index 0000000..0b12a8a --- /dev/null +++ b/lib/setup/postgresql.rb @@ -0,0 +1,23 @@ + +module Setup + require_relative '../templates' + + module PostgreSQL + extend Templates + + # attr_accessor :te + + + + def self.make_config + pg_hba = render("pg_hba.conf") + + test = render("test", te: "This is a test string") + puts test + end + + def self.install + make_config + end + end +end diff --git a/lib/templates.rb b/lib/templates.rb new file mode 100644 index 0000000..a5bd996 --- /dev/null +++ b/lib/templates.rb @@ -0,0 +1,20 @@ +require 'erb' + +module Templates + def render(name, locals = {}) + # caller_module = Module.nesting.first.to_s.split('::').last&.downcase || 'common' + caller_file = caller_locations(1, 1)[0].absolute_path + inferred_dir = File.basename(caller_file).sub(/^install-/, '').sub(/\.rb$/, '') + puts "caller name: #{inferred_dir}" + + template_path = File.join(__dir__, 'data', 'templates', inferred_dir, "#{name}.erb") + template = File.read(template_path) + erb = ERB.new(template) + + # erb.result(binding) + + context = Struct.new(*locals.keys).new(*locals.values) + erb.result(context.instance_eval { binding }) + end +end + diff --git a/recipes/forgejo-recipe/debian.yml b/recipes/forgejo-recipe/debian.yml index 0159ae8..b620dfb 100644 --- a/recipes/forgejo-recipe/debian.yml +++ b/recipes/forgejo-recipe/debian.yml @@ -1,4 +1,7 @@ +service: + name: forgejo + archive: url: https://codeberg.org/forgejo/forgejo/releases/download/v12.0.1/forgejo-12.0.1-linux-amd64.xz diff --git a/recipes/postgresql/debian-setup.yml b/recipes/postgresql/debian-setup.yml new file mode 100644 index 0000000..126cc9f --- /dev/null +++ b/recipes/postgresql/debian-setup.yml @@ -0,0 +1,24 @@ +environment: + PG_DOMAIN: gurgul.org + + +packages: + - postgresql + - postgresql-contrib + +steps: + - $SUDO systemctl enable postgresql + - $SUDO systemctl start postgresql + # Installing certificates + - $SUDO mkdir /etc/postgresql/ssl + - $SUDO cp /etc/letsencrypt/live/$PG_DOMAIN/fullchain.pem /etc/postgresql/ssl/server.crt + - $SUDO cp /etc/letsencrypt/live/$PG_DOMAIN/privkey.pem /etc/postgresql/ssl/server.key + - $SUDO chown postgres:postgres /etc/postgresql/ssl/server.* + - $SUDO chmod 600 /etc/postgresql/ssl/server.key + + +actions: + # dat action postgresql:add-user -u user + add-user: + - sudo -u postgres createuser --no-superuser --no-createdb --no-createrole $DB_USER + - sudo -u postgres createdb -O $DB_USER $DB_USER diff --git a/recipes/postgresql/debian.yml b/recipes/postgresql/debian.yml new file mode 100644 index 0000000..1d0e951 --- /dev/null +++ b/recipes/postgresql/debian.yml @@ -0,0 +1,21 @@ + +packages: + - build-essential + - libreadline-dev + - zlib1g-dev + - flex + - bison + - libssl-dev + - libxml2-dev + - libxslt1-dev + - libpam0g-dev + - libedit-dev + +repository: + url: https://github.com/postgres/postgres.git + branch: REL_17_5 + +steps: + - ./configure --prefix=$PREFIX + - make -j$CPUS + - make install