Skip to content

Commit ad94115

Browse files
committed
Problem: can't build linux package under macOS
The problem is generally solved by running inside the specialized `pgpm` container which has necessary dependencies installed. However, this requires us to run it there. Solution: podmanize everything! We already use podman to bring components we may not have – like rust toolchain. Why not use it to bring `mock` in? This is not perfect yet, and relies on volume mapping (which is what we do already anyway) – for which we had to do special accommodations to ensure we know these paths and they are absolute. We currently use the `pgpm` image as the one that should contain `mock`. But may be it should be a different, smaller image? To build for a particular OS, use the `--os` flag, for example: ``` --os rocky+epel-9 ```
1 parent 109d3e5 commit ad94115

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

exe/pgpm

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Pgpm
3434

3535
include SharedOptions
3636

37-
option :os, type: :string, default: Pgpm::OS.auto_detect.name, desc: "OS name"
37+
option :os, type: :string, default: Pgpm::OS.auto_detect&.name, desc: "OS name"
3838
option :arch, type: :string, default: Pgpm::Arch.host.name, desc: "Target architecture"
3939
option :pgdist, type: :string, default: "pgdg", desc: "Target Postgres distribution"
4040
option :pgver, type: :string, default: Pgpm::Postgres::Distribution.versions.last.to_s, desc: "Target Postgres version"
@@ -71,7 +71,7 @@ module Pgpm
7171
pkg
7272
end
7373

74-
os = Pgpm::OS.auto_detect
74+
os = os ? Pgpm::OS.find(os) : Pgpm::OS.auto_detect
7575
arch = if arch
7676
Pgpm::Arch.new(arch)
7777
else

lib/pgpm/arch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.in_scope
1414
end
1515

1616
def initialize(name)
17-
@name = name
17+
@name = name == "arm64" ? "aarch64" : name
1818
end
1919

2020
attr_reader :name

lib/pgpm/os.rb

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def self.auto_detect
4242
Pgpm::OS::Linux.auto_detect
4343
end
4444

45+
def self.find(name)
46+
Base.all_subclasses.find { |klass| klass.name == name }&.new
47+
end
48+
4549
def self.in_scope
4650
LSpace[:pgpm_target_operating_system]
4751
end

lib/pgpm/rpm/mock/operation.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ def self.buildsrpm(spec, sources, config: nil, result_dir: nil, cb: nil)
1212
]
1313
args.push("--sources", sources) if sources
1414
args.push("-r", config.to_s) unless config.nil?
15-
new(*args, cb: lambda {
15+
paths = [buffer_result_dir]
16+
paths.push(File.dirname(spec))
17+
paths.push(File.dirname(sources)) if sources
18+
new(*args, paths:, cb: lambda {
1619
rpms = Dir.glob("*.rpm", base: buffer_result_dir).map do |f|
1720
FileUtils.cp(Pathname(buffer_result_dir).join(f), result_dir) unless result_dir.nil?
18-
f
21+
File.join(File.absolute_path(result_dir), f)
1922
end
2023
FileUtils.rm_rf(buffer_result_dir)
2124
cb.call unless cb.nil?
@@ -29,22 +32,25 @@ def self.rebuild(srpm, config: nil, result_dir: nil, cb: nil)
2932
"--rebuild", "--chain", "--recurse", srpm, "--localrepo", buffer_result_dir
3033
]
3134
args.push("-r", config.to_s) unless config.nil?
32-
new(*args, cb: lambda {
35+
paths = [buffer_result_dir]
36+
paths.push(File.dirname(srpm))
37+
new(*args, paths:, cb: lambda {
3338
# Here we glob for **/*.rpm as ``--localrepo` behaves differently from
3439
# `--resultdir`
3540
rpms = Dir.glob("**/*.rpm", base: buffer_result_dir).map do |f|
3641
FileUtils.cp(Pathname(buffer_result_dir).join(f), result_dir) unless result_dir.nil?
37-
f
42+
File.join(File.absolute_path(result_dir), f)
3843
end
3944
FileUtils.rm_rf(buffer_result_dir)
4045
cb.call unless cb.nil?
4146
rpms
4247
})
4348
end
4449

45-
def initialize(*args, opts: nil, cb: nil)
50+
def initialize(*args, opts: nil, paths: [], cb: nil)
4651
@args = args
4752
@cb = cb
53+
@paths = paths
4854
@opts = opts || { "print_main_output" => "True", "pgdg_version" => Postgres::Distribution.in_scope.major_version }
4955
end
5056

@@ -53,7 +59,8 @@ def initialize(*args, opts: nil, cb: nil)
5359
def call
5460
options = @opts.flat_map { |(k, v)| ["--config-opts", "#{k}=#{v}"] }.compact.join(" ")
5561
command = "mock #{options} #{@args.join(" ")}"
56-
raise "Failed to execute `#{command}`" unless system command
62+
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}")
5764

5865
@cb&.call
5966
end

0 commit comments

Comments
 (0)