Skip to content

Commit aa0d915

Browse files
author
qount25
committed
Refactor: replace most hardcoded values for Pgpm::Deb::Spec with values from @Package
1 parent 62748ff commit aa0d915

File tree

7 files changed

+22
-30
lines changed

7 files changed

+22
-30
lines changed

lib/pgpm/deb/builder.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ class Builder
66

77
def initialize(spec)
88
@spec = spec
9-
@image_name = "quay.io/qount25/pgpm-debian12"
109
@container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}"
1110
end
1211

1312
def build
14-
puts "build()"
1513
prepare
1614
generate_deb_src_files
1715
create_container
@@ -22,6 +20,11 @@ def build
2220

2321
private
2422

23+
# Depends on postgres version and arch
24+
def image_name
25+
"quay.io/qount25/pgpm-debian-pg#{@spec.postgres_major_version}-#{@spec.arch}"
26+
end
27+
2528
def prepare
2629
puts "Preparing build..."
2730
puts " Creating container dir structure..."
@@ -35,18 +38,18 @@ def prepare
3538
def create_container
3639
puts "Creating a podman container..."
3740
# Check if image exists
38-
system("podman image exists #{@image_name}")
41+
system("podman image exists #{image_name}")
3942
if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository
40-
puts " Pulling image #{@image_name}..."
43+
puts " Pulling image #{image_name}..."
4144
system("podman pull quay.io/qount25/pgpm-debian12")
4245
else
43-
puts " Image #{@image_name} already exists! OK"
46+
puts " Image #{image_name} already exists! OK"
4447
end
4548

4649
create_opts = " -v #{@pgpm_dir}:/root/pgpm"
4750
create_opts += ":z" if selinux_enabled?
4851
create_opts += " --privileged --annotation run.oci.keep_original_groups=1"
49-
create_opts += " --name #{@container_name} #{@image_name}"
52+
create_opts += " --name #{@container_name} #{image_name}"
5053

5154
puts " Creating and starting container #{@container_name}"
5255
puts " podman run -dti #{create_opts}"
@@ -76,7 +79,6 @@ def run_pbuilder
7679
def copy_build_from_container
7780
puts "Moving .deb file from podman container into current directory..."
7881
cmd_pref = "podman exec #{@container_name} "
79-
arch = "amd64"
8082
deb_fn = "#{@spec.full_pkg_name}.deb"
8183
system("#{cmd_pref} mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/")
8284
FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd)

lib/pgpm/deb/spec.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,35 @@ def generate(template_name)
2828
end
2929

3030
def deps
31-
["postgresql-#{postgres_version}"]
31+
["postgresql-#{postgres_major_version}"]
3232
end
3333

3434
def build_deps
3535
[
36-
"postgresql-#{postgres_version}",
36+
"postgresql-#{postgres_major_version}",
3737
"build-essential",
38-
"postgresql-#{postgres_version}",
39-
"postgresql-server-dev-#{postgres_version}",
38+
"postgresql-#{postgres_major_version}",
39+
"postgresql-server-dev-#{postgres_major_version}",
4040
"postgresql-common"
4141
]
4242
end
4343

44-
def postgres_version
45-
17
44+
def postgres_major_version
45+
@spec.postgres_distribution.version.split(".")[0]
4646
end
4747

4848
def source_version
4949
@package.version.to_s
5050
end
5151

52-
def source_name
53-
@package.name
54-
end
55-
5652
def full_pkg_name
5753
"#{@package.name}-#{@package.version.to_s}_0-1_#{arch}"
5854
end
5955

60-
def deb_version
61-
"0.1.0"
62-
end
63-
6456
def arch
6557
"amd64"
6658
end
6759

68-
def description
69-
@package.description
70-
end
71-
7260
# Whatever is returned from this method gets added to the "rules" file.
7361
def rules_amendments
7462
"#"

lib/pgpm/deb/templates/control.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
Source: <%= source_name %>-<%= source_version %>
1+
Source: <%= self.package.name %>-<%= source_version %>
22
Section: libs
33
Priority: optional
44
Maintainer: PGPM Debian maintainer <debian[email protected]>
55
Rules-Requires-Root: no
66
Build-Depends: debhelper-compat (= 13), <%= build_deps.join(", ") %>
77
Standards-Version: 4.6.2
88

9-
Package: <%= source_name %>-<%= source_version %>
9+
Package: <%= self.package.name %>-<%= source_version %>
1010
Depends: <%= deps.join(", ") %>
1111
Section: libdevel
1212
Architecture: <%= arch %>
13-
Description: <%= description %>
13+
Description: <%= self.package.description %>

lib/pgpm/deb/templates/copyright.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Source: <url://example.com>
3-
Upstream-Name: <%= source_name %>-<%= source_version %>
3+
Upstream-Name: <%= self.package.name %>-<%= self.package.name %>
44
Upstream-Contact: <preferred name and address to reach the upstream project>
55

66
Files:

lib/pgpm/deb/templates/files.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= source_name %>-<%= source_version %>_0-1_source.buildinfo libs optional
1+
<%= self.package.name %>-<%= source_version %>_0-1_source.buildinfo libs optional

lib/pgpm/package/packaging.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def to_rpm_spec(**opts)
99
end
1010

1111
def to_deb_spec(**opts)
12+
binding.break
1213
Pgpm::Deb::Spec.new(self, **opts)
1314
end
1415

lib/pgpm/scoped_object.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ScopedObject < SimpleDelegator
77
def initialize(obj, *scopes)
88
@scopes = scopes
99
super(obj)
10+
binding.break
1011
end
1112

1213
def method_missing(method, *args, &block)

0 commit comments

Comments
 (0)