From 06df6f3a2bc80adeb9aabf83cc3aca3126b3543a Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 1 Mar 2025 02:35:45 +0000 Subject: [PATCH 01/43] Working scaffold for Pgpm::Deb::Builder where every method is a build step --- exe/pgpm | 66 +++++++++++++++++++++++------------ lib/pgpm/deb/builder.rb | 61 ++++++++++++++++++++++++++++++++ lib/pgpm/deb/spec.rb | 43 +++++++++++++++++++++++ lib/pgpm/os/debian.rb | 35 +++++++++++++++++++ lib/pgpm/package/packaging.rb | 6 ++++ 5 files changed, 189 insertions(+), 22 deletions(-) create mode 100644 lib/pgpm/deb/builder.rb create mode 100644 lib/pgpm/deb/spec.rb create mode 100644 lib/pgpm/os/debian.rb diff --git a/exe/pgpm b/exe/pgpm index bb67ce4..001e0c3 100755 --- a/exe/pgpm +++ b/exe/pgpm @@ -8,6 +8,8 @@ require "dry/cli" require "parallel" require "etc" +require "debug" + module Pgpm module CLI module Commands @@ -85,34 +87,54 @@ module Pgpm exit(1) end - unless os.is_a?(Pgpm::OS::RedHat) - puts "#{os.name} is not a supported OS at this moment" - exit(1) - end - puts "Building #{pkgs.map { |p| "#{p.name}@#{p.version}" }.join(", ")} for Postgres #{matching_pgver}" - selected_pgdist = Postgres::RedhatBasedPgdg.new(matching_pgver.to_s) - - os.with_scope do - arch.with_scope do - selected_pgdist.with_scope do - b = pkgs.reduce(nil) do |c, p| - if p.broken? - puts "Can't build a broken package #{p.name}@#{p.version}" - exit(1) + if os.is_a? Pgpm::OS::Debian + puts "Building #{pkgs.map { |p| "#{p.name}@#{p.version}" }.join(", ")} for Postgres #{matching_pgver}" + selected_pgdist = Postgres::RedhatBasedPgdg.new(matching_pgver.to_s) + + os.with_scope do + arch.with_scope do + selected_pgdist.with_scope do + spec = nil + b = pkgs.reduce(nil) do |c, p| + p = Pgpm::ScopedObject.new(p, os, arch) + spec = p.to_deb_spec end - p = Pgpm::ScopedObject.new(p, os, arch) - spec = p.to_rpm_spec - builder = Pgpm::RPM::Builder.new(spec) - src_builder = builder.source_builder - p = c.nil? ? src_builder : c.and_then(src_builder) - p.and_then(builder.versionless_builder) +binding.break + builder = Pgpm::Deb::Builder.new(spec) + builder.build end + end + end + elsif os.is_a? Pgpm::OS::RedHat + puts "Building #{pkgs.map { |p| "#{p.name}@#{p.version}" }.join(", ")} for Postgres #{matching_pgver}" + selected_pgdist = Postgres::RedhatBasedPgdg.new(matching_pgver.to_s) + + os.with_scope do + arch.with_scope do + selected_pgdist.with_scope do + b = pkgs.reduce(nil) do |c, p| + if p.broken? + puts "Can't build a broken package #{p.name}@#{p.version}" + exit(1) + end + p = Pgpm::ScopedObject.new(p, os, arch) + spec = p.to_rpm_spec + builder = Pgpm::RedHat::Builder.new(spec) + src_builder = builder.source_builder + p = c.nil? ? src_builder : c.and_then(src_builder) + p.and_then(builder.versionless_builder) + end - srpms = b.call - Pgpm::RPM::Builder.builder(srpms).call + srpms = b.call + Pgpm::RedHat::Builder.builder(srpms).call + end end end + else + puts "#{os.name} is not a supported OS at this moment" + exit(1) end + end # rubocop:enable Metrics/ParameterLists: diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb new file mode 100644 index 0000000..d403377 --- /dev/null +++ b/lib/pgpm/deb/builder.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Pgpm + module Deb + class Builder + + def initialize(spec) + @spec = spec + end + + def build + puts "build()" + p @spec + #create_container + #generate_deb_src_files + #run_pbuilder + #copy_build_from_container + #destroy_container + end + + private + + def create_container + # pull pgpm-enabled debian podman image if doesn't exist locally + # create a new container with that image + # and @spec.package.source mounted into the container + end + + def generate_deb_src_files + @spec.generate_rules + @spec.generate_control + @spec.generate_licence + @spec.generate_version + # save generated content into actual files + end + + def run_pbuilder + end + + def copy_build_from_container + end + + def copy_into_container(dest_dir_in_container) + end + + def copy_from_container(dest_dir_on_host) + end + + def destroy_container + end + + def run_container_command(cmd) + end + + def safe_package_name + @spec.package.name.gsub(%r{/}, "__") + end + + end + end +end diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb new file mode 100644 index 0000000..8f93c68 --- /dev/null +++ b/lib/pgpm/deb/spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require "digest" +require "open-uri" + +module Pgpm + module Deb + class Spec + attr_reader :package, :release, :postgres_version, :postgres_distribution + + def initialize(package) + @package = package + @release = 1 + + @postgres_distribution = Pgpm::Postgres::Distribution.in_scope + end + + def sources + @package.sources + end + + def generate_control + end + + def generate_rules + end + + def generate_licence + end + + def generate_version + end + + private + + def unpack?(src) + src = src.name if src.respond_to?(:name) + src.to_s.end_with?(".tar.gz") || src.to_s.end_with?(".tar.xz") + end + + end + end +end diff --git a/lib/pgpm/os/debian.rb b/lib/pgpm/os/debian.rb new file mode 100644 index 0000000..885636b --- /dev/null +++ b/lib/pgpm/os/debian.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rbconfig" + +module Pgpm + module OS + class Debian < Pgpm::OS::Linux + def self.auto_detect + # TODO: distinguish between flavors of Debian + Debian12.new + end + + def self.name + "debian" + end + + def mock_config; end + end + + class Debian12 < Pgpm::OS::Debian + def self.name + "debian-12" + end + + def self.builder + Pgpm::Debian::Builder + end + + def mock_config + "debian-12-#{Pgpm::Arch.in_scope.name}+pgdg" + end + + end + end +end diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index cabcdc8..3bf04d1 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -3,9 +3,15 @@ module Pgpm class Package module Packaging + def to_rpm_spec(**opts) Pgpm::RPM::Spec.new(self, **opts) end + + def to_deb_spec(**opts) + Pgpm::Deb::Spec.new(self, **opts) + end + end end end From 0a1c5f204091e03270182451d1f9831cb6bba094 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 2 Mar 2025 00:34:25 +0000 Subject: [PATCH 02/43] Pgpm::Deb::Builder #prepare and #create_container methods --- exe/pgpm | 1 - lib/pgpm/deb/builder.rb | 53 +++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/exe/pgpm b/exe/pgpm index 001e0c3..8bbc46e 100755 --- a/exe/pgpm +++ b/exe/pgpm @@ -99,7 +99,6 @@ module Pgpm p = Pgpm::ScopedObject.new(p, os, arch) spec = p.to_deb_spec end -binding.break builder = Pgpm::Deb::Builder.new(spec) builder.build end diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index d403377..f11b339 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -6,24 +6,51 @@ class Builder def initialize(spec) @spec = spec + @image_name = "pgpm-debian12" + @container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}" end def build puts "build()" - p @spec - #create_container + prepare #generate_deb_src_files + create_container #run_pbuilder #copy_build_from_container - #destroy_container + #cleanup end private + def prepare + puts "Preparing build..." + puts " Creating container dir structure..." + @pgpm_dir = Dir.mktmpdir + Dir.mkdir "#{@pgpm_dir}/source" + Dir.mkdir "#{@pgpm_dir}/out" + puts " Copying #{@spec.package.source.to_s} to #{@pgpm_dir}/source/" + FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/" + end + def create_container - # pull pgpm-enabled debian podman image if doesn't exist locally - # create a new container with that image - # and @spec.package.source mounted into the container + puts "Creating a podman container..." + # Check if image exists + system("podman image exists #{@image_name}") + if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository + puts " Pulling image #{@image_name}..." + # TODO + else + puts " Image #{@image_name} already exists! OK" + end + + create_opts = " -v #{@pgpm_dir}:/root/pgpm" + create_opts += ":z" if selinux_enabled? + create_opts += " --privileged" + create_opts += " --name #{@container_name} #{@image_name}" + + puts " Creating and starting container #{@container_name}" + puts " podman run -dti #{create_opts}" + system("podman run -dti #{create_opts}") end def generate_deb_src_files @@ -40,16 +67,18 @@ def run_pbuilder def copy_build_from_container end - def copy_into_container(dest_dir_in_container) - end - - def copy_from_container(dest_dir_on_host) + def run_container_command(cmd) end - def destroy_container + def cleanup end - def run_container_command(cmd) + # Needed because SELinux requires :z suffix for mounted directories to + # be accessible -- otherwise we get "Permission denied" when cd into a + # mounted dir inside the container. + def selinux_enabled? + # This returns true or false by itself + system("sestatus | grep 'SELinux status' | grep -o 'enabled'") end def safe_package_name From 676ac4dab604fd15bad154705c242922ad2c4967 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 2 Mar 2025 02:46:37 +0000 Subject: [PATCH 03/43] Generating debian files used when building a deb package with pbuilder --- lib/pgpm/deb/builder.rb | 16 ++++++---- lib/pgpm/deb/spec.rb | 48 +++++++++++++++++++++++----- lib/pgpm/deb/templates/changelog.erb | 5 +++ lib/pgpm/deb/templates/control.erb | 13 ++++++++ lib/pgpm/deb/templates/copyright.erb | 48 ++++++++++++++++++++++++++++ lib/pgpm/deb/templates/files.erb | 1 + lib/pgpm/deb/templates/rules.erb | 21 ++++++++++++ 7 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 lib/pgpm/deb/templates/changelog.erb create mode 100644 lib/pgpm/deb/templates/control.erb create mode 100644 lib/pgpm/deb/templates/copyright.erb create mode 100644 lib/pgpm/deb/templates/files.erb create mode 100644 lib/pgpm/deb/templates/rules.erb diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index f11b339..e5a0cac 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -13,8 +13,8 @@ def initialize(spec) def build puts "build()" prepare - #generate_deb_src_files - create_container + generate_deb_src_files + #create_container #run_pbuilder #copy_build_from_container #cleanup @@ -54,11 +54,13 @@ def create_container end def generate_deb_src_files - @spec.generate_rules - @spec.generate_control - @spec.generate_licence - @spec.generate_version - # save generated content into actual files + puts "Generating debian files..." + Dir.mkdir "#{@pgpm_dir}/debian" + [:changelog, :control, :copyright, :files, :rules].each do |f| + puts " -> #{@pgpm_dir}/debian/#{f}" + File.write "#{@pgpm_dir}/debian/#{f}", @spec.generate(f) + end + File.chmod 0740, "#{@pgpm_dir}/debian/rules" # rules file must be executable end def run_pbuilder diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 8f93c68..7653e36 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -2,6 +2,7 @@ require "digest" require "open-uri" +require "erb" module Pgpm module Deb @@ -19,23 +20,54 @@ def sources @package.sources end - def generate_control + def generate(template_name) + fn = "#{__dir__}/templates/#{template_name}.erb" + raise "No such template: #{fn}" unless File.exist?(fn) + erb = ERB.new(File.read(fn)) + erb.result(binding) end - def generate_rules + def deps + ["postgresql-#{postgres_version}"] end - def generate_licence + def build_deps + [ + "postgresql-#{postgres_version}", + "build-essential", + "postgresql-#{postgres_version}", + "postgresql-server-dev-#{postgres_version}", + "postgresql-common" + ] end - def generate_version + def postgres_version + 17 end - private + def source_version + @package.version.to_s + end + + def source_name + @package.name + end + + def deb_version + "0.1.0" + end + + def arch + "amd64" + end + + def description + @package.description + end - def unpack?(src) - src = src.name if src.respond_to?(:name) - src.to_s.end_with?(".tar.gz") || src.to_s.end_with?(".tar.xz") + # Whatever is returned from this method gets added to the "rules" file. + def rules_amendments + "#" end end diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb new file mode 100644 index 0000000..a1fb3c7 --- /dev/null +++ b/lib/pgpm/deb/templates/changelog.erb @@ -0,0 +1,5 @@ +<%= source_name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium + + * Initial release. (Closes: #nnnn) + + -- PGPM Debian maintainer Fri, 21 Feb 2025 21:08:08 +0000 diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb new file mode 100644 index 0000000..83adcc2 --- /dev/null +++ b/lib/pgpm/deb/templates/control.erb @@ -0,0 +1,13 @@ +Source: <%= source_name %>-<%= source_version %> +Section: libs +Priority: optional +Maintainer: PGPM Debian maintainer +Rules-Requires-Root: no +Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %> +Standards-Version: 4.6.2 + +Package: <%= source_name %>-<%= deb_version %> +Depends: <%= deps.join(", ") %> +Section: libdevel +Architecture: <%= arch %> +Description: <%= description %> diff --git a/lib/pgpm/deb/templates/copyright.erb b/lib/pgpm/deb/templates/copyright.erb new file mode 100644 index 0000000..448bbd4 --- /dev/null +++ b/lib/pgpm/deb/templates/copyright.erb @@ -0,0 +1,48 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Source: +Upstream-Name: <%= source_name %>-<%= source_version %> +Upstream-Contact: + +Files: + * +Copyright: + + +License: + + + . + + +# If you want to use GPL v2 or later for the /debian/* files use +# the following clauses, or change it to suit. Delete these two lines +Files: + debian/* +Copyright: + 2025 PGPM Debian maintainer +License: GPL-2+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see +Comment: + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. +# Please avoid picking licenses with terms that are more restrictive than the +# packaged work, as it may make Debian's contributions unacceptable upstream. +# +# If you need, there are some extra license texts available in two places: +# /usr/share/debhelper/dh_make/licenses/ +# /usr/share/common-licenses/ + diff --git a/lib/pgpm/deb/templates/files.erb b/lib/pgpm/deb/templates/files.erb new file mode 100644 index 0000000..0b517f9 --- /dev/null +++ b/lib/pgpm/deb/templates/files.erb @@ -0,0 +1 @@ +<%= source_name %>-<%= source_version %>_0-1_source.buildinfo libs optional diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb new file mode 100644 index 0000000..82cdccc --- /dev/null +++ b/lib/pgpm/deb/templates/rules.erb @@ -0,0 +1,21 @@ +#!/usr/bin/make -f + +# See debhelper(7) (uncomment to enable). +# Output every command that modifies files on the build system. +#export DH_VERBOSE = 1 + + +# See FEATURE AREAS in dpkg-buildflags(1). +#export DEB_BUILD_MAINT_OPTIONS = hardening=+all + +# See ENVIRONMENT in dpkg-buildflags(1). +# Package maintainers to append CFLAGS. +#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic +# Package maintainers to append LDFLAGS. +#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed + + +%: + dh $@ + +<%= self.rules_amendments %> From 11cc4deab10c69a2e62ca2cbb2cad0d9e08a8ff1 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 2 Mar 2025 02:52:50 +0000 Subject: [PATCH 04/43] Pgpm::Deb::Buider#cleanup stops & removes podman container, removes tmp dir --- lib/pgpm/deb/builder.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index e5a0cac..53c1d5d 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -14,10 +14,10 @@ def build puts "build()" prepare generate_deb_src_files - #create_container + create_container #run_pbuilder #copy_build_from_container - #cleanup + cleanup end private @@ -73,6 +73,24 @@ def run_container_command(cmd) end def cleanup + puts "Cleaning up..." + + # Stop and destroy podman container + puts " Stopping podman container: #{@container_name}" + system("podman stop #{@container_name}") + puts " Destroying podman container: #{@container_name}" + system("podman container rm #{@container_name}") + + # Remove temporary files + # + # Make sure @pgpm_dir starts with "/tmp/" or we may accidentally + # delete something everything! You can never be sure! + if @pgpm_dir.start_with?("/tmp/") + puts " Removing temporary files in #{@pgpm_dir}" + FileUtils.rm_rf(@pgpm_dir) + else + puts "WARNING: will not remove temporary files, strange path: \"#{@pgpm_dir}\"" + end end # Needed because SELinux requires :z suffix for mounted directories to From 0b2dd5172c473baff3a5c7bfd8f7963ac9f1d59a Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 2 Mar 2025 22:37:53 +0000 Subject: [PATCH 05/43] Pgpm::Deb::Builder build with pbuilder, then move .deb file to the host --- lib/pgpm/deb/builder.rb | 27 ++++++++++++++++++++------- lib/pgpm/deb/spec.rb | 4 ++++ lib/pgpm/deb/templates/control.erb | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 53c1d5d..ebeb8bd 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -15,8 +15,8 @@ def build prepare generate_deb_src_files create_container - #run_pbuilder - #copy_build_from_container + run_pbuilder + copy_build_from_container cleanup end @@ -45,7 +45,7 @@ def create_container create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? - create_opts += " --privileged" + create_opts += " --privileged --annotation run.oci.keep_original_groups=1" create_opts += " --name #{@container_name} #{@image_name}" puts " Creating and starting container #{@container_name}" @@ -55,18 +55,31 @@ def create_container def generate_deb_src_files puts "Generating debian files..." - Dir.mkdir "#{@pgpm_dir}/debian" + Dir.mkdir "#{@pgpm_dir}/source/debian" [:changelog, :control, :copyright, :files, :rules].each do |f| - puts " -> #{@pgpm_dir}/debian/#{f}" - File.write "#{@pgpm_dir}/debian/#{f}", @spec.generate(f) + puts " -> #{@pgpm_dir}/source/debian/#{f}" + File.write "#{@pgpm_dir}/source/debian/#{f}", @spec.generate(f) end - File.chmod 0740, "#{@pgpm_dir}/debian/rules" # rules file must be executable + File.chmod 0740, "#{@pgpm_dir}/source/debian/rules" # rules file must be executable end def run_pbuilder + puts "Building a .deb package with pbuilder..." + cmd_pref = "podman exec -w /root/pgpm/source #{@container_name} " + system("#{cmd_pref} dpkg-buildpackage --build=source") + exit(1) if $?.to_i > 0 + dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" + system("#{cmd_pref} fakeroot pbuilder build ../#{dsc_fn}") + exit(1) if $?.to_i > 0 end def copy_build_from_container + puts "Moving .deb file from podman container into current directory..." + cmd_pref = "podman exec #{@container_name} " + arch = "amd64" + deb_fn = "#{@spec.full_pkg_name}.deb" + system("#{cmd_pref} mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/") + FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd) end def run_container_command(cmd) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 7653e36..8f7346f 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -53,6 +53,10 @@ def source_name @package.name end + def full_pkg_name + "#{@package.name}-#{@package.version.to_s}_0-1_#{arch}" + end + def deb_version "0.1.0" end diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index 83adcc2..5136bc2 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -6,7 +6,7 @@ Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %> Standards-Version: 4.6.2 -Package: <%= source_name %>-<%= deb_version %> +Package: <%= source_name %>-<%= source_version %> Depends: <%= deps.join(", ") %> Section: libdevel Architecture: <%= arch %> From 62748ff7d95681bc0f5191edf1e020f270bc35c0 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 2 Mar 2025 22:56:11 +0000 Subject: [PATCH 06/43] Pgpb::Deb:Builder pull image unless it exists --- lib/pgpm/deb/builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index ebeb8bd..077200a 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -6,7 +6,7 @@ class Builder def initialize(spec) @spec = spec - @image_name = "pgpm-debian12" + @image_name = "quay.io/qount25/pgpm-debian12" @container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}" end @@ -38,7 +38,7 @@ def create_container system("podman image exists #{@image_name}") if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository puts " Pulling image #{@image_name}..." - # TODO + system("podman pull quay.io/qount25/pgpm-debian12") else puts " Image #{@image_name} already exists! OK" end From aa0d91503299584bfe83069ade1f7c117f4acb9f Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 6 Mar 2025 00:47:50 +0000 Subject: [PATCH 07/43] Refactor: replace most hardcoded values for Pgpm::Deb::Spec with values from @package --- lib/pgpm/deb/builder.rb | 16 +++++++++------- lib/pgpm/deb/spec.rb | 24 ++++++------------------ lib/pgpm/deb/templates/control.erb | 6 +++--- lib/pgpm/deb/templates/copyright.erb | 2 +- lib/pgpm/deb/templates/files.erb | 2 +- lib/pgpm/package/packaging.rb | 1 + lib/pgpm/scoped_object.rb | 1 + 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 077200a..2056b32 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -6,12 +6,10 @@ class Builder def initialize(spec) @spec = spec - @image_name = "quay.io/qount25/pgpm-debian12" @container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}" end def build - puts "build()" prepare generate_deb_src_files create_container @@ -22,6 +20,11 @@ def build private + # Depends on postgres version and arch + def image_name + "quay.io/qount25/pgpm-debian-pg#{@spec.postgres_major_version}-#{@spec.arch}" + end + def prepare puts "Preparing build..." puts " Creating container dir structure..." @@ -35,18 +38,18 @@ def prepare def create_container puts "Creating a podman container..." # Check if image exists - system("podman image exists #{@image_name}") + system("podman image exists #{image_name}") if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository - puts " Pulling image #{@image_name}..." + puts " Pulling image #{image_name}..." system("podman pull quay.io/qount25/pgpm-debian12") else - puts " Image #{@image_name} already exists! OK" + puts " Image #{image_name} already exists! OK" end create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? create_opts += " --privileged --annotation run.oci.keep_original_groups=1" - create_opts += " --name #{@container_name} #{@image_name}" + create_opts += " --name #{@container_name} #{image_name}" puts " Creating and starting container #{@container_name}" puts " podman run -dti #{create_opts}" @@ -76,7 +79,6 @@ def run_pbuilder def copy_build_from_container puts "Moving .deb file from podman container into current directory..." cmd_pref = "podman exec #{@container_name} " - arch = "amd64" deb_fn = "#{@spec.full_pkg_name}.deb" system("#{cmd_pref} mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/") FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 8f7346f..7ba153e 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -28,47 +28,35 @@ def generate(template_name) end def deps - ["postgresql-#{postgres_version}"] + ["postgresql-#{postgres_major_version}"] end def build_deps [ - "postgresql-#{postgres_version}", + "postgresql-#{postgres_major_version}", "build-essential", - "postgresql-#{postgres_version}", - "postgresql-server-dev-#{postgres_version}", + "postgresql-#{postgres_major_version}", + "postgresql-server-dev-#{postgres_major_version}", "postgresql-common" ] end - def postgres_version - 17 + def postgres_major_version + @spec.postgres_distribution.version.split(".")[0] end def source_version @package.version.to_s end - def source_name - @package.name - end - def full_pkg_name "#{@package.name}-#{@package.version.to_s}_0-1_#{arch}" end - def deb_version - "0.1.0" - end - def arch "amd64" end - def description - @package.description - end - # Whatever is returned from this method gets added to the "rules" file. def rules_amendments "#" diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index 5136bc2..0698166 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -1,4 +1,4 @@ -Source: <%= source_name %>-<%= source_version %> +Source: <%= self.package.name %>-<%= source_version %> Section: libs Priority: optional Maintainer: PGPM Debian maintainer @@ -6,8 +6,8 @@ Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %> Standards-Version: 4.6.2 -Package: <%= source_name %>-<%= source_version %> +Package: <%= self.package.name %>-<%= source_version %> Depends: <%= deps.join(", ") %> Section: libdevel Architecture: <%= arch %> -Description: <%= description %> +Description: <%= self.package.description %> diff --git a/lib/pgpm/deb/templates/copyright.erb b/lib/pgpm/deb/templates/copyright.erb index 448bbd4..b2dde3f 100644 --- a/lib/pgpm/deb/templates/copyright.erb +++ b/lib/pgpm/deb/templates/copyright.erb @@ -1,6 +1,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Source: -Upstream-Name: <%= source_name %>-<%= source_version %> +Upstream-Name: <%= self.package.name %>-<%= self.package.name %> Upstream-Contact: Files: diff --git a/lib/pgpm/deb/templates/files.erb b/lib/pgpm/deb/templates/files.erb index 0b517f9..78cbdbb 100644 --- a/lib/pgpm/deb/templates/files.erb +++ b/lib/pgpm/deb/templates/files.erb @@ -1 +1 @@ -<%= source_name %>-<%= source_version %>_0-1_source.buildinfo libs optional +<%= self.package.name %>-<%= source_version %>_0-1_source.buildinfo libs optional diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index 3bf04d1..34d766c 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -9,6 +9,7 @@ def to_rpm_spec(**opts) end def to_deb_spec(**opts) +binding.break Pgpm::Deb::Spec.new(self, **opts) end diff --git a/lib/pgpm/scoped_object.rb b/lib/pgpm/scoped_object.rb index f5e113d..3ade0d6 100644 --- a/lib/pgpm/scoped_object.rb +++ b/lib/pgpm/scoped_object.rb @@ -7,6 +7,7 @@ class ScopedObject < SimpleDelegator def initialize(obj, *scopes) @scopes = scopes super(obj) +binding.break end def method_missing(method, *args, &block) From 97d5506a7bba294501faf7df5541d303e7faf4a1 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 6 Mar 2025 04:37:25 +0000 Subject: [PATCH 08/43] Refactor: make build run all podman commands in one go, then exit --- lib/pgpm/deb/builder.rb | 51 +++++++++++++--------------- lib/pgpm/deb/spec.rb | 2 +- lib/pgpm/deb/templates/changelog.erb | 2 +- lib/pgpm/package/packaging.rb | 1 - lib/pgpm/scoped_object.rb | 1 - 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 2056b32..0fdceb5 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -6,14 +6,14 @@ class Builder def initialize(spec) @spec = spec - @container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}" + @container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10000)}" end def build prepare generate_deb_src_files - create_container - run_pbuilder + pull_image + run_build copy_build_from_container cleanup end @@ -35,25 +35,16 @@ def prepare FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/" end - def create_container - puts "Creating a podman container..." + def pull_image + puts "Checking if podman image exists..." # Check if image exists system("podman image exists #{image_name}") if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository - puts " Pulling image #{image_name}..." + puts " No. Pulling image #{image_name}..." system("podman pull quay.io/qount25/pgpm-debian12") else - puts " Image #{image_name} already exists! OK" + puts " Yes, image #{image_name} already exists! OK" end - - create_opts = " -v #{@pgpm_dir}:/root/pgpm" - create_opts += ":z" if selinux_enabled? - create_opts += " --privileged --annotation run.oci.keep_original_groups=1" - create_opts += " --name #{@container_name} #{image_name}" - - puts " Creating and starting container #{@container_name}" - puts " podman run -dti #{create_opts}" - system("podman run -dti #{create_opts}") end def generate_deb_src_files @@ -66,27 +57,33 @@ def generate_deb_src_files File.chmod 0740, "#{@pgpm_dir}/source/debian/rules" # rules file must be executable end - def run_pbuilder - puts "Building a .deb package with pbuilder..." - cmd_pref = "podman exec -w /root/pgpm/source #{@container_name} " - system("#{cmd_pref} dpkg-buildpackage --build=source") - exit(1) if $?.to_i > 0 + def run_build + # podman run options + create_opts = " -v #{@pgpm_dir}:/root/pgpm" + create_opts += ":z" if selinux_enabled? + create_opts += " --privileged --annotation run.oci.keep_original_groups=1" + create_opts += " --name #{@container_name} #{image_name}" + dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" - system("#{cmd_pref} fakeroot pbuilder build ../#{dsc_fn}") + deb_fn = "#{@spec.full_pkg_name}.deb" + + # commands to run + cmds = " /bin/bash -c 'cd /root/pgpm/source" + cmds += " && dpkg-buildpackage --build=source" + cmds += " && fakeroot pbuilder build ../#{dsc_fn}" + cmds += " && mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/'" + + puts " Creating and starting container #{@container_name} & running pbuilder" + system("podman run -it #{create_opts} #{cmds}") exit(1) if $?.to_i > 0 end def copy_build_from_container puts "Moving .deb file from podman container into current directory..." - cmd_pref = "podman exec #{@container_name} " deb_fn = "#{@spec.full_pkg_name}.deb" - system("#{cmd_pref} mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/") FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd) end - def run_container_command(cmd) - end - def cleanup puts "Cleaning up..." diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 7ba153e..621aa4d 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -42,7 +42,7 @@ def build_deps end def postgres_major_version - @spec.postgres_distribution.version.split(".")[0] + self.postgres_distribution.version.split(".")[0] end def source_version diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index a1fb3c7..06dabac 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -1,4 +1,4 @@ -<%= source_name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium +<%= self.package.name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium * Initial release. (Closes: #nnnn) diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index 34d766c..3bf04d1 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -9,7 +9,6 @@ def to_rpm_spec(**opts) end def to_deb_spec(**opts) -binding.break Pgpm::Deb::Spec.new(self, **opts) end diff --git a/lib/pgpm/scoped_object.rb b/lib/pgpm/scoped_object.rb index 3ade0d6..f5e113d 100644 --- a/lib/pgpm/scoped_object.rb +++ b/lib/pgpm/scoped_object.rb @@ -7,7 +7,6 @@ class ScopedObject < SimpleDelegator def initialize(obj, *scopes) @scopes = scopes super(obj) -binding.break end def method_missing(method, *args, &block) From e26594fbecba77f09def6842e8246d9da81a1d62 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 7 Mar 2025 01:23:41 +0000 Subject: [PATCH 09/43] Fix: hardocoded podman image name instead of using Pgpm::Deb::Builder#image_name --- lib/pgpm/deb/builder.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 0fdceb5..7f1ae32 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -41,7 +41,7 @@ def pull_image system("podman image exists #{image_name}") if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository puts " No. Pulling image #{image_name}..." - system("podman pull quay.io/qount25/pgpm-debian12") + system("podman pull #{image_name}") else puts " Yes, image #{image_name} already exists! OK" end @@ -87,9 +87,6 @@ def copy_build_from_container def cleanup puts "Cleaning up..." - # Stop and destroy podman container - puts " Stopping podman container: #{@container_name}" - system("podman stop #{@container_name}") puts " Destroying podman container: #{@container_name}" system("podman container rm #{@container_name}") From 29b258bdd43a745b00f8c0316b480e5967c6b164 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 7 Mar 2025 05:01:53 +0000 Subject: [PATCH 10/43] Choosing arch suffix for debian packages (it's not the same as in RPM!) --- lib/pgpm/deb/spec.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 621aa4d..b9b350a 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -54,7 +54,14 @@ def full_pkg_name end def arch - "amd64" + # https://memgraph.com/blog/ship-it-on-arm64-or-is-it-aarch64 + # Debian suffixes are "amd64" and "arm64". Here we translate: + case Pgpm::Arch.host.name + when "amd64", "x86_64" + "amd64" + when "aarch64", "arm64" + "arm64" + end end # Whatever is returned from this method gets added to the "rules" file. From 1f8b9b29da66352da9ad1023d549b56b602cdb51 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 7 Mar 2025 06:12:33 +0000 Subject: [PATCH 11/43] WIP: Timescaledb package with #build_info_for() for Debian and RedHat --- packages/timescaledb.rb | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 packages/timescaledb.rb diff --git a/packages/timescaledb.rb b/packages/timescaledb.rb new file mode 100644 index 0000000..76c04f3 --- /dev/null +++ b/packages/timescaledb.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +class Timescaledb < Pgpm::Package + github "timescale/timescaledb" + + def description + "An open-source time-series SQL database optimized for fast ingest and " + + "complex queries" + end + + def licence + "Timescale License" + end + + def summary + "TimescaleDB is an open-source database designed to make SQL " + + "scalable for time-series data. It is engineered up from PostgreSQL " + + "and packaged as a PostgreSQL extension, providing automatic " + + "partitioning across time and space (partitioning key), as well as " + + "full SQL support." + end + + def build_info_for(os) + case os.downcase + when "debian", "ubuntu" + { + dependencies: [], + build_dependencies: ["openssl-dev", "cmake"], + rules: "override_dh_auto_configure:\n" + + " dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" + } + when "rocky", "redhat", "fedora" + { + dependencies: [], + build_dependencies: ["openssl-devel", "cmake"], + build_steps: [ + "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", + "cmake --build build --parallel" + ], + install_steps: [ + "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" + ] + } + } + end + end + + protected + + def bootstrap_flags + [] + end + +end From 3165c1045af37bf090a3ef33904d1f96cce4cdfe Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 7 Mar 2025 06:36:59 +0000 Subject: [PATCH 12/43] Add Package#licence which attempts to read LICENCE file in pkg root and return its contents --- lib/pgpm/deb/builder.rb | 1 + lib/pgpm/deb/templates/copyright.erb | 41 +--------------------------- lib/pgpm/package/metadata.rb | 10 +++++++ lib/pgpm/package/pgxn.rb | 17 ++++-------- packages/timescale/timescaledb.rb | 4 --- packages/timescaledb.rb | 5 ---- 6 files changed, 18 insertions(+), 60 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 7f1ae32..a8907d4 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -10,6 +10,7 @@ def initialize(spec) end def build +binding.break prepare generate_deb_src_files pull_image diff --git a/lib/pgpm/deb/templates/copyright.erb b/lib/pgpm/deb/templates/copyright.erb index b2dde3f..737534a 100644 --- a/lib/pgpm/deb/templates/copyright.erb +++ b/lib/pgpm/deb/templates/copyright.erb @@ -6,43 +6,4 @@ Upstream-Contact: Files: * Copyright: - - -License: - - - . - - -# If you want to use GPL v2 or later for the /debian/* files use -# the following clauses, or change it to suit. Delete these two lines -Files: - debian/* -Copyright: - 2025 PGPM Debian maintainer -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see -Comment: - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". - -# Please also look if there are files or directories which have a -# different copyright/license attached and list them here. -# Please avoid picking licenses with terms that are more restrictive than the -# packaged work, as it may make Debian's contributions unacceptable upstream. -# -# If you need, there are some extra license texts available in two places: -# /usr/share/debhelper/dh_make/licenses/ -# /usr/share/common-licenses/ - +<%= slef.package.licence %> diff --git a/lib/pgpm/package/metadata.rb b/lib/pgpm/package/metadata.rb index 88858f1..b0210e4 100644 --- a/lib/pgpm/package/metadata.rb +++ b/lib/pgpm/package/metadata.rb @@ -25,6 +25,16 @@ def broken? requires.any?(&:broken?) end + def license + path = "#{self.source.to_s}" + ["LICENSE", "license", "License"].each do |fn| + if File.exist?("#{path}/#{fn}") + return File.read("#{path}/#{fn}") + end + end + nil + end + module ClassMethods def extension_name self[:latest]&.extension_name diff --git a/lib/pgpm/package/pgxn.rb b/lib/pgpm/package/pgxn.rb index b5a00b3..495fe43 100644 --- a/lib/pgpm/package/pgxn.rb +++ b/lib/pgpm/package/pgxn.rb @@ -42,20 +42,15 @@ def description end def license - if provides_pgxn_meta_json? - lic = pgxn_meta_json["license"] - case lic - when Hash - lic.keys.join(" or ") - when Array - lic.join(" or ") - when String - lic + path = "#{self.source.to_s}" + ["LICENSE", "license", "License"].each do |fn| + if File.exist?("#{path}/#{fn}") + return File.read("#{path}/#{fn}") end - else - super end + nil end + end end end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index 1efb38f..e8b3ea0 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -19,10 +19,6 @@ def description "An open-source time-series SQL database optimized for fast ingest and complex queries" end - def license - "Timescale License" - end - def build_steps [ "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", diff --git a/packages/timescaledb.rb b/packages/timescaledb.rb index 76c04f3..78c0b34 100644 --- a/packages/timescaledb.rb +++ b/packages/timescaledb.rb @@ -8,10 +8,6 @@ def description "complex queries" end - def licence - "Timescale License" - end - def summary "TimescaleDB is an open-source database designed to make SQL " + "scalable for time-series data. It is engineered up from PostgreSQL " + @@ -41,7 +37,6 @@ def build_info_for(os) "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" ] } - } end end From 70cb28a871fba13ef6a566ddb14342efd0eb6822 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 05:11:19 +0000 Subject: [PATCH 13/43] Fix: email address domain name for debian packages --- lib/pgpm/deb/templates/control.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index 0698166..f7cebdd 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -1,7 +1,7 @@ Source: <%= self.package.name %>-<%= source_version %> Section: libs Priority: optional -Maintainer: PGPM Debian maintainer +Maintainer: PGPM Debian maintainer Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %> Standards-Version: 4.6.2 From 7dec4dc00df564d463aa50af8512a6e030637539 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 05:13:59 +0000 Subject: [PATCH 14/43] Refactor: use Pgpm::Arch.in_scope to determine architecture --- lib/pgpm/deb/spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index b9b350a..28535da 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -56,7 +56,7 @@ def full_pkg_name def arch # https://memgraph.com/blog/ship-it-on-arm64-or-is-it-aarch64 # Debian suffixes are "amd64" and "arm64". Here we translate: - case Pgpm::Arch.host.name + case Pgpm::Arch.in_scope.name when "amd64", "x86_64" "amd64" when "aarch64", "arm64" From 998546d78fefc05e8b6f838ebc0a71a79fa8830f Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 05:49:29 +0000 Subject: [PATCH 15/43] Rename Pgpm::Package::PGXN#license into #license_text, restore old #license method --- lib/pgpm/package/metadata.rb | 10 ---------- lib/pgpm/package/pgxn.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/pgpm/package/metadata.rb b/lib/pgpm/package/metadata.rb index b0210e4..88858f1 100644 --- a/lib/pgpm/package/metadata.rb +++ b/lib/pgpm/package/metadata.rb @@ -25,16 +25,6 @@ def broken? requires.any?(&:broken?) end - def license - path = "#{self.source.to_s}" - ["LICENSE", "license", "License"].each do |fn| - if File.exist?("#{path}/#{fn}") - return File.read("#{path}/#{fn}") - end - end - nil - end - module ClassMethods def extension_name self[:latest]&.extension_name diff --git a/lib/pgpm/package/pgxn.rb b/lib/pgpm/package/pgxn.rb index 495fe43..a50c868 100644 --- a/lib/pgpm/package/pgxn.rb +++ b/lib/pgpm/package/pgxn.rb @@ -42,6 +42,22 @@ def description end def license + if provides_pgxn_meta_json? + lic = pgxn_meta_json["license"] + case lic + when Hash + lic.keys.join(" or ") + when Array + lic.join(" or ") + when String + lic + end + else + super + end + end + + def license_text path = "#{self.source.to_s}" ["LICENSE", "license", "License"].each do |fn| if File.exist?("#{path}/#{fn}") From 4ac7c0f3cd69c29291b101b6b3740cc11d2cac7c Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 06:30:28 +0000 Subject: [PATCH 16/43] Specify default & custom dependencies in packages --- lib/pgpm/deb/builder.rb | 3 +- lib/pgpm/deb/spec.rb | 28 ++------------- lib/pgpm/deb/templates/control.erb | 5 +-- lib/pgpm/deb/templates/copyright.erb | 2 +- lib/pgpm/deb/templates/rules.erb | 2 +- lib/pgpm/package/building.rb | 13 +++---- lib/pgpm/package/dependencies.rb | 32 ++++++++++++++--- lib/pgpm/package/packaging.rb | 2 ++ packages/timescale/timescaledb.rb | 53 +++++++++++++++++++--------- packages/timescaledb.rb | 49 ------------------------- 10 files changed, 82 insertions(+), 107 deletions(-) delete mode 100644 packages/timescaledb.rb diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index a8907d4..5b0ef76 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -10,7 +10,6 @@ def initialize(spec) end def build -binding.break prepare generate_deb_src_files pull_image @@ -23,7 +22,7 @@ def build # Depends on postgres version and arch def image_name - "quay.io/qount25/pgpm-debian-pg#{@spec.postgres_major_version}-#{@spec.arch}" + "quay.io/qount25/pgpm-debian-pg#{@spec.package.postgres_major_version}-#{@spec.arch}" end def prepare diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 28535da..d3860fa 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -10,10 +10,11 @@ class Spec attr_reader :package, :release, :postgres_version, :postgres_distribution def initialize(package) + @postgres_distribution = Pgpm::Postgres::Distribution.in_scope @package = package + @package.postgres_major_version = @postgres_distribution.version.split(".")[0] + @package.os = "debian" @release = 1 - - @postgres_distribution = Pgpm::Postgres::Distribution.in_scope end def sources @@ -27,24 +28,6 @@ def generate(template_name) erb.result(binding) end - def deps - ["postgresql-#{postgres_major_version}"] - end - - def build_deps - [ - "postgresql-#{postgres_major_version}", - "build-essential", - "postgresql-#{postgres_major_version}", - "postgresql-server-dev-#{postgres_major_version}", - "postgresql-common" - ] - end - - def postgres_major_version - self.postgres_distribution.version.split(".")[0] - end - def source_version @package.version.to_s end @@ -64,11 +47,6 @@ def arch end end - # Whatever is returned from this method gets added to the "rules" file. - def rules_amendments - "#" - end - end end end diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index f7cebdd..42234ef 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -1,13 +1,14 @@ Source: <%= self.package.name %>-<%= source_version %> +Description: <%= self.package.description %> Section: libs Priority: optional Maintainer: PGPM Debian maintainer Rules-Requires-Root: no -Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %> +Build-Depends: debhelper-compat (= 13), <%= self.package.build_dependencies.join(", ") %> Standards-Version: 4.6.2 Package: <%= self.package.name %>-<%= source_version %> -Depends: <%= deps.join(", ") %> +Depends: <%= self.package.dependencies.join(", ") %> Section: libdevel Architecture: <%= arch %> Description: <%= self.package.description %> diff --git a/lib/pgpm/deb/templates/copyright.erb b/lib/pgpm/deb/templates/copyright.erb index 737534a..42a9127 100644 --- a/lib/pgpm/deb/templates/copyright.erb +++ b/lib/pgpm/deb/templates/copyright.erb @@ -6,4 +6,4 @@ Upstream-Contact: Files: * Copyright: -<%= slef.package.licence %> +<%= self.package.license %> diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index 82cdccc..d923f32 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -18,4 +18,4 @@ %: dh $@ -<%= self.rules_amendments %> +<%= self.package.build_info[:rules] %> diff --git a/lib/pgpm/package/building.rb b/lib/pgpm/package/building.rb index 886ce85..64c5851 100644 --- a/lib/pgpm/package/building.rb +++ b/lib/pgpm/package/building.rb @@ -7,12 +7,13 @@ def configure_steps [] end - def build_steps - [] - end - - def install_steps - [] + def build_info + case @os + when "debian", "ubuntu" + { rules: "" } + when "rocky", "redhat", "fedora" + { build_steps: [], install_steps: [] } + end end def source_url_directory_name diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index 084afca..b39b259 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -3,14 +3,37 @@ module Pgpm class Package module Dependencies - def build_dependencies - return ["gcc"] if c_files_present? - [] + attr_accessor :postgres_major_version + + def build_dependencies + case @os + when "debian", "ubuntu" + [ + "postgresql-#{postgres_major_version}", + "build-essential", + "postgresql-#{postgres_major_version}", + "postgresql-server-dev-#{postgres_major_version}", + "postgresql-common" + ] + when "rocky", "redhat", "fedora" + [ + "postgresql-#{postgres_major_version}", + "build-essential", + "postgresql-#{postgres_major_version}", + "postgresql-server-devel-#{postgres_major_version}", + "postgresql-common" + ] + end end def dependencies - [] + case @os + when "debian", "ubuntu" + [ "postgresql-#{postgres_major_version}" ] + when "rocky", "redhat", "fedora" + [ "postgresql-#{postgres_major_version}" ] + end end def requires @@ -20,6 +43,7 @@ def requires def c_files_present? Dir.glob("*.c", base: source).any? end + end end end diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index 3bf04d1..3c799ee 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -4,6 +4,8 @@ module Pgpm class Package module Packaging + attr_accessor :os + def to_rpm_spec(**opts) Pgpm::RPM::Spec.new(self, **opts) end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index e8b3ea0..3c26420 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -11,33 +11,51 @@ def self.package_versions super.select { |v| v.to_s =~ /^(\d+\.\d+\.\d+)$/ } end - def summary - "TimescaleDB is an open-source database designed to make SQL scalable for time-series data. It is engineered up from PostgreSQL and packaged as a PostgreSQL extension, providing automatic partitioning across time and space (partitioning key), as well as full SQL support." - end - def description - "An open-source time-series SQL database optimized for fast ingest and complex queries" + "An open-source time-series SQL database optimized for fast ingest and " + + "complex queries" end - def build_steps - [ - "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", - "cmake --build build --parallel" - ] + def summary + "TimescaleDB is an open-source database designed to make SQL " + + "scalable for time-series data. It is engineered up from PostgreSQL " + + "and packaged as a PostgreSQL extension, providing automatic " + + "partitioning across time and space (partitioning key), as well as " + + "full SQL support." end - def install_steps - [ - "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" - ] + def dependencies + super end def build_dependencies - super + %w[openssl-devel cmake] + deps = case @os + when "debian", "ubunut" + ["openssl-dev", "cmake"] + when "rocky", "redhat", "fedora" + ["openssl-devel", "cmake"] + end + super + deps end - def dependencies - super + %w[openssl] + def build_info + case @os + when "debian", "ubuntu" + { + rules: "override_dh_auto_configure:\n" + + " dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" + } + when "rocky", "redhat", "fedora" + { + build_steps: [ + "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", + "cmake --build build --parallel" + ], + install_steps: [ + "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" + ] + } + end end protected @@ -45,5 +63,6 @@ def dependencies def bootstrap_flags [] end + end end diff --git a/packages/timescaledb.rb b/packages/timescaledb.rb deleted file mode 100644 index 78c0b34..0000000 --- a/packages/timescaledb.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -class Timescaledb < Pgpm::Package - github "timescale/timescaledb" - - def description - "An open-source time-series SQL database optimized for fast ingest and " + - "complex queries" - end - - def summary - "TimescaleDB is an open-source database designed to make SQL " + - "scalable for time-series data. It is engineered up from PostgreSQL " + - "and packaged as a PostgreSQL extension, providing automatic " + - "partitioning across time and space (partitioning key), as well as " + - "full SQL support." - end - - def build_info_for(os) - case os.downcase - when "debian", "ubuntu" - { - dependencies: [], - build_dependencies: ["openssl-dev", "cmake"], - rules: "override_dh_auto_configure:\n" + - " dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" - } - when "rocky", "redhat", "fedora" - { - dependencies: [], - build_dependencies: ["openssl-devel", "cmake"], - build_steps: [ - "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", - "cmake --build build --parallel" - ], - install_steps: [ - "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" - ] - } - end - end - - protected - - def bootstrap_flags - [] - end - -end From 97581e75291c34c008cde0306ce0a4bf9725f02c Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 07:19:03 +0000 Subject: [PATCH 17/43] Fix: dpkg-buildpackage --build=source step in Pgpm::Deb::Builder should not require dependencies install inside podman --- lib/pgpm/deb/builder.rb | 5 +++-- packages/timescale/timescaledb.rb | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 5b0ef76..e9b6a56 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -61,7 +61,7 @@ def run_build # podman run options create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? - create_opts += " --privileged --annotation run.oci.keep_original_groups=1" + create_opts += " --privileged" create_opts += " --name #{@container_name} #{image_name}" dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" @@ -69,11 +69,12 @@ def run_build # commands to run cmds = " /bin/bash -c 'cd /root/pgpm/source" - cmds += " && dpkg-buildpackage --build=source" + cmds += " && dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error cmds += " && fakeroot pbuilder build ../#{dsc_fn}" cmds += " && mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/'" puts " Creating and starting container #{@container_name} & running pbuilder" + puts "podman run -it #{create_opts} #{cmds}" system("podman run -it #{create_opts} #{cmds}") exit(1) if $?.to_i > 0 end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index 3c26420..b558321 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -31,7 +31,7 @@ def dependencies def build_dependencies deps = case @os when "debian", "ubunut" - ["openssl-dev", "cmake"] + ["libssl-dev", "cmake"] when "rocky", "redhat", "fedora" ["openssl-devel", "cmake"] end @@ -43,7 +43,7 @@ def build_info when "debian", "ubuntu" { rules: "override_dh_auto_configure:\n" + - " dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" + "\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" } when "rocky", "redhat", "fedora" { From 3b02c92324b39699bcef9b553a3aa3c201fa9517 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 07:33:18 +0000 Subject: [PATCH 18/43] Proper changelog template for pbuilder packaging --- lib/pgpm/deb/templates/changelog.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index 06dabac..21617e3 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -1,5 +1,5 @@ <%= self.package.name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium - * Initial release. (Closes: #nnnn) + * Version <%= source_version %> package release. - -- PGPM Debian maintainer Fri, 21 Feb 2025 21:08:08 +0000 + -- PGPM Debian maintainer <%= Time.now.to_s %> From 0a84b1d99eefaa9982198dd81b1931b28e228153 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 8 Mar 2025 08:24:48 +0000 Subject: [PATCH 19/43] Assign .os and .postgres_major_version to @package in Pgpm::RPM::Spec constructor --- lib/pgpm/rpm/spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pgpm/rpm/spec.rb b/lib/pgpm/rpm/spec.rb index f078265..41df174 100644 --- a/lib/pgpm/rpm/spec.rb +++ b/lib/pgpm/rpm/spec.rb @@ -9,10 +9,15 @@ class Spec attr_reader :package, :release, :postgres_version, :postgres_distribution def initialize(package) + @postgres_distribution = Pgpm::Postgres::Distribution.in_scope @package = package @release = 1 - @postgres_distribution = Pgpm::Postgres::Distribution.in_scope + # Needed in order to return correct dependencies for the selected + # version of postgres and selected OS. + @package = package + @package.os = "redhat" + @package.postgres_major_version = @postgres_distribution.version.split(".")[0] end def versionless From d39f047024ff91c923da921bac6464c479aa7111 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 9 Mar 2025 05:44:49 +0000 Subject: [PATCH 20/43] Refactor: simpler way to extract postgres major version --- lib/pgpm/deb/spec.rb | 2 +- lib/pgpm/rpm/spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index d3860fa..06c85f6 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -12,7 +12,7 @@ class Spec def initialize(package) @postgres_distribution = Pgpm::Postgres::Distribution.in_scope @package = package - @package.postgres_major_version = @postgres_distribution.version.split(".")[0] + @package.postgres_major_version = @postgres_distribution.major_version @package.os = "debian" @release = 1 end diff --git a/lib/pgpm/rpm/spec.rb b/lib/pgpm/rpm/spec.rb index 41df174..ef90613 100644 --- a/lib/pgpm/rpm/spec.rb +++ b/lib/pgpm/rpm/spec.rb @@ -17,7 +17,7 @@ def initialize(package) # version of postgres and selected OS. @package = package @package.os = "redhat" - @package.postgres_major_version = @postgres_distribution.version.split(".")[0] + @package.postgres_major_version = @postgres_distribution.major_version end def versionless From 164cc590c74763320dbc200dfd5ff1da7ba04852 Mon Sep 17 00:00:00 2001 From: qount25 Date: Mon, 10 Mar 2025 06:06:22 +0000 Subject: [PATCH 21/43] Add Dockerfile to build Debian images --- lib/pgpm/deb/Dockerfile | 31 +++++++++++++++++++++++++ lib/pgpm/deb/builder.rb | 2 +- lib/pgpm/deb/pbuilder_install_script.sh | 21 +++++++++++++++++ lib/pgpm/deb/templates/changelog.erb | 2 +- lib/pgpm/package/dependencies.rb | 2 -- 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 lib/pgpm/deb/Dockerfile create mode 100644 lib/pgpm/deb/pbuilder_install_script.sh diff --git a/lib/pgpm/deb/Dockerfile b/lib/pgpm/deb/Dockerfile new file mode 100644 index 0000000..72b18ec --- /dev/null +++ b/lib/pgpm/deb/Dockerfile @@ -0,0 +1,31 @@ +# syntax = docker/dockerfile:experimental + +# IMPORTANT: build it this way to allow for privileged execution +# +# Docker daemon config should have the entitlement +# ```json +# { "builder": {"Entitlements": {"security-insecure": true }} } +# ``` +# ``` +# DOCKER_BUILDKIT=1 docker build --allow security.insecure -t IMAGE_NAME /path/to/pgpm +# ``` + +# This Dockerfile is used to build a Debian image, which includes pbuilder and +# pbuilder chroot image with basic dependendencies needed for building most +# packages already pre-installed. + +FROM docker.io/library/debian + +MAINTAINER PGPM Debian Maintainer debian.maintainer@postgres.pm + +VOLUME /proc +ARG DEBIAN_FRONTEND=noninteractive +RUN apt update +RUN apt install -y build-essential pbuilder fakeroot fakechroot +RUN echo 'MIRRORSITE=http://deb.debian.org/debian' > /etc/pbuilderrc +RUN echo 'AUTO_DEBSIGN=${AUTO_DEBSIGN:-no}' > /root/.pbuilderrc +RUN echo 'HOOKDIR=/var/cache/pbuilder/hooks' >> /root/.pbuilderrc +RUN --security=insecure pbuilder create # --components "main contrib-non-free" + +COPY pbuilder_install_script.sh /root/pbuilder_install_script.sh +RUN --security=insecure pbuilder execute --save-after-exec /root/pbuilder_install_script.sh diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index e9b6a56..66a8c49 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -61,7 +61,7 @@ def run_build # podman run options create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? - create_opts += " --privileged" + create_opts += " --privileged --tmpfs /tmp" #--privileged --cap-add=sys_admin --security-opt label:disable -v /proc:/proc create_opts += " --name #{@container_name} #{image_name}" dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" diff --git a/lib/pgpm/deb/pbuilder_install_script.sh b/lib/pgpm/deb/pbuilder_install_script.sh new file mode 100644 index 0000000..484850f --- /dev/null +++ b/lib/pgpm/deb/pbuilder_install_script.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +apt update +DEBIAN_FRONTEND=noninteractive apt -y install build-essential curl lsb-release ca-certificates + +### PostgreSQL installation +# +install -d /usr/share/postgresql-common/pgdg +curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc + +# Create the repository configuration file: +sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + +# Update the package lists: +apt update + +# Install the latest version of PostgreSQL: +# If you want a specific version, use 'postgresql-16' or similar instead of 'postgresql' +apt -y install postgresql-17 postgresql-server-dev-17 postgresql-common +# +### END OF PostgreSQL installation + diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index 21617e3..3982661 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -2,4 +2,4 @@ * Version <%= source_version %> package release. - -- PGPM Debian maintainer <%= Time.now.to_s %> + -- PGPM Debian maintainer <%= Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')%> diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index b39b259..ade6d98 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -10,7 +10,6 @@ def build_dependencies case @os when "debian", "ubuntu" [ - "postgresql-#{postgres_major_version}", "build-essential", "postgresql-#{postgres_major_version}", "postgresql-server-dev-#{postgres_major_version}", @@ -18,7 +17,6 @@ def build_dependencies ] when "rocky", "redhat", "fedora" [ - "postgresql-#{postgres_major_version}", "build-essential", "postgresql-#{postgres_major_version}", "postgresql-server-devel-#{postgres_major_version}", From 3122b37b8897f209d8238be4ef1ddba670b82873 Mon Sep 17 00:00:00 2001 From: qount25 Date: Tue, 11 Mar 2025 04:39:00 +0000 Subject: [PATCH 22/43] Run build commands in podman through `podman exec` so later failed container build can be inspected --- lib/pgpm/deb/builder.rb | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 66a8c49..8a427af 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -58,25 +58,32 @@ def generate_deb_src_files end def run_build - # podman run options + # podman create options create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? - create_opts += " --privileged --tmpfs /tmp" #--privileged --cap-add=sys_admin --security-opt label:disable -v /proc:/proc + create_opts += " --privileged --tmpfs /tmp" create_opts += " --name #{@container_name} #{image_name}" dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" deb_fn = "#{@spec.full_pkg_name}.deb" - # commands to run - cmds = " /bin/bash -c 'cd /root/pgpm/source" - cmds += " && dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error - cmds += " && fakeroot pbuilder build ../#{dsc_fn}" - cmds += " && mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/'" - puts " Creating and starting container #{@container_name} & running pbuilder" - puts "podman run -it #{create_opts} #{cmds}" - system("podman run -it #{create_opts} #{cmds}") + system("podman create -it #{create_opts}") + exit(1) if $?.to_i > 0 + system("podman start #{@container_name}") exit(1) if $?.to_i > 0 + + cmds = [] + cmds << "dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error + cmds << "fakeroot pbuilder build ../#{dsc_fn}" + cmds << "mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/" + + puts " Building package with pbuilder..." + cmds.each do |cmd| + system("podman exec -w /root/pgpm/source #{@container_name} /bin/bash -c '#{cmd}'") + exit(1) if $?.to_i > 0 + end + end def copy_build_from_container @@ -88,7 +95,8 @@ def copy_build_from_container def cleanup puts "Cleaning up..." - puts " Destroying podman container: #{@container_name}" + puts " Stopping destroying podman container: #{@container_name}" + system("podman container stop #{@container_name}") system("podman container rm #{@container_name}") # Remove temporary files From a1ca04615b08286e88039bec696c9364ac3ea35b Mon Sep 17 00:00:00 2001 From: qount25 Date: Tue, 11 Mar 2025 06:11:55 +0000 Subject: [PATCH 23/43] Patch pbuilder for before running it: prevent cleanup --- lib/pgpm/deb/Dockerfile | 2 +- lib/pgpm/deb/builder.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pgpm/deb/Dockerfile b/lib/pgpm/deb/Dockerfile index 72b18ec..46a9940 100644 --- a/lib/pgpm/deb/Dockerfile +++ b/lib/pgpm/deb/Dockerfile @@ -25,7 +25,7 @@ RUN apt install -y build-essential pbuilder fakeroot fakechroot RUN echo 'MIRRORSITE=http://deb.debian.org/debian' > /etc/pbuilderrc RUN echo 'AUTO_DEBSIGN=${AUTO_DEBSIGN:-no}' > /root/.pbuilderrc RUN echo 'HOOKDIR=/var/cache/pbuilder/hooks' >> /root/.pbuilderrc -RUN --security=insecure pbuilder create # --components "main contrib-non-free" +RUN --security=insecure pbuilder create COPY pbuilder_install_script.sh /root/pbuilder_install_script.sh RUN --security=insecure pbuilder execute --save-after-exec /root/pbuilder_install_script.sh diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 8a427af..5e71bb0 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -74,6 +74,19 @@ def run_build exit(1) if $?.to_i > 0 cmds = [] + + # This line prevents clean-up after pbuilder finishes. There's no option + # in pbuilder to do it, so we have to patch it manually. The issue is + # with pbuilder not being able to delete some directories (presumably, + # due to directory names starting with ".") and returning error. + # + # This little patch avoids the error by returning from the python cleanup + # function early -- because the package itself is built successfully and + # we don't actually care that pbuilder is unable to clean something up. + # The container is going to be removed anyway, so it's even less work as + # a result. + cmds << "sed -E -i \"s/(^function clean_subdirectories.*$)/\\1\\n return/g\" /usr/lib/pbuilder/pbuilder-modules" + cmds << "dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error cmds << "fakeroot pbuilder build ../#{dsc_fn}" cmds << "mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/" From 0b62193c5e1e31dd8a53f7e27a56f3179a1e9e47 Mon Sep 17 00:00:00 2001 From: qount25 Date: Tue, 11 Mar 2025 07:18:18 +0000 Subject: [PATCH 24/43] Fix: use Pgpm::OS.in_scope to determine OS name at the package level --- exe/pgpm | 2 +- lib/pgpm/deb/spec.rb | 1 - lib/pgpm/package/building.rb | 4 ++-- lib/pgpm/package/dependencies.rb | 8 ++++---- lib/pgpm/package/packaging.rb | 2 -- lib/pgpm/rpm/spec.rb | 2 -- packages/timescale/timescaledb.rb | 8 ++++---- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/exe/pgpm b/exe/pgpm index 8bbc46e..8072c18 100755 --- a/exe/pgpm +++ b/exe/pgpm @@ -118,7 +118,7 @@ module Pgpm end p = Pgpm::ScopedObject.new(p, os, arch) spec = p.to_rpm_spec - builder = Pgpm::RedHat::Builder.new(spec) + builder = Pgpm::RPM::Builder.new(spec) src_builder = builder.source_builder p = c.nil? ? src_builder : c.and_then(src_builder) p.and_then(builder.versionless_builder) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 06c85f6..85eec86 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -13,7 +13,6 @@ def initialize(package) @postgres_distribution = Pgpm::Postgres::Distribution.in_scope @package = package @package.postgres_major_version = @postgres_distribution.major_version - @package.os = "debian" @release = 1 end diff --git a/lib/pgpm/package/building.rb b/lib/pgpm/package/building.rb index 64c5851..cdf134a 100644 --- a/lib/pgpm/package/building.rb +++ b/lib/pgpm/package/building.rb @@ -8,10 +8,10 @@ def configure_steps end def build_info - case @os + case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" { rules: "" } - when "rocky", "redhat", "fedora" + when "rocky+epel-9", "redhat", "fedora" { build_steps: [], install_steps: [] } end end diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index ade6d98..a61df7f 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -7,7 +7,7 @@ module Dependencies attr_accessor :postgres_major_version def build_dependencies - case @os + case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" [ "build-essential", @@ -15,7 +15,7 @@ def build_dependencies "postgresql-server-dev-#{postgres_major_version}", "postgresql-common" ] - when "rocky", "redhat", "fedora" + when "rocky+epel-9", "redhat", "fedora" [ "build-essential", "postgresql-#{postgres_major_version}", @@ -26,10 +26,10 @@ def build_dependencies end def dependencies - case @os + case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" [ "postgresql-#{postgres_major_version}" ] - when "rocky", "redhat", "fedora" + when "rocky+epel-9", "redhat", "fedora" [ "postgresql-#{postgres_major_version}" ] end end diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index 3c799ee..3bf04d1 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -4,8 +4,6 @@ module Pgpm class Package module Packaging - attr_accessor :os - def to_rpm_spec(**opts) Pgpm::RPM::Spec.new(self, **opts) end diff --git a/lib/pgpm/rpm/spec.rb b/lib/pgpm/rpm/spec.rb index ef90613..631cb47 100644 --- a/lib/pgpm/rpm/spec.rb +++ b/lib/pgpm/rpm/spec.rb @@ -15,8 +15,6 @@ def initialize(package) # Needed in order to return correct dependencies for the selected # version of postgres and selected OS. - @package = package - @package.os = "redhat" @package.postgres_major_version = @postgres_distribution.major_version end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index b558321..c822573 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -29,23 +29,23 @@ def dependencies end def build_dependencies - deps = case @os + deps = case Pgpm::OS.in_scope.class.name when "debian", "ubunut" ["libssl-dev", "cmake"] - when "rocky", "redhat", "fedora" + when "rocky+epel-9", "redhat", "fedora" ["openssl-devel", "cmake"] end super + deps end def build_info - case @os + case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" { rules: "override_dh_auto_configure:\n" + "\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" } - when "rocky", "redhat", "fedora" + when "rocky+epel-9", "redhat", "fedora" { build_steps: [ "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", From 0e9ce561cb659b83d254e425247e4fadf75b641f Mon Sep 17 00:00:00 2001 From: qount25 Date: Tue, 11 Mar 2025 07:22:46 +0000 Subject: [PATCH 25/43] Remove 'require "debug"' --- exe/pgpm | 2 -- 1 file changed, 2 deletions(-) diff --git a/exe/pgpm b/exe/pgpm index 8072c18..53de466 100755 --- a/exe/pgpm +++ b/exe/pgpm @@ -8,8 +8,6 @@ require "dry/cli" require "parallel" require "etc" -require "debug" - module Pgpm module CLI module Commands From f2339f8a4bb482ae3b91f312b6231f272864dada Mon Sep 17 00:00:00 2001 From: qount25 Date: Wed, 12 Mar 2025 11:48:33 +0000 Subject: [PATCH 26/43] Refactor: use @spec.sources to download and extract sources when building deb This is instead of copying repository into the container. --- lib/pgpm/deb/builder.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 5e71bb0..5e9d18f 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "debug" + module Pgpm module Deb class Builder @@ -31,8 +33,32 @@ def prepare @pgpm_dir = Dir.mktmpdir Dir.mkdir "#{@pgpm_dir}/source" Dir.mkdir "#{@pgpm_dir}/out" - puts " Copying #{@spec.package.source.to_s} to #{@pgpm_dir}/source/" - FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/" + + puts " Downloading and unpacking sources to #{@pgpm_dir}" + + fn = nil + @spec.sources.map do |src| + srcfile = File.join("#{@pgpm_dir}", src.name) + File.write(srcfile, src.read) + fn = src.name + end + + system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source/") + FileUtils.remove("#{@pgpm_dir}/#{fn}") + + untar_dir_entries = Dir.entries("#{@pgpm_dir}/source/").select do |entry| + !([".", ".."].include?(entry)) + end + + if untar_dir_entries.size == 1 + entry = untar_dir_entries[0] + if File.directory?("#{@pgpm_dir}/source/#{entry}") + FileUtils.mv "#{@pgpm_dir}/source/#{entry}", "#{@pgpm_dir}/" + FileUtils.remove_dir "#{@pgpm_dir}/source/" + FileUtils.mv "#{@pgpm_dir}/#{entry}", "#{@pgpm_dir}/source" + end + end + end def pull_image From 71bcfdd34822cc47caaa35887be0a9c154faba69 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 15 Mar 2025 17:00:11 +0000 Subject: [PATCH 27/43] Rename & package versioned files into a DEB package, assign proper package name --- lib/pgpm/deb/builder.rb | 22 ++-- lib/pgpm/deb/scripts/pg_config.sh | 21 ++++ lib/pgpm/deb/scripts/prepare_artifacts.sh | 132 ++++++++++++++++++++++ lib/pgpm/deb/spec.rb | 4 +- lib/pgpm/deb/templates/changelog.erb | 2 +- lib/pgpm/deb/templates/control.erb | 4 +- lib/pgpm/deb/templates/copyright.erb | 2 +- lib/pgpm/deb/templates/files.erb | 2 +- lib/pgpm/deb/templates/rules.erb | 13 +++ 9 files changed, 185 insertions(+), 17 deletions(-) create mode 100644 lib/pgpm/deb/scripts/pg_config.sh create mode 100644 lib/pgpm/deb/scripts/prepare_artifacts.sh diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 5e9d18f..45f5173 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -17,7 +17,7 @@ def build pull_image run_build copy_build_from_container - cleanup + #cleanup end private @@ -59,6 +59,11 @@ def prepare end end + ["prepare_artifacts.sh", "pg_config.sh"].each do |fn| + script_fn = File.expand_path("#{__dir__}/scripts/#{fn}") + FileUtils.cp script_fn, "#{@pgpm_dir}/source/" + end + end def pull_image @@ -90,8 +95,8 @@ def run_build create_opts += " --privileged --tmpfs /tmp" create_opts += " --name #{@container_name} #{image_name}" - dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc" - deb_fn = "#{@spec.full_pkg_name}.deb" + dsc_fn = "#{@spec.deb_pkg_name}_0-1.dsc" + deb_fn = "#{@spec.deb_pkg_name}_0-1_#{@spec.arch}.deb" puts " Creating and starting container #{@container_name} & running pbuilder" system("podman create -it #{create_opts}") @@ -126,9 +131,10 @@ def run_build end def copy_build_from_container - puts "Moving .deb file from podman container into current directory..." - deb_fn = "#{@spec.full_pkg_name}.deb" - FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd) + puts "Copying .deb file from podman container into current directory..." + deb_fn = "#{@spec.deb_pkg_name}_0-1_#{@spec.arch}.deb" + deb_copy_fn = "#{@spec.deb_pkg_name}_#{@spec.arch}.deb" + FileUtils.cp("#{@pgpm_dir}/out/#{deb_fn}", "#{Dir.pwd}/#{deb_copy_fn}") end def cleanup @@ -158,10 +164,6 @@ def selinux_enabled? system("sestatus | grep 'SELinux status' | grep -o 'enabled'") end - def safe_package_name - @spec.package.name.gsub(%r{/}, "__") - end - end end end diff --git a/lib/pgpm/deb/scripts/pg_config.sh b/lib/pgpm/deb/scripts/pg_config.sh new file mode 100644 index 0000000..391bf29 --- /dev/null +++ b/lib/pgpm/deb/scripts/pg_config.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env bash + +# Ensure PG_CONFIG is set +if [[ -z "$PG_CONFIG" ]]; then + echo "Error: PG_CONFIG is not set." + exit 1 +fi + +# Wrapper function for pg_config +pg_config_wrapper() { + "$PG_CONFIG" "$@" | while read -r line; do + if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then + echo "$PGPM_BUILDROOT$line" + else + echo "$line" + fi + done +} + +# Call the wrapper function with the arguments passed to the script +pg_config_wrapper "$@" diff --git a/lib/pgpm/deb/scripts/prepare_artifacts.sh b/lib/pgpm/deb/scripts/prepare_artifacts.sh new file mode 100644 index 0000000..fb1f1e2 --- /dev/null +++ b/lib/pgpm/deb/scripts/prepare_artifacts.sh @@ -0,0 +1,132 @@ +#! /usr/bin/env bash + +#set -xe + +new_extension_so= + +echo $PGPM_BUILDROOT +echo $PGPM_EXTENSION_NAME +echo $PGPM_EXTENSION_VERSION +PG_CONFIG="pg_config" +echo "pg_config: $(which pg_config)" +echo "pg_config sharedir: $(pg_config --sharedir)" + +for file in $(find $PGPM_BUILDROOT -name '*.so'); do + filename=$(basename "$file") + if [[ "$filename" == "${PGPM_EXTENSION_NAME}.so" ]]; then + extension_so=$filename + dir=$(dirname "$file") + extension_dirname=${dir#"$PGPM_BUILDROOT"} + new_extension_so=$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.so + break + fi +done + +extdir=$PGPM_BUILDDEB$($PG_CONFIG --sharedir)/extension + +# control files +default_control=$extdir/$PGPM_EXTENSION_NAME.control +versioned_control=$extdir/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.control +controls=("$default_control" "$versioned_control") + +echo "PWD: $(pwd)" + +echo "----------------------" +echo "extension_dirname: $extension_dirname" +echo "new_extension_so: $new_extension_so" +echo "default_control: $default_control" +echo "versioned_control: $versioned_control" +echo "extension_so: $extension_so" +echo "extdir: $extdir" +echo "PGPM_BUILDDEB: $PGPM_BUILDDEB" +echo "----------------------" + +echo "CONTROLS CONTENTS" +echo "-----------------" +echo "DEFAULT CONTROL:" +cat $default_control +echo "\nVERSIONED CONTROL:" +cat $versioned_control +echo "-----------------" + +if [[ -n "$new_extension_so" ]]; then + + mv "$PGPM_BUILDDEB$extension_dirname/$extension_so" "$PGPM_BUILDDEB$extension_dirname/$new_extension_so" + + echo "CHANGING EXTENSION NAME IN CONTROLS" + echo "-----------------------------------" + # Change the extension name in controls + for control in "${controls[@]}"; do + if [[ -f "$control" ]]; then + echo "$control" + # extension.so + sed -i "s|${extension_so}'|${new_extension_so}'|g" "$control" + # extension + sed -i "s|${extension_so%".so"}'|${new_extension_so%".so"}'|g" "$control" + fi + done + echo "-----------------------------------" + + # sql files + echo "SQL FILES" + echo "---------" + for sql_file in $(find $PGPM_BUILDDEB -name '*.sql' -type f); do + echo "$sql_file" + # extension.so + sed -i "s|/${extension_so}'|/${new_extension_so}'|g" "$sql_file" + # extension + sed -i "s|/${extension_so%".so"}'|/${new_extension_so}'|g" "$sql_file" + done + echo "---------" + + # bitcode + + pkglibdir=$PGPM_BUILDDEB$($PG_CONFIG --pkglibdir) + + bitcode_extension=$pkglibdir/bitcode/${extension_so%".so"} + bitcode_index=$pkglibdir/bitcode/${extension_so%".so"}.index.bc + + echo "BITCODE" + echo "-------" + if [[ -d "${bitcode_extension}" ]]; then + echo "$bitcode_extension" + mv "$bitcode_extension" "$pkglibdir/bitcode/${new_extension_so%".so"}" + fi + + if [[ -f "${bitcode_index}" ]]; then + echo "$bitcode_index" + mv "${bitcode_index}" "$pkglibdir/bitcode/${new_extension_so%".so"}.index.bc" + fi + echo "-------" + + # includes + includedir=$PGPM_BUILDDEB$($PG_CONFIG --includedir-server) + + echo "INCLUDES" + echo "--------" + if [[ -d "${includedir}/extension/$PGPM_EXTENSION_NAME" ]]; then + echo "$includedir" + versioned_dir=${includedir}/extension/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION + mkdir -p "$versioned_dir" + mv "${includedir}/extension/$PGPM_EXTENSION_NAME" "$versioned_dir" + fi + echo "--------" + + # TODO: share, docs, etc. + +fi + + +# Make sure we don't build a default control as it belongs +# to another package +if [[ -f "$default_control" ]]; then + if [[ -f "$versioned_control" ]]; then + # We don't need default control if versioned is present + rm -f "$default_control" + else + # Default becomes versioned + mv "$default_control" "$versioned_control" + # Don't need default_version + sed -i '/default_version/d' "$versioned_control" + fi +fi diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 85eec86..9855db9 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -31,8 +31,8 @@ def source_version @package.version.to_s end - def full_pkg_name - "#{@package.name}-#{@package.version.to_s}_0-1_#{arch}" + def deb_pkg_name + "#{@package.name}+#{@package.version.to_s}-pg#{@package.postgres_major_version}" end def arch diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index 3982661..953f5bb 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -1,4 +1,4 @@ -<%= self.package.name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium +<%= deb_pkg_name %> (0-1) UNRELEASED; urgency=medium * Version <%= source_version %> package release. diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index 42234ef..3dc744a 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -1,4 +1,4 @@ -Source: <%= self.package.name %>-<%= source_version %> +Source: <%= deb_pkg_name %> Description: <%= self.package.description %> Section: libs Priority: optional @@ -7,7 +7,7 @@ Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), <%= self.package.build_dependencies.join(", ") %> Standards-Version: 4.6.2 -Package: <%= self.package.name %>-<%= source_version %> +Package: <%= deb_pkg_name %> Depends: <%= self.package.dependencies.join(", ") %> Section: libdevel Architecture: <%= arch %> diff --git a/lib/pgpm/deb/templates/copyright.erb b/lib/pgpm/deb/templates/copyright.erb index 42a9127..aa7b533 100644 --- a/lib/pgpm/deb/templates/copyright.erb +++ b/lib/pgpm/deb/templates/copyright.erb @@ -1,6 +1,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Source: -Upstream-Name: <%= self.package.name %>-<%= self.package.name %> +Upstream-Name: <%= self.package.name %>-<%= self.package.version.to_s %> Upstream-Contact: Files: diff --git a/lib/pgpm/deb/templates/files.erb b/lib/pgpm/deb/templates/files.erb index 78cbdbb..b06eb05 100644 --- a/lib/pgpm/deb/templates/files.erb +++ b/lib/pgpm/deb/templates/files.erb @@ -1 +1 @@ -<%= self.package.name %>-<%= source_version %>_0-1_source.buildinfo libs optional +<%= deb_pkg_name %>_source.buildinfo libs optional diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index d923f32..2d6f2ac 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -14,8 +14,21 @@ # Package maintainers to append LDFLAGS. #export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed +DEB_BUILDDIR ?= $(CURDIR) %: dh $@ +override_dh_install: + dh_install + chmod +x "$(DEB_BUILDDIR)/prepare_artifacts.sh" + chmod +x "$(DEB_BUILDDIR)/pg_config.sh" + find $(DEB_BUILDDIR) -type f | sort - | sed 's|^$(DEB_BUILDDIR)||' > .pgpm_before | sort + export PG_CONFIG="$(DEB_BUILDDIR)/pg_config.sh"; \ + export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ + export PGPM_EXTENSION_NAME="<%= self.package.extension_name %>"; \ + export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ + export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name %>"; \ + ./prepare_artifacts.sh + <%= self.package.build_info[:rules] %> From cb58e0a174e83b6e66c045456a999bcd8846a236 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sun, 16 Mar 2025 18:16:23 +0000 Subject: [PATCH 28/43] Create second .deb package (default) which depends on the versioned package in Pgpm::Deb::Builder --- lib/pgpm/deb/builder.rb | 124 ++++++++++++------ .../deb/scripts/install_default_control.sh | 12 ++ lib/pgpm/deb/scripts/pg_config.sh | 21 --- lib/pgpm/deb/spec.rb | 13 +- lib/pgpm/deb/templates/changelog.erb | 4 +- lib/pgpm/deb/templates/control.erb | 6 +- lib/pgpm/deb/templates/files.erb | 2 +- lib/pgpm/deb/templates/rules.erb | 42 +++--- 8 files changed, 134 insertions(+), 90 deletions(-) create mode 100644 lib/pgpm/deb/scripts/install_default_control.sh delete mode 100644 lib/pgpm/deb/scripts/pg_config.sh diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index 45f5173..dd65d18 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -9,15 +9,25 @@ class Builder def initialize(spec) @spec = spec @container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10000)}" + @pgpm_dir = Dir.mktmpdir end def build - prepare - generate_deb_src_files pull_image - run_build - copy_build_from_container - #cleanup + start_container + patch_pbuilder + + prepare_versioned_source + generate_deb_src_files(:versioned) + run_build(:versioned) + copy_build_from_container(:versioned) + + prepare_default_source + generate_deb_src_files(:default) + run_build(:default) + copy_build_from_container(:default) + + cleanup end private @@ -27,11 +37,10 @@ def image_name "quay.io/qount25/pgpm-debian-pg#{@spec.package.postgres_major_version}-#{@spec.arch}" end - def prepare + def prepare_versioned_source puts "Preparing build..." puts " Creating container dir structure..." - @pgpm_dir = Dir.mktmpdir - Dir.mkdir "#{@pgpm_dir}/source" + Dir.mkdir "#{@pgpm_dir}/source-versioned" Dir.mkdir "#{@pgpm_dir}/out" puts " Downloading and unpacking sources to #{@pgpm_dir}" @@ -43,29 +52,57 @@ def prepare fn = src.name end - system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source/") + system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source-versioned/") FileUtils.remove("#{@pgpm_dir}/#{fn}") - untar_dir_entries = Dir.entries("#{@pgpm_dir}/source/").select do |entry| + untar_dir_entries = Dir.entries("#{@pgpm_dir}/source-versioned/").select do |entry| !([".", ".."].include?(entry)) end if untar_dir_entries.size == 1 entry = untar_dir_entries[0] - if File.directory?("#{@pgpm_dir}/source/#{entry}") - FileUtils.mv "#{@pgpm_dir}/source/#{entry}", "#{@pgpm_dir}/" - FileUtils.remove_dir "#{@pgpm_dir}/source/" - FileUtils.mv "#{@pgpm_dir}/#{entry}", "#{@pgpm_dir}/source" + if File.directory?("#{@pgpm_dir}/source-versioned/#{entry}") + FileUtils.mv "#{@pgpm_dir}/source-versioned/#{entry}", "#{@pgpm_dir}/" + FileUtils.remove_dir "#{@pgpm_dir}/source-versioned/" + FileUtils.mv "#{@pgpm_dir}/#{entry}", "#{@pgpm_dir}/source-versioned" end end - ["prepare_artifacts.sh", "pg_config.sh"].each do |fn| + ["prepare_artifacts.sh"].each do |fn| script_fn = File.expand_path("#{__dir__}/scripts/#{fn}") - FileUtils.cp script_fn, "#{@pgpm_dir}/source/" + FileUtils.cp script_fn, "#{@pgpm_dir}/source-versioned/" end end + def prepare_default_source + Dir.mkdir "#{@pgpm_dir}/source-default" + + # 1. All pbuilder builds are in /var/cache/pbuilder/build. At this point + # there's only one build, but we don't know what the directory is named + # (the name is usually some numbers). So we just pick the first (and only) + # entry at this location and this is our build dir. + pbuilds_dir = "/var/cache/pbuilder/build" + cmd = "ls -U #{pbuilds_dir} | head -1" + build_dir = `podman exec #{@container_name} /bin/bash -c '#{cmd}'`.strip + puts "BUILD DIR IS: #{pbuilds_dir}/#{build_dir}" + + # 2. Determine the name of the .control file inside the versioned build + deb_dir = "#{pbuilds_dir}/#{build_dir}/build/#{@spec.deb_pkg_name(:versioned)}-0/debian/#{@spec.deb_pkg_name(:versioned)}" + control_fn = "#{deb_dir}/usr/share/postgresql/#{@spec.package.postgres_major_version}/extension/#{@spec.package.extension_name}--#{@spec.package.version}.control" + + # 3. Copy .control file to the source-default dir + puts "Copying #{control_fn} into /root/pgpm/source-default/" + target_control_fn = "/root/pgpm/source-default/#{@spec.package.extension_name}.control" + cmd = "cp #{control_fn} #{target_control_fn}" + system("podman exec #{@container_name} /bin/bash -c '#{cmd}'") + + ["install_default_control.sh"].each do |fn| + script_fn = File.expand_path("#{__dir__}/scripts/#{fn}") + FileUtils.cp script_fn, "#{@pgpm_dir}/source-default/" + end + end + def pull_image puts "Checking if podman image exists..." # Check if image exists @@ -78,62 +115,65 @@ def pull_image end end - def generate_deb_src_files + def generate_deb_src_files(pkg_type=:versioned) puts "Generating debian files..." - Dir.mkdir "#{@pgpm_dir}/source/debian" + Dir.mkdir "#{@pgpm_dir}/source-#{pkg_type}/debian" [:changelog, :control, :copyright, :files, :rules].each do |f| - puts " -> #{@pgpm_dir}/source/debian/#{f}" - File.write "#{@pgpm_dir}/source/debian/#{f}", @spec.generate(f) + puts " -> #{@pgpm_dir}/source-#{pkg_type}/debian/#{f}" + File.write "#{@pgpm_dir}/source-#{pkg_type}/debian/#{f}", @spec.generate(f, pkg_type) end - File.chmod 0740, "#{@pgpm_dir}/source/debian/rules" # rules file must be executable + File.chmod 0740, "#{@pgpm_dir}/source-#{pkg_type}/debian/rules" # rules file must be executable end - def run_build + def start_container # podman create options create_opts = " -v #{@pgpm_dir}:/root/pgpm" create_opts += ":z" if selinux_enabled? create_opts += " --privileged --tmpfs /tmp" create_opts += " --name #{@container_name} #{image_name}" - dsc_fn = "#{@spec.deb_pkg_name}_0-1.dsc" - deb_fn = "#{@spec.deb_pkg_name}_0-1_#{@spec.arch}.deb" - puts " Creating and starting container #{@container_name} & running pbuilder" system("podman create -it #{create_opts}") exit(1) if $?.to_i > 0 system("podman start #{@container_name}") exit(1) if $?.to_i > 0 + end - cmds = [] + # Prevents clean-up after pbuilder finishes. There's no option + # in pbuilder to do it, so we have to patch it manually. The issue is + # with pbuilder not being able to delete some directories (presumably, + # due to directory names starting with ".") and returning error. + # + # This little patch avoids the error by returning from the python cleanup + # function early -- because the package itself is built successfully and + # we don't actually care that pbuilder is unable to clean something up. + # The container is going to be removed anyway, so it's even less work as + # a result. + def patch_pbuilder + cmd = "sed -E -i \"s/(^function clean_subdirectories.*$)/\\1\\n return/g\" /usr/lib/pbuilder/pbuilder-modules" + system("podman exec #{@container_name} /bin/bash -c '#{cmd}'") + end - # This line prevents clean-up after pbuilder finishes. There's no option - # in pbuilder to do it, so we have to patch it manually. The issue is - # with pbuilder not being able to delete some directories (presumably, - # due to directory names starting with ".") and returning error. - # - # This little patch avoids the error by returning from the python cleanup - # function early -- because the package itself is built successfully and - # we don't actually care that pbuilder is unable to clean something up. - # The container is going to be removed anyway, so it's even less work as - # a result. - cmds << "sed -E -i \"s/(^function clean_subdirectories.*$)/\\1\\n return/g\" /usr/lib/pbuilder/pbuilder-modules" + def run_build(pkg_type=:versioned) + dsc_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1.dsc" + deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb" + cmds = [] cmds << "dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error cmds << "fakeroot pbuilder build ../#{dsc_fn}" cmds << "mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/" puts " Building package with pbuilder..." cmds.each do |cmd| - system("podman exec -w /root/pgpm/source #{@container_name} /bin/bash -c '#{cmd}'") + system("podman exec -w /root/pgpm/source-#{pkg_type} #{@container_name} /bin/bash -c '#{cmd}'") exit(1) if $?.to_i > 0 end - end - def copy_build_from_container + def copy_build_from_container(pkg_type=:versioned) puts "Copying .deb file from podman container into current directory..." - deb_fn = "#{@spec.deb_pkg_name}_0-1_#{@spec.arch}.deb" - deb_copy_fn = "#{@spec.deb_pkg_name}_#{@spec.arch}.deb" + deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb" + deb_copy_fn = "#{@spec.deb_pkg_name(pkg_type)}_#{@spec.arch}.deb" FileUtils.cp("#{@pgpm_dir}/out/#{deb_fn}", "#{Dir.pwd}/#{deb_copy_fn}") end diff --git a/lib/pgpm/deb/scripts/install_default_control.sh b/lib/pgpm/deb/scripts/install_default_control.sh new file mode 100644 index 0000000..e6a3184 --- /dev/null +++ b/lib/pgpm/deb/scripts/install_default_control.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +ext_dir="$PGPM_BUILDDEB/$(pg_config --sharedir)/extension" +control_fn="$ext_dir/$PGPM_EXTENSION_NAME.control" + +echo "Creating extension dir: $ext_dir" +mkdir -p "$ext_dir" + +echo "Creating control file: $control_fn" +cp "$PGPM_BUILDROOT/$PGPM_EXTENSION_NAME.control" "$ext_dir/" +echo >> "$control_fn" +echo "default_version = '$PGPM_EXTENSION_VERSION'" >> "$control_fn" diff --git a/lib/pgpm/deb/scripts/pg_config.sh b/lib/pgpm/deb/scripts/pg_config.sh deleted file mode 100644 index 391bf29..0000000 --- a/lib/pgpm/deb/scripts/pg_config.sh +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/env bash - -# Ensure PG_CONFIG is set -if [[ -z "$PG_CONFIG" ]]; then - echo "Error: PG_CONFIG is not set." - exit 1 -fi - -# Wrapper function for pg_config -pg_config_wrapper() { - "$PG_CONFIG" "$@" | while read -r line; do - if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then - echo "$PGPM_BUILDROOT$line" - else - echo "$line" - fi - done -} - -# Call the wrapper function with the arguments passed to the script -pg_config_wrapper "$@" diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 9855db9..8a7fa27 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -20,10 +20,13 @@ def sources @package.sources end - def generate(template_name) + def generate(template_name, pkg_type=:versioned) fn = "#{__dir__}/templates/#{template_name}.erb" raise "No such template: #{fn}" unless File.exist?(fn) erb = ERB.new(File.read(fn)) + + # Uses pkg_type parameter (which is in scope) to generate + # debian/* files for versionless and main packages. erb.result(binding) end @@ -31,8 +34,12 @@ def source_version @package.version.to_s end - def deb_pkg_name - "#{@package.name}+#{@package.version.to_s}-pg#{@package.postgres_major_version}" + def deb_pkg_name(type=:versioned) + if type == :versioned + "#{@package.name}+#{@package.version.to_s}-pg#{@package.postgres_major_version}" + else + "#{@package.name}-pg#{@package.postgres_major_version}" + end end def arch diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index 953f5bb..c7ab1b0 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -1,5 +1,5 @@ -<%= deb_pkg_name %> (0-1) UNRELEASED; urgency=medium +<%= deb_pkg_name(pkg_type) %> (0-1) UNRELEASED; urgency=medium - * Version <%= source_version %> package release. + * Version <%= pkg_type == :versioned ? 1 : source_version %> package release. -- PGPM Debian maintainer <%= Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')%> diff --git a/lib/pgpm/deb/templates/control.erb b/lib/pgpm/deb/templates/control.erb index 3dc744a..54f6fff 100644 --- a/lib/pgpm/deb/templates/control.erb +++ b/lib/pgpm/deb/templates/control.erb @@ -1,4 +1,4 @@ -Source: <%= deb_pkg_name %> +Source: <%= deb_pkg_name(pkg_type) %> Description: <%= self.package.description %> Section: libs Priority: optional @@ -7,8 +7,8 @@ Rules-Requires-Root: no Build-Depends: debhelper-compat (= 13), <%= self.package.build_dependencies.join(", ") %> Standards-Version: 4.6.2 -Package: <%= deb_pkg_name %> -Depends: <%= self.package.dependencies.join(", ") %> +Package: <%= deb_pkg_name(pkg_type) %> +Depends: <%= pkg_type == :versioned ? self.package.dependencies.join(", ") : deb_pkg_name(:versioned) %> Section: libdevel Architecture: <%= arch %> Description: <%= self.package.description %> diff --git a/lib/pgpm/deb/templates/files.erb b/lib/pgpm/deb/templates/files.erb index b06eb05..af64618 100644 --- a/lib/pgpm/deb/templates/files.erb +++ b/lib/pgpm/deb/templates/files.erb @@ -1 +1 @@ -<%= deb_pkg_name %>_source.buildinfo libs optional +<%= deb_pkg_name(pkg_type) %>_source.buildinfo libs optional diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index 2d6f2ac..c3a89f5 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -1,34 +1,40 @@ #!/usr/bin/make -f -# See debhelper(7) (uncomment to enable). -# Output every command that modifies files on the build system. -#export DH_VERBOSE = 1 - - -# See FEATURE AREAS in dpkg-buildflags(1). -#export DEB_BUILD_MAINT_OPTIONS = hardening=+all - -# See ENVIRONMENT in dpkg-buildflags(1). -# Package maintainers to append CFLAGS. -#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic -# Package maintainers to append LDFLAGS. -#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed - DEB_BUILDDIR ?= $(CURDIR) +EXTENSION_NAME ?= "<%= self.package.extension_name %>" +<% if pkg_type == :versioned %> %: dh $@ override_dh_install: dh_install chmod +x "$(DEB_BUILDDIR)/prepare_artifacts.sh" - chmod +x "$(DEB_BUILDDIR)/pg_config.sh" find $(DEB_BUILDDIR) -type f | sort - | sed 's|^$(DEB_BUILDDIR)||' > .pgpm_before | sort - export PG_CONFIG="$(DEB_BUILDDIR)/pg_config.sh"; \ + export PG_CONFIG="which pg_config"; \ export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ - export PGPM_EXTENSION_NAME="<%= self.package.extension_name %>"; \ + export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ - export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name %>"; \ + export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ ./prepare_artifacts.sh <%= self.package.build_info[:rules] %> + +<% else %> +%: + dh $@ + +build: + # Custom build commands + echo " --> BUILD" + +install: + echo " --> INSTALL" + chmod +x "$(DEB_BUILDDIR)/install_default_control.sh" + export PG_CONFIG="which pg_config"; \ + export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ + export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ + export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ + export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ + ./install_default_control.sh +<% end %> From 8de62ed0e657e1b4cdeed17396f248d992007f8e Mon Sep 17 00:00:00 2001 From: qount25 Date: Mon, 17 Mar 2025 17:52:42 +0000 Subject: [PATCH 29/43] Refactor: prepare_artifacts in deb/ --- .../deb/scripts/install_default_control.sh | 2 +- lib/pgpm/deb/scripts/prepare_artifacts.sh | 118 ++++++++---------- lib/pgpm/deb/templates/rules.erb | 4 +- pgpm.gemspec | 49 -------- 4 files changed, 56 insertions(+), 117 deletions(-) delete mode 100644 pgpm.gemspec diff --git a/lib/pgpm/deb/scripts/install_default_control.sh b/lib/pgpm/deb/scripts/install_default_control.sh index e6a3184..c4ca5b8 100644 --- a/lib/pgpm/deb/scripts/install_default_control.sh +++ b/lib/pgpm/deb/scripts/install_default_control.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -ext_dir="$PGPM_BUILDDEB/$(pg_config --sharedir)/extension" +ext_dir="${PGPM_INSTALL_ROOT:-$PGPM_BUILDROOT}/$(pg_config --sharedir)/extension" control_fn="$ext_dir/$PGPM_EXTENSION_NAME.control" echo "Creating extension dir: $ext_dir" diff --git a/lib/pgpm/deb/scripts/prepare_artifacts.sh b/lib/pgpm/deb/scripts/prepare_artifacts.sh index fb1f1e2..b7f2609 100644 --- a/lib/pgpm/deb/scripts/prepare_artifacts.sh +++ b/lib/pgpm/deb/scripts/prepare_artifacts.sh @@ -4,12 +4,14 @@ new_extension_so= -echo $PGPM_BUILDROOT -echo $PGPM_EXTENSION_NAME -echo $PGPM_EXTENSION_VERSION -PG_CONFIG="pg_config" -echo "pg_config: $(which pg_config)" -echo "pg_config sharedir: $(pg_config --sharedir)" +PG_CONFIG="${PG_CONFIG:-"pg_config"}" + +# When building with pbuilder on Debian, files are installed under +# `$PGPM_BUILDROOT/debian/ext-name-0.0.0/` -- this path should then be +# assigned to the PGPM_INSTALL_ROOT env variable. However it isn't assigned +# to it (as is the case with rpm and mock), then we use PGPM_BUILDROOT instead. +# In this script we're +install_root="${PGPM_INSTALL_ROOT:-$PGPM_BUILDROOT}" for file in $(find $PGPM_BUILDROOT -name '*.so'); do filename=$(basename "$file") @@ -22,40 +24,21 @@ for file in $(find $PGPM_BUILDROOT -name '*.so'); do fi done -extdir=$PGPM_BUILDDEB$($PG_CONFIG --sharedir)/extension +extdir=$install_root$($PG_CONFIG --sharedir)/extension # control files default_control=$extdir/$PGPM_EXTENSION_NAME.control versioned_control=$extdir/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.control controls=("$default_control" "$versioned_control") -echo "PWD: $(pwd)" - -echo "----------------------" -echo "extension_dirname: $extension_dirname" -echo "new_extension_so: $new_extension_so" -echo "default_control: $default_control" -echo "versioned_control: $versioned_control" -echo "extension_so: $extension_so" -echo "extdir: $extdir" -echo "PGPM_BUILDDEB: $PGPM_BUILDDEB" -echo "----------------------" - -echo "CONTROLS CONTENTS" -echo "-----------------" -echo "DEFAULT CONTROL:" -cat $default_control -echo "\nVERSIONED CONTROL:" -cat $versioned_control -echo "-----------------" - -if [[ -n "$new_extension_so" ]]; then - - mv "$PGPM_BUILDDEB$extension_dirname/$extension_so" "$PGPM_BUILDDEB$extension_dirname/$new_extension_so" +function rename_so() { + mv "$install_root$extension_dirname/$extension_so" \ + "$install_root$extension_dirname/$new_extension_so" +} - echo "CHANGING EXTENSION NAME IN CONTROLS" - echo "-----------------------------------" - # Change the extension name in controls +function change_name_in_controls() { + echo "CHANGING EXTENSION NAME IN CONTROL FILES" + echo "----------------------------------------" for control in "${controls[@]}"; do if [[ -f "$control" ]]; then echo "$control" @@ -65,29 +48,28 @@ if [[ -n "$new_extension_so" ]]; then sed -i "s|${extension_so%".so"}'|${new_extension_so%".so"}'|g" "$control" fi done - echo "-----------------------------------" +} - # sql files - echo "SQL FILES" - echo "---------" - for sql_file in $(find $PGPM_BUILDDEB -name '*.sql' -type f); do +function rename_sql_files() { + echo "RENAMING EXTENSION SQL FILES" + echo "----------------------------" + for sql_file in $(find $install_root -name '*.sql' -type f); do echo "$sql_file" # extension.so sed -i "s|/${extension_so}'|/${new_extension_so}'|g" "$sql_file" # extension sed -i "s|/${extension_so%".so"}'|/${new_extension_so}'|g" "$sql_file" done - echo "---------" +} - # bitcode - - pkglibdir=$PGPM_BUILDDEB$($PG_CONFIG --pkglibdir) +function rename_bitcode() { + echo "RENAMING BITCODE" + echo "----------------" + pkglibdir=$install_root$($PG_CONFIG --pkglibdir) bitcode_extension=$pkglibdir/bitcode/${extension_so%".so"} bitcode_index=$pkglibdir/bitcode/${extension_so%".so"}.index.bc - echo "BITCODE" - echo "-------" if [[ -d "${bitcode_extension}" ]]; then echo "$bitcode_extension" mv "$bitcode_extension" "$pkglibdir/bitcode/${new_extension_so%".so"}" @@ -97,36 +79,42 @@ if [[ -n "$new_extension_so" ]]; then echo "$bitcode_index" mv "${bitcode_index}" "$pkglibdir/bitcode/${new_extension_so%".so"}.index.bc" fi - echo "-------" - - # includes - includedir=$PGPM_BUILDDEB$($PG_CONFIG --includedir-server) +} - echo "INCLUDES" - echo "--------" +function rename_includes() { + includedir=$install_root$($PG_CONFIG --includedir-server) + echo "RENAMING INCLUDES" + echo "-----------------" if [[ -d "${includedir}/extension/$PGPM_EXTENSION_NAME" ]]; then echo "$includedir" versioned_dir=${includedir}/extension/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION mkdir -p "$versioned_dir" mv "${includedir}/extension/$PGPM_EXTENSION_NAME" "$versioned_dir" fi - echo "--------" - - # TODO: share, docs, etc. - -fi - +} # Make sure we don't build a default control as it belongs # to another package -if [[ -f "$default_control" ]]; then - if [[ -f "$versioned_control" ]]; then - # We don't need default control if versioned is present - rm -f "$default_control" - else - # Default becomes versioned - mv "$default_control" "$versioned_control" - # Don't need default_version - sed -i '/default_version/d' "$versioned_control" +function handle_default_control() { + if [[ -f "$default_control" ]]; then + if [[ -f "$versioned_control" ]]; then + # We don't need default control if versioned is present + rm -f "$default_control" + else + # Default becomes versioned + mv "$default_control" "$versioned_control" + # Don't need default_version + sed -i '/default_version/d' "$versioned_control" + fi fi +} + +if [[ -n "$new_extension_so" ]]; then + rename_so + change_name_in_controls + rename_sql_files + rename_bitcode + rename_incluides fi + +handle_default_control diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index c3a89f5..d25069f 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -15,7 +15,7 @@ override_dh_install: export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ - export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ + export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ ./prepare_artifacts.sh <%= self.package.build_info[:rules] %> @@ -35,6 +35,6 @@ install: export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ - export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ + export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ ./install_default_control.sh <% end %> diff --git a/pgpm.gemspec b/pgpm.gemspec deleted file mode 100644 index eb7262e..0000000 --- a/pgpm.gemspec +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -require_relative "lib/pgpm/version" - -Gem::Specification.new do |spec| - spec.name = "pgpm" - spec.version = Pgpm::VERSION - spec.authors = ["Yurii Rashkovskii"] - spec.email = ["yrashk@gmail.com"] - - spec.summary = "Postgres Package Manager" - spec.homepage = "https://postgres.pm" - spec.license = "Apache-2.0" - spec.required_ruby_version = ">= 3.3.0" - - # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/postgres-pm/postgres-om" - # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." - - # Specify which files should be added to the gem when it is released. - spec.files = Dir.glob(["exe/*", "lib/**/**", "sig/**/**"]) - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] - - # Uncomment to register a new dependency of your gem - # spec.add_dependency "example-gem", "~> 1.0" - - spec.add_dependency "dry-cli", "~> 1.1.0" - spec.add_dependency "dry-inflector", "~> 1.1.0" - spec.add_dependency "git", "~> 2.3.0" - spec.add_dependency "lspace", "~> 0.14" - spec.add_dependency "minitar", "~> 1.0.2" - spec.add_dependency "nokogiri", "~> 1.16" - spec.add_dependency "oj", "~> 3.16.6" - spec.add_dependency "parallel", "~> 1.26.3" - spec.add_dependency "perfect_toml", "~> 0.9.0" - spec.add_dependency "progress", "~> 3.6.0" - spec.add_dependency "semver_dialects", "~> 3.4.3" - spec.add_dependency "tty-command", "~> 0.10.1" - spec.add_dependency "xdg", [">= 8.7.0", "< 10"] - spec.add_dependency "zeitwerk", "~> 2.6.18" - spec.add_dependency "zlib", "~> 3.1.1" - - # For more information and examples about making a new gem, check out our - # guide at: https://bundler.io/guides/creating_gem.html -end From 7b2aee872150b8e27ea9f04c79148da0e1f4ece8 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 20 Mar 2025 20:11:55 +0000 Subject: [PATCH 30/43] Restore accidentally deleted pgpm.spec --- pgpm.gemspec | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 pgpm.gemspec diff --git a/pgpm.gemspec b/pgpm.gemspec new file mode 100644 index 0000000..eb7262e --- /dev/null +++ b/pgpm.gemspec @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative "lib/pgpm/version" + +Gem::Specification.new do |spec| + spec.name = "pgpm" + spec.version = Pgpm::VERSION + spec.authors = ["Yurii Rashkovskii"] + spec.email = ["yrashk@gmail.com"] + + spec.summary = "Postgres Package Manager" + spec.homepage = "https://postgres.pm" + spec.license = "Apache-2.0" + spec.required_ruby_version = ">= 3.3.0" + + # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/postgres-pm/postgres-om" + # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." + + # Specify which files should be added to the gem when it is released. + spec.files = Dir.glob(["exe/*", "lib/**/**", "sig/**/**"]) + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + # Uncomment to register a new dependency of your gem + # spec.add_dependency "example-gem", "~> 1.0" + + spec.add_dependency "dry-cli", "~> 1.1.0" + spec.add_dependency "dry-inflector", "~> 1.1.0" + spec.add_dependency "git", "~> 2.3.0" + spec.add_dependency "lspace", "~> 0.14" + spec.add_dependency "minitar", "~> 1.0.2" + spec.add_dependency "nokogiri", "~> 1.16" + spec.add_dependency "oj", "~> 3.16.6" + spec.add_dependency "parallel", "~> 1.26.3" + spec.add_dependency "perfect_toml", "~> 0.9.0" + spec.add_dependency "progress", "~> 3.6.0" + spec.add_dependency "semver_dialects", "~> 3.4.3" + spec.add_dependency "tty-command", "~> 0.10.1" + spec.add_dependency "xdg", [">= 8.7.0", "< 10"] + spec.add_dependency "zeitwerk", "~> 2.6.18" + spec.add_dependency "zlib", "~> 3.1.1" + + # For more information and examples about making a new gem, check out our + # guide at: https://bundler.io/guides/creating_gem.html +end From 775da7cf503a3723a4228f8dd92c43c98108fbc0 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 20 Mar 2025 20:12:07 +0000 Subject: [PATCH 31/43] Use configure_steps, make_steps & install_steps instead of build_info in Pgpm::Deb::Spec templates --- lib/pgpm/deb/templates/rules.erb | 19 ++++++++++++++----- lib/pgpm/package/building.rb | 9 --------- lib/pgpm/package/make.rb | 19 +++++++++++++++---- packages/timescale/timescaledb.rb | 26 ++++++++++++-------------- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index d25069f..a5b91ce 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -18,16 +18,25 @@ override_dh_install: export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ ./prepare_artifacts.sh -<%= self.package.build_info[:rules] %> +<% if self.package.configure_steps.size > 0 %> +override_dh_auto_configure: + <%= self.package.configure_steps.join("\n\t") %> +<% end %> + +<% if self.package.build_steps.size > 0 %> +override_dh_build: + <%= self.package.build_steps.join("\n\t") %> +<% end %> + +<% if self.package.install_steps.size > 0 %> +override_dh_install: + <%= self.package.install_steps.join("\n\t") %> +<% end %> <% else %> %: dh $@ -build: - # Custom build commands - echo " --> BUILD" - install: echo " --> INSTALL" chmod +x "$(DEB_BUILDDIR)/install_default_control.sh" diff --git a/lib/pgpm/package/building.rb b/lib/pgpm/package/building.rb index cdf134a..e7eb06d 100644 --- a/lib/pgpm/package/building.rb +++ b/lib/pgpm/package/building.rb @@ -7,15 +7,6 @@ def configure_steps [] end - def build_info - case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - { rules: "" } - when "rocky+epel-9", "redhat", "fedora" - { build_steps: [], install_steps: [] } - end - end - def source_url_directory_name nil end diff --git a/lib/pgpm/package/make.rb b/lib/pgpm/package/make.rb index dbe38c1..59b4e82 100644 --- a/lib/pgpm/package/make.rb +++ b/lib/pgpm/package/make.rb @@ -3,21 +3,32 @@ module Pgpm class Package module Make - def build_steps - return [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present? + def build_steps + case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + return [] + when "rocky+epel-9", "redhat", "fedora" + return [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present? + end super end def install_steps - return [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_BUILDROOT", "PG_CONFIG=$PG_CONFIG")] if makefile_present? - + case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + return [] + when "rocky+epel-9", "redhat", "fedora" + return [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_BUILDROOT", "PG_CONFIG=$PG_CONFIG")] if makefile_present? + end super end def makefile_present? !Dir.glob(%w[Makefile GNUmakefile makefile], base: source.to_s).empty? end + end + end end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index c822573..8d45458 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -38,23 +38,21 @@ def build_dependencies super + deps end - def build_info + def configure_steps case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" - { - rules: "override_dh_auto_configure:\n" + - "\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\"" - } + ["dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\""] when "rocky+epel-9", "redhat", "fedora" - { - build_steps: [ - "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", - "cmake --build build --parallel" - ], - install_steps: [ - "DESTDIR=$PGPM_BUILDROOT cmake --build build --target install" - ] - } + [] + end + end + + def install_steps + case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + [] + when "rocky+epel-9", "redhat", "fedora" + ["DESTDIR=$PGPM_BUILDROOT cmake --build build --target install"] end end From 4bd0cbf63894606dbc678894057801ee6150fc98 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 20 Mar 2025 20:15:04 +0000 Subject: [PATCH 32/43] Remove build-essential from the list of default build dependencies --- lib/pgpm/package/dependencies.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index 17d22d0..be114d4 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -10,14 +10,12 @@ def build_dependencies case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" [ - "build-essential", "postgresql-#{postgres_major_version}", "postgresql-server-dev-#{postgres_major_version}", "postgresql-common" ] when "rocky+epel-9", "redhat", "fedora" [ - "build-essential", "postgresql-#{postgres_major_version}", "postgresql-server-devel-#{postgres_major_version}", "postgresql-common" From a99f00b3f8a41419908012d60bba6b4166618c49 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 20 Mar 2025 20:27:13 +0000 Subject: [PATCH 33/43] Accept a larger diversity of filenames for License --- lib/pgpm/package/pgxn.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/pgpm/package/pgxn.rb b/lib/pgpm/package/pgxn.rb index a50c868..23991e7 100644 --- a/lib/pgpm/package/pgxn.rb +++ b/lib/pgpm/package/pgxn.rb @@ -59,9 +59,13 @@ def license def license_text path = "#{self.source.to_s}" - ["LICENSE", "license", "License"].each do |fn| - if File.exist?("#{path}/#{fn}") - return File.read("#{path}/#{fn}") + ["license", "lisence", "unlicense", "unlisence", "copying"].each do |fn| + [fn, fn.capitalize, fn.upcase].each do |fn2| + ["", ".txt", ".md"].each do |fn3| + if File.exist?("#{path}/#{fn2}#{fn3}") + return File.read("#{path}/#{fn2}#{fn3}") + end + end end end nil From 2a4a708b22e459b8b83d73d9b576ca35cb2468f9 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 21 Mar 2025 13:36:42 +0000 Subject: [PATCH 34/43] Oops: spelling of "ubuntu" --- packages/timescale/timescaledb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index 8d45458..aba547b 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -30,7 +30,7 @@ def dependencies def build_dependencies deps = case Pgpm::OS.in_scope.class.name - when "debian", "ubunut" + when "debian", "ubuntu" ["libssl-dev", "cmake"] when "rocky+epel-9", "redhat", "fedora" ["openssl-devel", "cmake"] From e14be75e6ceba831e7875c08db3ea6ca3a001164 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 21 Mar 2025 19:46:54 +0000 Subject: [PATCH 35/43] Use Package#native? as condition to add "build-essential" to build_dependencies --- lib/pgpm/package/dependencies.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index c99258a..fe774cc 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "tsort" +require "debug" module Pgpm class Package @@ -11,11 +12,15 @@ module Dependencies def build_dependencies case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" - [ + deps = [ "postgresql-#{postgres_major_version}", "postgresql-server-dev-#{postgres_major_version}", "postgresql-common" ] + if self.native? + binding.break + deps << "build-essential" + end when "rocky+epel-9", "redhat", "fedora" [ "postgresql-#{postgres_major_version}", From 8d0c1750d24a95307f32a83e6eb3bb8974ffc157 Mon Sep 17 00:00:00 2001 From: qount25 Date: Wed, 26 Mar 2025 03:17:30 +0000 Subject: [PATCH 36/43] Refactor: use completely customized debian rules file -- without calling `dh` in it (WIP) --- .../deb/scripts/install_default_control.sh | 2 +- lib/pgpm/deb/scripts/pg_config.sh | 21 ++++++ lib/pgpm/deb/scripts/prepare_artifacts.sh | 7 +- lib/pgpm/deb/templates/rules.erb | 65 ++++++++++--------- lib/pgpm/package/dependencies.rb | 1 - lib/pgpm/package/make.rb | 16 +---- lib/pgpm/rpm/scripts/pg_config.sh | 6 +- lib/pgpm/rpm/scripts/prepare_artifacts.sh | 16 ++--- lib/pgpm/rpm/spec.rb | 4 +- packages/omnigres/package.rb | 12 ++-- packages/timescale/timescaledb.rb | 2 +- 11 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 lib/pgpm/deb/scripts/pg_config.sh diff --git a/lib/pgpm/deb/scripts/install_default_control.sh b/lib/pgpm/deb/scripts/install_default_control.sh index c4ca5b8..4b66bbc 100644 --- a/lib/pgpm/deb/scripts/install_default_control.sh +++ b/lib/pgpm/deb/scripts/install_default_control.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -ext_dir="${PGPM_INSTALL_ROOT:-$PGPM_BUILDROOT}/$(pg_config --sharedir)/extension" +ext_dir="$PGPM_INSTALL_ROOT/$(pg_config --sharedir)/extension" control_fn="$ext_dir/$PGPM_EXTENSION_NAME.control" echo "Creating extension dir: $ext_dir" diff --git a/lib/pgpm/deb/scripts/pg_config.sh b/lib/pgpm/deb/scripts/pg_config.sh new file mode 100644 index 0000000..77fbe26 --- /dev/null +++ b/lib/pgpm/deb/scripts/pg_config.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env bash + +# Ensure PG_CONFIG is set +if [[ -z "$PG_CONFIG" ]]; then + echo "Error: PG_CONFIG is not set." + exit 1 +fi + +# Wrapper function for pg_config +pg_config_wrapper() { + "$PG_CONFIG" "$@" | while read -r line; do + if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then + echo "$PGPM_INSTALL_ROOT$line" + else + echo "$line" + fi + done +} + +# Call the wrapper function with the arguments passed to the script +pg_config_wrapper "$@" diff --git a/lib/pgpm/deb/scripts/prepare_artifacts.sh b/lib/pgpm/deb/scripts/prepare_artifacts.sh index b7f2609..f0e87f0 100644 --- a/lib/pgpm/deb/scripts/prepare_artifacts.sh +++ b/lib/pgpm/deb/scripts/prepare_artifacts.sh @@ -6,12 +6,7 @@ new_extension_so= PG_CONFIG="${PG_CONFIG:-"pg_config"}" -# When building with pbuilder on Debian, files are installed under -# `$PGPM_BUILDROOT/debian/ext-name-0.0.0/` -- this path should then be -# assigned to the PGPM_INSTALL_ROOT env variable. However it isn't assigned -# to it (as is the case with rpm and mock), then we use PGPM_BUILDROOT instead. -# In this script we're -install_root="${PGPM_INSTALL_ROOT:-$PGPM_BUILDROOT}" +install_root=$PGPM_INSTALL_ROOT for file in $(find $PGPM_BUILDROOT -name '*.so'); do filename=$(basename "$file") diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index a5b91ce..7a009f4 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -1,37 +1,45 @@ #!/usr/bin/make -f -DEB_BUILDDIR ?= $(CURDIR) -EXTENSION_NAME ?= "<%= self.package.extension_name %>" +export DEB_BUILDDIR = $(CURDIR) +export PGPM_BUILDROOT = $(CURDIR) +export PG_CONFIG = $(shell /usr/bin/which pg_config) +export PGPM_EXTENSION_NAME = "<%= self.package.extension_name %>" +export PGPM_EXTENSION_VERSION = "<%= self.package.version %>" +export PGPM_INSTALL_ROOT = "$(CURDIR)/debian/<%= deb_pkg_name(pkg_type) %>" <% if pkg_type == :versioned %> %: - dh $@ - -override_dh_install: - dh_install - chmod +x "$(DEB_BUILDDIR)/prepare_artifacts.sh" - find $(DEB_BUILDDIR) -type f | sort - | sed 's|^$(DEB_BUILDDIR)||' > .pgpm_before | sort - export PG_CONFIG="which pg_config"; \ - export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ - export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ - export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ - export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ + echo " --> % rules target" + +build: + echo " --> build target" + <%= self.package.build_steps.join("\n\t").gsub('$', '$$') %> + +install: build + mkdir -p $$PGPM_INSTALL_ROOT + echo " --> install target" + <%= self.package.install_steps.join("\n\t").gsub('$', '$$') %> + chmod +x "$$DEB_BUILDDIR/prepare_artifacts.sh" + find $$PGPM_INSTALL_ROOT -type f | sort - | sed 's|^$$PGPM_INSTALL_ROOT||' > .pgpm_before | sort ./prepare_artifacts.sh -<% if self.package.configure_steps.size > 0 %> -override_dh_auto_configure: - <%= self.package.configure_steps.join("\n\t") %> -<% end %> +build-arch: + echo " --> build-arch" -<% if self.package.build_steps.size > 0 %> -override_dh_build: - <%= self.package.build_steps.join("\n\t") %> -<% end %> +build-indep: + echo " --> build-indep" -<% if self.package.install_steps.size > 0 %> -override_dh_install: - <%= self.package.install_steps.join("\n\t") %> -<% end %> +binary: install + echo " --> binary" + +binary-arch: + echo " --> binary-arch" + +binary-indep: + echo " --> binary-indep" + +clean: + echo " --> clean" <% else %> %: @@ -39,11 +47,6 @@ override_dh_install: install: echo " --> INSTALL" - chmod +x "$(DEB_BUILDDIR)/install_default_control.sh" - export PG_CONFIG="which pg_config"; \ - export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \ - export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \ - export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \ - export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \ + chmod +x "$$DEB_BUILDDIR/install_default_control.sh" ./install_default_control.sh <% end %> diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index fe774cc..05f5806 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -18,7 +18,6 @@ def build_dependencies "postgresql-common" ] if self.native? - binding.break deps << "build-essential" end when "rocky+epel-9", "redhat", "fedora" diff --git a/lib/pgpm/package/make.rb b/lib/pgpm/package/make.rb index 59b4e82..f0ccb01 100644 --- a/lib/pgpm/package/make.rb +++ b/lib/pgpm/package/make.rb @@ -5,23 +5,13 @@ class Package module Make def build_steps - case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - return [] - when "rocky+epel-9", "redhat", "fedora" - return [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present? - end - super + [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present? end def install_steps - case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - return [] - when "rocky+epel-9", "redhat", "fedora" - return [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_BUILDROOT", "PG_CONFIG=$PG_CONFIG")] if makefile_present? + if makefile_present? + [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")] end - super end def makefile_present? diff --git a/lib/pgpm/rpm/scripts/pg_config.sh b/lib/pgpm/rpm/scripts/pg_config.sh index 06da6ae..77fbe26 100755 --- a/lib/pgpm/rpm/scripts/pg_config.sh +++ b/lib/pgpm/rpm/scripts/pg_config.sh @@ -1,7 +1,5 @@ #! /usr/bin/env bash -#!/bin/bash - # Ensure PG_CONFIG is set if [[ -z "$PG_CONFIG" ]]; then echo "Error: PG_CONFIG is not set." @@ -12,7 +10,7 @@ fi pg_config_wrapper() { "$PG_CONFIG" "$@" | while read -r line; do if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then - echo "$PGPM_BUILDROOT$line" + echo "$PGPM_INSTALL_ROOT$line" else echo "$line" fi @@ -20,4 +18,4 @@ pg_config_wrapper() { } # Call the wrapper function with the arguments passed to the script -pg_config_wrapper "$@" \ No newline at end of file +pg_config_wrapper "$@" diff --git a/lib/pgpm/rpm/scripts/prepare_artifacts.sh b/lib/pgpm/rpm/scripts/prepare_artifacts.sh index 7521c65..93bcff4 100755 --- a/lib/pgpm/rpm/scripts/prepare_artifacts.sh +++ b/lib/pgpm/rpm/scripts/prepare_artifacts.sh @@ -4,17 +4,17 @@ set -xe new_extension_so= -for file in $(find $PGPM_BUILDROOT -name '*.so'); do +for file in $(find $PGPM_INSTALL_ROOT -name '*.so'); do filename=$(basename "$file") if [[ "$filename" == "${PGPM_EXTENSION_NAME}.so" ]]; then extension_so=$filename dir=$(dirname "$file") - extension_dirname=${dir#"$PGPM_BUILDROOT"} + extension_dirname=${dir#"$PGPM_INSTALL_ROOT"} new_extension_so=$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.so fi done -extdir=$PGPM_BUILDROOT$($PG_CONFIG --sharedir)/extension +extdir=$PGPM_INSTALL_ROOT$($PG_CONFIG --sharedir)/extension # control files default_control=$extdir/$PGPM_EXTENSION_NAME.control @@ -24,7 +24,7 @@ controls=("$default_control" "$versioned_control") if [[ -n "$new_extension_so" ]]; then - mv "$PGPM_BUILDROOT$extension_dirname/$extension_so" "$PGPM_BUILDROOT$extension_dirname/$new_extension_so" + mv "$PGPM_INSTALL_ROOT$extension_dirname/$extension_so" "$PGPM_INSTALL_ROOT$extension_dirname/$new_extension_so" # Change the extension name in controls for control in "${controls[@]}"; do @@ -37,7 +37,7 @@ if [[ -n "$new_extension_so" ]]; then done # sql files - for sql_file in $(find $PGPM_BUILDROOT -name '*.sql' -type f); do + for sql_file in $(find $PGPM_INSTALL_ROOT -name '*.sql' -type f); do # extension.so sed -i "s|/${extension_so}'|/${new_extension_so}'|g" "$sql_file" # extension @@ -46,7 +46,7 @@ if [[ -n "$new_extension_so" ]]; then # bitcode - pkglibdir=$PGPM_BUILDROOT$($PG_CONFIG --pkglibdir) + pkglibdir=$PGPM_INSTALL_ROOT$($PG_CONFIG --pkglibdir) bitcode_extension=$pkglibdir/bitcode/${extension_so%".so"} bitcode_index=$pkglibdir/bitcode/${extension_so%".so"}.index.bc @@ -60,7 +60,7 @@ if [[ -n "$new_extension_so" ]]; then fi # includes - includedir=$PGPM_BUILDROOT$($PG_CONFIG --includedir-server) + includedir=$PGPM_INSTALL_ROOT$($PG_CONFIG --includedir-server) if [[ -d "${includedir}/extension/$PGPM_EXTENSION_NAME" ]]; then versioned_dir=${includedir}/extension/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION @@ -85,4 +85,4 @@ if [[ -f "$default_control" ]]; then # Don't need default_version sed -i '/default_version/d' "$versioned_control" fi -fi \ No newline at end of file +fi diff --git a/lib/pgpm/rpm/spec.rb b/lib/pgpm/rpm/spec.rb index c8fc644..fbc8aef 100644 --- a/lib/pgpm/rpm/spec.rb +++ b/lib/pgpm/rpm/spec.rb @@ -97,12 +97,12 @@ def to_s %build export PG_CONFIG=$(rpm -ql #{@postgres_distribution.pg_config_package} | grep 'pg_config$') - export PGPM_BUILDROOT=%{buildroot} + export PGPM_INSTALL_ROOT=%{buildroot} #{@package.build_steps.map(&:to_s).join("\n")} %install export PG_CONFIG=$(rpm -ql #{@postgres_distribution.pg_config_package} | grep 'pg_config$') - export PGPM_BUILDROOT=%{buildroot} + export PGPM_INSTALL_ROOT=%{buildroot} cp %{SOURCE#{sources.find_index { |src| src.name == "pg_config.sh" }}} ./pg_config.sh chmod +x ./pg_config.sh find %{buildroot} -type f | sort - | sed 's|^%{buildroot}||' > .pgpm_before | sort diff --git a/packages/omnigres/package.rb b/packages/omnigres/package.rb index ffa163b..c45575d 100644 --- a/packages/omnigres/package.rb +++ b/packages/omnigres/package.rb @@ -88,17 +88,17 @@ def build_steps def install_steps steps = [ - "mkdir -p $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension", - "mkdir -p $PGPM_BUILDROOT/$($PG_CONFIG --pkglibdir)", + "mkdir -p $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension", + "mkdir -p $PGPM_INSTALL_ROOT/$($PG_CONFIG --pkglibdir)", # Package .so artifacts - "find build/packaged -name '#{name}*.so' -type f -exec cp {} $PGPM_BUILDROOT/$($PG_CONFIG --pkglibdir) \\;", + "find build/packaged -name '#{name}*.so' -type f -exec cp {} $PGPM_INSTALL_ROOT/$($PG_CONFIG --pkglibdir) \\;", # Package version-specific control file - "cp build/packaged/extension/#{name}--#{version}.control $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension", + "cp build/packaged/extension/#{name}--#{version}.control $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension", # Package version-specific init file - "cp build/packaged/extension/#{name}--#{version}.sql $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension" + "cp build/packaged/extension/#{name}--#{version}.sql $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension" ] if previous_version && !previous_version.broken? && !@no_migration - steps.push("cp build/packaged/extension/#{name}--#{previous_version.version}--#{version}.sql $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension") + steps.push("cp build/packaged/extension/#{name}--#{previous_version.version}--#{version}.sql $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension") end steps end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index aba547b..ffe1a7b 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -52,7 +52,7 @@ def install_steps when "debian", "ubuntu" [] when "rocky+epel-9", "redhat", "fedora" - ["DESTDIR=$PGPM_BUILDROOT cmake --build build --target install"] + ["DESTDIR=$PGPM_INSTALL_ROOT cmake --build build --target install"] end end From 8eb2766763225ce03d26ab558161789d6d9b9496 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 27 Mar 2025 04:43:02 +0000 Subject: [PATCH 37/43] Fix: better way to handle custom configure, build and install steps in deb rules + timescaledb package custom configure/install steps --- lib/pgpm/deb/spec.rb | 10 ++++++++ lib/pgpm/deb/templates/rules.erb | 42 +++++++++++-------------------- packages/timescale/timescaledb.rb | 8 +++--- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 8a7fa27..5b52bc9 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -53,6 +53,16 @@ def arch end end + def cmds_if_not_empty(cmds, else_echo) + if cmds.nil? || cmds.empty? + return "\techo \"#{else_echo}\"" + else + cmds.map! { |c| c.to_s } + cmds.map! { |c| c.gsub("$", "$$") } + return cmds.join("\t") + end + end + end end end diff --git a/lib/pgpm/deb/templates/rules.erb b/lib/pgpm/deb/templates/rules.erb index 7a009f4..23c12f8 100644 --- a/lib/pgpm/deb/templates/rules.erb +++ b/lib/pgpm/deb/templates/rules.erb @@ -9,44 +9,32 @@ export PGPM_INSTALL_ROOT = "$(CURDIR)/debian/<%= deb_pkg_name(pkg_type) %>" <% if pkg_type == :versioned %> %: - echo " --> % rules target" + dh $@ + +override_dh_auto_configure: + echo " --> configuring" + <%= cmds_if_not_empty self.package.configure_steps, '...nothing to configure' %> -build: - echo " --> build target" - <%= self.package.build_steps.join("\n\t").gsub('$', '$$') %> +override_dh_auto_build: + echo " --> building" + <%= cmds_if_not_empty self.package.build_steps, '...nothing to build' %> -install: build - mkdir -p $$PGPM_INSTALL_ROOT - echo " --> install target" - <%= self.package.install_steps.join("\n\t").gsub('$', '$$') %> +override_dh_auto_install: + echo " --> installing" + dh_auto_install + <%= cmds_if_not_empty self.package.install_steps, '...no custom install steps' %> chmod +x "$$DEB_BUILDDIR/prepare_artifacts.sh" find $$PGPM_INSTALL_ROOT -type f | sort - | sed 's|^$$PGPM_INSTALL_ROOT||' > .pgpm_before | sort ./prepare_artifacts.sh -build-arch: - echo " --> build-arch" - -build-indep: - echo " --> build-indep" - -binary: install - echo " --> binary" - -binary-arch: - echo " --> binary-arch" - -binary-indep: - echo " --> binary-indep" - -clean: - echo " --> clean" - <% else %> %: dh $@ -install: +override_dh_auto_install: + dh_auto_install echo " --> INSTALL" chmod +x "$$DEB_BUILDDIR/install_default_control.sh" ./install_default_control.sh + <% end %> diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index ffe1a7b..609e41d 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -42,17 +42,17 @@ def configure_steps case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" ["dh_auto_configure -- -DCMAKE_BUILD_TYPE=\"Release\""] - when "rocky+epel-9", "redhat", "fedora" - [] + else + super end end def install_steps case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - [] when "rocky+epel-9", "redhat", "fedora" ["DESTDIR=$PGPM_INSTALL_ROOT cmake --build build --target install"] + else + super end end From 6fb0482bb939e275626206590dd5b9c960754a09 Mon Sep 17 00:00:00 2001 From: qount25 Date: Thu, 27 Mar 2025 05:05:45 +0000 Subject: [PATCH 38/43] Fix: timescaledb #build_steps method with custom steps for debian --- packages/timescale/timescaledb.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index 609e41d..ddd0f4f 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -47,6 +47,15 @@ def configure_steps end end + def build_steps + case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + ["dh_auto_build"] + else + super + end + end + def install_steps case Pgpm::OS.in_scope.class.name when "rocky+epel-9", "redhat", "fedora" From a9ac637674b6096b07223c766667cb6fc335aef5 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 28 Mar 2025 00:53:31 +0000 Subject: [PATCH 39/43] Fix: deb package names should not include _, replace them with - --- lib/pgpm/deb/spec.rb | 7 ++++--- lib/pgpm/deb/templates/changelog.erb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 5b52bc9..7fb874d 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -31,14 +31,15 @@ def generate(template_name, pkg_type=:versioned) end def source_version - @package.version.to_s + v = @package.version.to_s + v.match(/\Z\d+\.\d+\Z/) ? v + ".0" : v end def deb_pkg_name(type=:versioned) if type == :versioned - "#{@package.name}+#{@package.version.to_s}-pg#{@package.postgres_major_version}" + "#{@package.name.gsub("_", "-")}+#{source_version}-pg#{@package.postgres_major_version}" else - "#{@package.name}-pg#{@package.postgres_major_version}" + "#{@package.name.gsub("_", "-")}-pg#{@package.postgres_major_version}" end end diff --git a/lib/pgpm/deb/templates/changelog.erb b/lib/pgpm/deb/templates/changelog.erb index c7ab1b0..a09bdba 100644 --- a/lib/pgpm/deb/templates/changelog.erb +++ b/lib/pgpm/deb/templates/changelog.erb @@ -1,4 +1,4 @@ -<%= deb_pkg_name(pkg_type) %> (0-1) UNRELEASED; urgency=medium +<%= deb_pkg_name(pkg_type) %> (0-1) stable; urgency=medium * Version <%= pkg_type == :versioned ? 1 : source_version %> package release. From 7f4217c943552f04c17f546c0c5301701920371f Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 28 Mar 2025 00:54:48 +0000 Subject: [PATCH 40/43] Fix: os-specific dependency names for pgsodium package --- packages/pgsodium.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/pgsodium.rb b/packages/pgsodium.rb index bfac4e5..eb15526 100644 --- a/packages/pgsodium.rb +++ b/packages/pgsodium.rb @@ -4,11 +4,23 @@ class Pgsodium < Pgpm::Package github "michelp/pgsodium" def build_dependencies - super + ["libsodium-devel >= 1.0.18"] + deps = case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + ["libsodium-dev (>= 1.0.18)"] + when "rocky+epel-9", "redhat", "fedora" + ["libsodium-devel >= 1.0.18"] + end + super + deps end def dependencies - super + ["libsodium >= 1.0.18"] + deps = case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + ["libsodium (>= 1.0.18)"] + when "rocky+epel-9", "redhat", "fedora" + ["libsodium >= 1.0.18"] + end + super + deps end def broken? From d0a79077d26e52aa717f8a4c1e314c4154a721b9 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 28 Mar 2025 00:55:45 +0000 Subject: [PATCH 41/43] Oops: remove `require "debug"` --- lib/pgpm/package/dependencies.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index 05f5806..31907d8 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "tsort" -require "debug" module Pgpm class Package From 79e11728b5fbac97e0bba9fa82c4827edcd25f82 Mon Sep 17 00:00:00 2001 From: qount25 Date: Fri, 28 Mar 2025 02:13:42 +0000 Subject: [PATCH 42/43] Fix: remove default dependencies for rocky/redheat packages + update dependncies for rpm's side of timescaledb pkg --- lib/pgpm/package/dependencies.rb | 8 ++------ packages/timescale/timescaledb.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index 31907d8..ae01462 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -20,11 +20,7 @@ def build_dependencies deps << "build-essential" end when "rocky+epel-9", "redhat", "fedora" - [ - "postgresql-#{postgres_major_version}", - "postgresql-server-devel-#{postgres_major_version}", - "postgresql-common" - ] + [] end end @@ -33,7 +29,7 @@ def dependencies when "debian", "ubuntu" [ "postgresql-#{postgres_major_version}" ] when "rocky+epel-9", "redhat", "fedora" - [ "postgresql-#{postgres_major_version}" ] + [] end end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index ddd0f4f..0600201 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -25,7 +25,11 @@ def summary end def dependencies - super + deps = case Pgpm::OS.in_scope.class.name + when "rocky+epel-9", "redhat", "fedora" + ["openssl"] + end + super + deps end def build_dependencies @@ -51,8 +55,11 @@ def build_steps case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" ["dh_auto_build"] - else - super + when "rocky+epel-9", "redhat", "fedora" + [ + "./bootstrap -DPG_CONFIG=$PG_CONFIG #{bootstrap_flags.map { |f| "-D#{f}" }.join(" ")}", + "cmake --build build --parallel" + ] end end From 3073f73809a5ed9b61626b35de64ca42a28a3822 Mon Sep 17 00:00:00 2001 From: qount25 Date: Sat, 29 Mar 2025 03:24:34 +0000 Subject: [PATCH 43/43] Fixing rubocop issues --- exe/pgpm | 2 +- lib/pgpm/deb/builder.rb | 36 +++++++++++++++---------------- lib/pgpm/deb/spec.rb | 28 +++++++++++------------- lib/pgpm/os/debian.rb | 1 - lib/pgpm/package/dependencies.rb | 6 ++---- lib/pgpm/package/make.rb | 9 +++----- lib/pgpm/package/packaging.rb | 2 -- lib/pgpm/package/pgxn.rb | 5 ++--- packages/pgsodium.rb | 24 ++++++++++----------- packages/timescale/timescaledb.rb | 29 ++++++++++++------------- 10 files changed, 64 insertions(+), 78 deletions(-) diff --git a/exe/pgpm b/exe/pgpm index b05b331..dd6b974 100755 --- a/exe/pgpm +++ b/exe/pgpm @@ -109,7 +109,7 @@ module Pgpm arch.with_scope do selected_pgdist.with_scope do spec = nil - b = pkgs.reduce(nil) do |c, p| + pkgs.reduce(nil) do |_c, p| p = Pgpm::ScopedObject.new(p, os, arch) spec = p.to_deb_spec end diff --git a/lib/pgpm/deb/builder.rb b/lib/pgpm/deb/builder.rb index dd65d18..a036c8c 100644 --- a/lib/pgpm/deb/builder.rb +++ b/lib/pgpm/deb/builder.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true +require "English" require "debug" module Pgpm module Deb class Builder - def initialize(spec) @spec = spec - @container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10000)}" - @pgpm_dir = Dir.mktmpdir + @container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10_000)}" + @pgpm_dir = Dir.mktmpdir end def build @@ -47,7 +47,7 @@ def prepare_versioned_source fn = nil @spec.sources.map do |src| - srcfile = File.join("#{@pgpm_dir}", src.name) + srcfile = File.join(@pgpm_dir.to_s, src.name) File.write(srcfile, src.read) fn = src.name end @@ -55,8 +55,8 @@ def prepare_versioned_source system("tar -xf #{@pgpm_dir}/#{fn} -C #{@pgpm_dir}/source-versioned/") FileUtils.remove("#{@pgpm_dir}/#{fn}") - untar_dir_entries = Dir.entries("#{@pgpm_dir}/source-versioned/").select do |entry| - !([".", ".."].include?(entry)) + untar_dir_entries = Dir.entries("#{@pgpm_dir}/source-versioned/").reject do |entry| + [".", ".."].include?(entry) end if untar_dir_entries.size == 1 @@ -68,11 +68,10 @@ def prepare_versioned_source end end - ["prepare_artifacts.sh"].each do |fn| - script_fn = File.expand_path("#{__dir__}/scripts/#{fn}") + ["prepare_artifacts.sh"].each do |f| + script_fn = File.expand_path("#{__dir__}/scripts/#{f}") FileUtils.cp script_fn, "#{@pgpm_dir}/source-versioned/" end - end def prepare_default_source @@ -107,7 +106,7 @@ def pull_image puts "Checking if podman image exists..." # Check if image exists system("podman image exists #{image_name}") - if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository + if $CHILD_STATUS.to_i.positive? # image doesn't exist -- pull image from a remote repository puts " No. Pulling image #{image_name}..." system("podman pull #{image_name}") else @@ -115,14 +114,14 @@ def pull_image end end - def generate_deb_src_files(pkg_type=:versioned) + def generate_deb_src_files(pkg_type = :versioned) puts "Generating debian files..." Dir.mkdir "#{@pgpm_dir}/source-#{pkg_type}/debian" - [:changelog, :control, :copyright, :files, :rules].each do |f| + %i[changelog control copyright files rules].each do |f| puts " -> #{@pgpm_dir}/source-#{pkg_type}/debian/#{f}" File.write "#{@pgpm_dir}/source-#{pkg_type}/debian/#{f}", @spec.generate(f, pkg_type) end - File.chmod 0740, "#{@pgpm_dir}/source-#{pkg_type}/debian/rules" # rules file must be executable + File.chmod 0o740, "#{@pgpm_dir}/source-#{pkg_type}/debian/rules" # rules file must be executable end def start_container @@ -134,9 +133,9 @@ def start_container puts " Creating and starting container #{@container_name} & running pbuilder" system("podman create -it #{create_opts}") - exit(1) if $?.to_i > 0 + exit(1) if $CHILD_STATUS.to_i.positive? system("podman start #{@container_name}") - exit(1) if $?.to_i > 0 + exit(1) if $CHILD_STATUS.to_i.positive? end # Prevents clean-up after pbuilder finishes. There's no option @@ -154,7 +153,7 @@ def patch_pbuilder system("podman exec #{@container_name} /bin/bash -c '#{cmd}'") end - def run_build(pkg_type=:versioned) + def run_build(pkg_type = :versioned) dsc_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1.dsc" deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb" @@ -166,11 +165,11 @@ def run_build(pkg_type=:versioned) puts " Building package with pbuilder..." cmds.each do |cmd| system("podman exec -w /root/pgpm/source-#{pkg_type} #{@container_name} /bin/bash -c '#{cmd}'") - exit(1) if $?.to_i > 0 + exit(1) if $CHILD_STATUS.to_i.positive? end end - def copy_build_from_container(pkg_type=:versioned) + def copy_build_from_container(pkg_type = :versioned) puts "Copying .deb file from podman container into current directory..." deb_fn = "#{@spec.deb_pkg_name(pkg_type)}_0-1_#{@spec.arch}.deb" deb_copy_fn = "#{@spec.deb_pkg_name(pkg_type)}_#{@spec.arch}.deb" @@ -203,7 +202,6 @@ def selinux_enabled? # This returns true or false by itself system("sestatus | grep 'SELinux status' | grep -o 'enabled'") end - end end end diff --git a/lib/pgpm/deb/spec.rb b/lib/pgpm/deb/spec.rb index 7fb874d..c3356f6 100644 --- a/lib/pgpm/deb/spec.rb +++ b/lib/pgpm/deb/spec.rb @@ -20,9 +20,10 @@ def sources @package.sources end - def generate(template_name, pkg_type=:versioned) + def generate(template_name, pkg_type = :versioned) fn = "#{__dir__}/templates/#{template_name}.erb" raise "No such template: #{fn}" unless File.exist?(fn) + erb = ERB.new(File.read(fn)) # Uses pkg_type parameter (which is in scope) to generate @@ -32,10 +33,10 @@ def generate(template_name, pkg_type=:versioned) def source_version v = @package.version.to_s - v.match(/\Z\d+\.\d+\Z/) ? v + ".0" : v + v.match(/\Z\d+\.\d+\Z/) ? "#{v}.0" : v end - def deb_pkg_name(type=:versioned) + def deb_pkg_name(type = :versioned) if type == :versioned "#{@package.name.gsub("_", "-")}+#{source_version}-pg#{@package.postgres_major_version}" else @@ -47,23 +48,20 @@ def arch # https://memgraph.com/blog/ship-it-on-arm64-or-is-it-aarch64 # Debian suffixes are "amd64" and "arm64". Here we translate: case Pgpm::Arch.in_scope.name - when "amd64", "x86_64" - "amd64" - when "aarch64", "arm64" - "arm64" + when "amd64", "x86_64" + "amd64" + when "aarch64", "arm64" + "arm64" end end def cmds_if_not_empty(cmds, else_echo) - if cmds.nil? || cmds.empty? - return "\techo \"#{else_echo}\"" - else - cmds.map! { |c| c.to_s } - cmds.map! { |c| c.gsub("$", "$$") } - return cmds.join("\t") - end - end + return "\techo \"#{else_echo}\"" if cmds.nil? || cmds.empty? + cmds.map!(&:to_s) + cmds.map! { |c| c.gsub("$", "$$") } + cmds.join("\t") + end end end end diff --git a/lib/pgpm/os/debian.rb b/lib/pgpm/os/debian.rb index 885636b..c559a17 100644 --- a/lib/pgpm/os/debian.rb +++ b/lib/pgpm/os/debian.rb @@ -29,7 +29,6 @@ def self.builder def mock_config "debian-12-#{Pgpm::Arch.in_scope.name}+pgdg" end - end end end diff --git a/lib/pgpm/package/dependencies.rb b/lib/pgpm/package/dependencies.rb index ae01462..8869156 100644 --- a/lib/pgpm/package/dependencies.rb +++ b/lib/pgpm/package/dependencies.rb @@ -5,7 +5,6 @@ module Pgpm class Package module Dependencies - attr_accessor :postgres_major_version def build_dependencies @@ -16,7 +15,7 @@ def build_dependencies "postgresql-server-dev-#{postgres_major_version}", "postgresql-common" ] - if self.native? + if native? deps << "build-essential" end when "rocky+epel-9", "redhat", "fedora" @@ -27,7 +26,7 @@ def build_dependencies def dependencies case Pgpm::OS.in_scope.class.name when "debian", "ubuntu" - [ "postgresql-#{postgres_major_version}" ] + ["postgresql-#{postgres_major_version}"] when "rocky+epel-9", "redhat", "fedora" [] end @@ -71,7 +70,6 @@ def sorted_packages def c_files_present? Dir.glob("*.c", base: source).any? end - end end end diff --git a/lib/pgpm/package/make.rb b/lib/pgpm/package/make.rb index f0ccb01..24c758d 100644 --- a/lib/pgpm/package/make.rb +++ b/lib/pgpm/package/make.rb @@ -3,22 +3,19 @@ module Pgpm class Package module Make - def build_steps [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present? end def install_steps - if makefile_present? - [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")] - end + return unless makefile_present? + + [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")] end def makefile_present? !Dir.glob(%w[Makefile GNUmakefile makefile], base: source.to_s).empty? end - end - end end diff --git a/lib/pgpm/package/packaging.rb b/lib/pgpm/package/packaging.rb index 3bf04d1..c7fa0a9 100644 --- a/lib/pgpm/package/packaging.rb +++ b/lib/pgpm/package/packaging.rb @@ -3,7 +3,6 @@ module Pgpm class Package module Packaging - def to_rpm_spec(**opts) Pgpm::RPM::Spec.new(self, **opts) end @@ -11,7 +10,6 @@ def to_rpm_spec(**opts) def to_deb_spec(**opts) Pgpm::Deb::Spec.new(self, **opts) end - end end end diff --git a/lib/pgpm/package/pgxn.rb b/lib/pgpm/package/pgxn.rb index 23991e7..b7127f7 100644 --- a/lib/pgpm/package/pgxn.rb +++ b/lib/pgpm/package/pgxn.rb @@ -58,8 +58,8 @@ def license end def license_text - path = "#{self.source.to_s}" - ["license", "lisence", "unlicense", "unlisence", "copying"].each do |fn| + path = source.to_s + %w[license lisence unlicense unlisence copying].each do |fn| [fn, fn.capitalize, fn.upcase].each do |fn2| ["", ".txt", ".md"].each do |fn3| if File.exist?("#{path}/#{fn2}#{fn3}") @@ -70,7 +70,6 @@ def license_text end nil end - end end end diff --git a/packages/pgsodium.rb b/packages/pgsodium.rb index eb15526..b2af14b 100644 --- a/packages/pgsodium.rb +++ b/packages/pgsodium.rb @@ -4,22 +4,22 @@ class Pgsodium < Pgpm::Package github "michelp/pgsodium" def build_dependencies - deps = case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - ["libsodium-dev (>= 1.0.18)"] - when "rocky+epel-9", "redhat", "fedora" - ["libsodium-devel >= 1.0.18"] - end - super + deps + deps = case Pgpm::OS.in_scope.class.name + when "debian", "ubuntu" + ["libsodium-dev (>= 1.0.18)"] + when "rocky+epel-9", "redhat", "fedora" + ["libsodium-devel >= 1.0.18"] + end + super + deps end def dependencies deps = case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - ["libsodium (>= 1.0.18)"] - when "rocky+epel-9", "redhat", "fedora" - ["libsodium >= 1.0.18"] - end + when "debian", "ubuntu" + ["libsodium (>= 1.0.18)"] + when "rocky+epel-9", "redhat", "fedora" + ["libsodium >= 1.0.18"] + end super + deps end diff --git a/packages/timescale/timescaledb.rb b/packages/timescale/timescaledb.rb index 0600201..59f0d55 100644 --- a/packages/timescale/timescaledb.rb +++ b/packages/timescale/timescaledb.rb @@ -12,33 +12,33 @@ def self.package_versions end def description - "An open-source time-series SQL database optimized for fast ingest and " + - "complex queries" + "An open-source time-series SQL database optimized for fast ingest and " \ + "complex queries" end def summary - "TimescaleDB is an open-source database designed to make SQL " + - "scalable for time-series data. It is engineered up from PostgreSQL " + - "and packaged as a PostgreSQL extension, providing automatic " + - "partitioning across time and space (partitioning key), as well as " + + "TimescaleDB is an open-source database designed to make SQL " \ + "scalable for time-series data. It is engineered up from PostgreSQL " \ + "and packaged as a PostgreSQL extension, providing automatic " \ + "partitioning across time and space (partitioning key), as well as " \ "full SQL support." end def dependencies deps = case Pgpm::OS.in_scope.class.name - when "rocky+epel-9", "redhat", "fedora" - ["openssl"] - end + when "rocky+epel-9", "redhat", "fedora" + ["openssl"] + end super + deps end def build_dependencies deps = case Pgpm::OS.in_scope.class.name - when "debian", "ubuntu" - ["libssl-dev", "cmake"] - when "rocky+epel-9", "redhat", "fedora" - ["openssl-devel", "cmake"] - end + when "debian", "ubuntu" + %w[libssl-dev cmake] + when "rocky+epel-9", "redhat", "fedora" + %w[openssl-devel cmake] + end super + deps end @@ -77,6 +77,5 @@ def install_steps def bootstrap_flags [] end - end end