Skip to content

Commit 6b56207

Browse files
author
qount25
committed
Merge branch 'master' into deb
2 parents 8de62ed + 57755eb commit 6b56207

File tree

13 files changed

+110
-45
lines changed

13 files changed

+110
-45
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,15 @@ docker rmi pgpm:local
166166
docker rmi ghcr.io/postgres-pm/pgpm:latest
167167
```
168168

169+
### Troubleshooting
170+
171+
#### Podman invocations terminate with exit code 137
172+
173+
Make sure your machine has enough RAM. For `podman-machine` you might want to adjust it
174+
with
175+
176+
```shell
177+
podman machine stop
178+
podman machine set -m 16384 # for 16GB
179+
podman machine start
180+
```

exe/pgpm

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ module Pgpm
4141
option :path, type: :path, desc: "Override path to the source"
4242
argument :packages, type: :array, required: true, desc: "Package names"
4343

44+
module ExtendedProc
45+
refine Proc do
46+
def and_then(callable)
47+
lambda do |*args|
48+
res1 = call(*args)
49+
res2 = callable.call(*args)
50+
return res1 + res2 if res1.is_a?(Array) && res2.is_a?(Array)
51+
52+
res2
53+
end
54+
end
55+
end
56+
end
57+
58+
using ExtendedProc
59+
4460
# rubocop:disable Metrics/ParameterLists:
4561
def call(packages:, args: nil, os: nil, arch: nil, pgdist: nil, pgver: nil, pkgdir: nil, path: nil)
4662
_ = args
@@ -109,6 +125,10 @@ module Pgpm
109125
os.with_scope do
110126
arch.with_scope do
111127
selected_pgdist.with_scope do
128+
pkgs = pkgs.flat_map do |pkg|
129+
[pkg, *pkg.all_requirements]
130+
end.reject(&:contrib?)
131+
112132
b = pkgs.reduce(nil) do |c, p|
113133
if p.broken?
114134
puts "Can't build a broken package #{p.name}@#{p.version}"
@@ -123,15 +143,14 @@ module Pgpm
123143
end
124144

125145
srpms = b.call
126-
Pgpm::RedHat::Builder.builder(srpms).call
146+
Pgpm::RPM::Builder.builder(srpms).call
127147
end
128148
end
129149
end
130150
else
131151
puts "#{os.name} is not a supported OS at this moment"
132152
exit(1)
133153
end
134-
135154
end
136155

137156
# rubocop:enable Metrics/ParameterLists:

lib/pgpm/contrib/postgres_fdw.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module Pgpm
4+
module Contrib
5+
class PostgresFdw < Pgpm::Package
6+
contrib_package
7+
end
8+
end
9+
end

lib/pgpm/package/dependencies.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def requires
3838
[]
3939
end
4040

41+
def all_requirements
42+
requires.flat_map { |r| [r, *r.all_requirements] }.uniq
43+
end
44+
4145
def c_files_present?
4246
Dir.glob("*.c", base: source).any?
4347
end

lib/pgpm/package/git_hub.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def sources
1717

1818
def source_url_directory_name
1919
# GitHub strips leading `v` from version tags
20-
commit = version_git_tag.gsub(/^v/, "") || version_git_commit
20+
commit = version_git_tag&.gsub(/^v/, "") || version_git_commit
2121
"#{self.class.github_config.name.split("/").last}-#{commit}"
2222
end
2323
end

lib/pgpm/package/rust.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def sources
2222

2323
vendor_dir = Dir.mktmpdir("pgpm")
2424

25-
podman_cmd = "run -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} -v #{vendor_dir}:#{vendor_dir} -ti rust"
25+
podman_cmd = "run -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} -v #{vendor_dir}:#{vendor_dir} -i rust"
2626
Podman.run("#{podman_cmd} cargo add --manifest-path #{source}/Cargo.toml --dev cargo-pgrx@#{pgrx_version}")
2727
Podman.run("#{podman_cmd} cargo vendor --versioned-dirs --manifest-path #{source}/Cargo.toml #{vendor_dir}/vendor")
2828
vendored_pgrx_version = Dir.glob("cargo-pgrx-*", base: File.join(vendor_dir, "vendor"))[0].split("-").last

lib/pgpm/podman.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module Pgpm
88
module Podman
99
def self.run(command, unhandled_reboot_mitigation: true, print_stdout: true)
1010
result = TTY::Command.new(printer: :null).run("podman #{command}", pty: true) do |out, err|
11-
$stderr.print(out.strip) if print_stdout
12-
warn err
11+
$stderr.print(out) if print_stdout
12+
warn err if err
1313
end
1414

1515
result.out

lib/pgpm/rpm/mock/operation.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,27 @@ def call
6060
options = @opts.flat_map { |(k, v)| ["--config-opts", "#{k}=#{v}"] }.compact.join(" ")
6161
command = "mock #{options} #{@args.join(" ")}"
6262
map_paths = @paths.map { |p| "-v #{p}:#{p}" }.join(" ")
63-
raise "Failed to execute `#{command}`" unless Podman.run("run -v #{Dir.pwd}:#{Dir.pwd} #{map_paths} --privileged -ti ghcr.io/postgres-pm/pgpm #{command}")
63+
raise "Failed to execute `#{command}`" unless Podman.run("run -v #{Dir.pwd}:#{Dir.pwd} #{map_paths} --privileged -i ghcr.io/postgres-pm/pgpm #{command}")
6464

6565
@cb&.call
6666
end
6767

6868
def chain(op)
6969
raise ArgumentError, "can't chain non-rebuild operations" unless op.args.include?("--rebuild") && @args.include?("--rebuild")
7070

71-
args = @args.clone
72-
args.insert(@args.index("--localrepo") - 1, op.args[op.args.index("--localrepo") - 1])
73-
self.class.new(*args, cb: lambda {
74-
res1 = @cb&.call
75-
res2 = op.cb&.call
76-
return res1 + res2 if res1.is_a?(Array) && res2.is_a?(Array)
77-
78-
res2
79-
})
71+
args.insert(args.index("--localrepo"), *op.args[op.args.index("--recurse") + 1..op.args.index("--localrepo") - 1])
72+
self
8073
end
8174

8275
def and_then(op)
8376
lambda do
8477
res1 = call
8578
res2 = op.call
86-
return res1 + res2 if res1.is_a?(Array) && res2.is_a?(Array)
87-
88-
[res1, res2]
79+
if res1.is_a?(Array) && res2.is_a?(Array)
80+
res1 + res2
81+
else
82+
[res1, res2]
83+
end
8984
end
9085
end
9186
end

lib/pgpm/rpm/spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def versionless
2727
License: #{@package.license}
2828
2929
BuildRequires: #{@postgres_distribution.build_time_requirement_packages.join(" ")}
30-
Requires: pgpm-#{@package.name}-#{@postgres_distribution.version}_#{@package.version}
31-
BuildRequires: pgpm-#{@package.name}-#{@postgres_distribution.version}_#{@package.version}
30+
Requires: pgpm-#{@package.name}+#{@package.version}-#{@postgres_distribution.version}
31+
BuildRequires: pgpm-#{@package.name}+#{@package.version}-#{@postgres_distribution.version}
3232
BuildArch: noarch
3333
3434
%description
@@ -65,7 +65,7 @@ def to_s
6565
end
6666

6767
<<~EOF
68-
Name: pgpm-#{@package.name}-#{@postgres_distribution.version}_#{@package.version}
68+
Name: pgpm-#{@package.name}+#{@package.version}-#{@postgres_distribution.version}
6969
Version: 1
7070
Release: 1%{?dist}
7171
Summary: #{@package.summary}
@@ -76,7 +76,7 @@ def to_s
7676
#{@package.build_dependencies.uniq.map { |dep| "BuildRequires: #{dep}" }.join("\n")}
7777
#{@package.dependencies.uniq.map { |dep| "Requires: #{dep}" }.join("\n")}
7878
#{@package.requires.uniq.map do |dep|
79-
req = dep.contrib? ? @postgres_distribution.package_for(dep) : "pgpm-#{dep.name}-#{@postgres_distribution.version}_#{dep.version}"
79+
req = dep.contrib? ? @postgres_distribution.package_for(dep) : "pgpm-#{dep.name}+#{dep.version}-#{@postgres_distribution.version}"
8080
raise "Can't build with a broken dependency #{dep.name}@#{dep.version}" if dep.broken?
8181
8282
"Requires: #{req}#{"\nBuildRequires: #{req}" if dep.contrib?}"

packages/omnigres/extension_discovery.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def initialize(revision: nil, path: nil)
2121
self.class.mutex.synchronize do
2222
git =
2323
if File.directory?(path)
24-
::Git.open(path)
24+
g = ::Git.open(path)
25+
g.pull
26+
g
2527
else
2628
::Git.clone("https://github.com/omnigres/omnigres", path)
2729
end

packages/omnigres/omni_cloudevents.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Omnigres
4+
class OmniCloudevents < Pgpm::Package
5+
include Package
6+
7+
def summary
8+
"CloudEvents support"
9+
end
10+
end
11+
end

packages/omnigres/omni_vfs_types_v1.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ def summary
88
"Virtual File System API"
99
end
1010

11+
def requires
12+
# FIXME: this handles the special case of this extension being in
13+
# the same folder as omni_vfs.
14+
# In order to configure it, all dependencies of omni_vfs, save for omni_vfs_types_v1,
15+
# must be included.
16+
Pgpm::Package["omnigres/omni_vfs"][:latest].requires.reject { |p| p.name == name }
17+
end
18+
1119
def native?
1220
# This extension shares the directory with `omni_vfs` which has .c files,
1321
# but it is not a native-code extension itself.

packages/omnigres/package.rb

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ def version_git_commit
6767

6868
def configure_steps
6969
extra_config = contains_vendorized_deps? ? "" : "-DCPM_SOURCE_CACHE=$(pwd)/deps/_deps "
70-
["export PIP_CONFIG_FILE=$(pwd)/deps/pip.conf",
71-
"cmake -S #{extension_path} -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo " \
72-
"-DOPENSSL_CONFIGURED=1 -DPG_CONFIG=$PG_CONFIG #{extra_config} -DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
70+
steps = ["export PIP_CONFIG_FILE=$(pwd)/deps/pip.conf",
71+
"cmake -S #{extension_path} -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo " \
72+
"-DOPENSSL_CONFIGURED=1 -DPG_CONFIG=$PG_CONFIG #{extra_config} -DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
73+
steps.unshift("source /opt/rh/gcc-toolset-14/enable") if Pgpm::OS.in_scope.is_a?(Pgpm::OS::RedHat)
74+
steps
7375
end
7476

7577
def build_steps
@@ -106,7 +108,9 @@ def license
106108
end
107109

108110
def build_dependencies
109-
%w[cmake openssl-devel python3 python3-devel nc sudo git] + super
111+
deps = %w[cmake openssl-devel python3 python3-devel nc sudo git] + super
112+
deps.push("gcc-toolset-14") if Pgpm::OS.in_scope.is_a?(Pgpm::OS::RedHat)
113+
deps
110114
end
111115

112116
def dependencies
@@ -182,7 +186,7 @@ def artifacts(src = nil)
182186
rescue Git::GitExecuteError
183187
share_fix = "-e PGSHAREDIR=#{pgpath}/build/share"
184188
end
185-
unless Pgpm::Podman.run "run -ti #{share_fix} -v #{source}:#{source} -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src} -B #{src}/build -DOPENSSL_CONFIGURED=1 -DPGVER=#{Pgpm::Postgres::Distribution.in_scope.version} -DPGDIR=#{pgpath}"
189+
unless Pgpm::Podman.run "run -i #{share_fix} -v #{src}:#{src} -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src} -B #{src}/build -DOPENSSL_CONFIGURED=1 -DPGVER=#{Pgpm::Postgres::Distribution.in_scope.version} -DPGDIR=#{pgpath}"
186190
raise "Can't configure the project"
187191
end
188192

@@ -208,25 +212,28 @@ def requires
208212
end
209213
end
210214

211-
def original_sources
212-
method(:sources).super_method.call
215+
def dont_fetch_previous
216+
@dont_fetch_previous = true
217+
self
213218
end
214219

215220
def sources
216221
return @srcs if @srcs
217222

218-
@srcs = original_sources
223+
@srcs = super
224+
return @srcs if @dont_fetch_previous
225+
219226
unless contains_vendorized_deps?
220227
@srcs.push(deps_tar_gz)
221228
end
222229
if previous_version && !previous_version.broken?
223230
begin
224-
puts "Fetching previous version #{previous_version.version} to be able to generate migrations"
225-
@srcs.push(*previous_version.original_sources) # archive
231+
puts "Fetching previous version of #{name} (#{previous_version.version}) to be able to generate migrations"
232+
@srcs.push(*previous_version.dont_fetch_previous.sources) # archive
226233
@srcs.push(previous_version.deps_tar_gz("deps-prev")) unless previous_version.contains_vendorized_deps?
227234
rescue UnsupportedVersion
228235
# ignore this one, just don't build an upgrade
229-
puts "Ignore #{previous_version.version}, it is unsupported"
236+
puts "Ignore #{name} #{previous_version.version}, it is unsupported"
230237
@srcs.pop # get the version out
231238
@no_migration = true
232239
end
@@ -291,15 +298,13 @@ def install_prerequisites
291298
return if @prerequisites_installed
292299

293300
@os = Pgpm::OS.auto_detect
294-
if @os.is_a?(Pgpm::OS::RedHat)
295-
images = Oj.load(Pgpm::Podman.run("images --format json", print_stdout: false))
296-
unless images.flat_map { |i| i["Names"] }.include?("localhost/#{PGPM_BUILD_CONTAINER_IMAGE}:latest")
297-
tmpfile = Tempfile.new
298-
Pgpm::Podman.run "run -ti --cidfile #{tmpfile.path} #{PGPM_BUILD_CONTAINER}"
299-
id = File.read(tmpfile.path)
300-
tmpfile.unlink
301-
Pgpm::Podman.run "commit #{id} #{PGPM_BUILD_CONTAINER_IMAGE}"
302-
end
301+
images = Oj.load(Pgpm::Podman.run("images --format json", print_stdout: false))
302+
unless images.flat_map { |i| i["Names"] }.include?("localhost/#{PGPM_BUILD_CONTAINER_IMAGE}:latest")
303+
tmpfile = Tempfile.new
304+
Pgpm::Podman.run "run -i --cidfile #{tmpfile.path} #{PGPM_BUILD_CONTAINER}"
305+
id = File.read(tmpfile.path)
306+
tmpfile.unlink
307+
Pgpm::Podman.run "commit #{id} #{PGPM_BUILD_CONTAINER_IMAGE}"
303308
end
304309
@prerequisites_installed = true
305310
end
@@ -314,7 +319,7 @@ def cmake_dependencies(dir_name = "deps")
314319
return if File.exist?(ready_marker)
315320
raise UnsupportedVersion unless File.directory?(File.join(src, "cmake", "dependencies"))
316321

317-
unless Pgpm::Podman.run "run -ti -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src}/cmake/dependencies -B #{deps} -DCPM_SOURCE_CACHE=#{deps}/_deps"
322+
unless Pgpm::Podman.run "run -i -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src}/cmake/dependencies -B #{deps} -DCPM_SOURCE_CACHE=#{deps}/_deps"
318323
raise "Can't fetch dependencies"
319324
end
320325

0 commit comments

Comments
 (0)