Skip to content

Commit 97d5506

Browse files
author
qount25
committed
Refactor: make build run all podman commands in one go, then exit
1 parent aa0d915 commit 97d5506

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

lib/pgpm/deb/builder.rb

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ class Builder
66

77
def initialize(spec)
88
@spec = spec
9-
@container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}"
9+
@container_name = "pgpm-debian_build-#{Time.now.to_i}_#{rand(10000)}"
1010
end
1111

1212
def build
1313
prepare
1414
generate_deb_src_files
15-
create_container
16-
run_pbuilder
15+
pull_image
16+
run_build
1717
copy_build_from_container
1818
cleanup
1919
end
@@ -35,25 +35,16 @@ def prepare
3535
FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/"
3636
end
3737

38-
def create_container
39-
puts "Creating a podman container..."
38+
def pull_image
39+
puts "Checking if podman image exists..."
4040
# Check if image exists
4141
system("podman image exists #{image_name}")
4242
if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository
43-
puts " Pulling image #{image_name}..."
43+
puts " No. Pulling image #{image_name}..."
4444
system("podman pull quay.io/qount25/pgpm-debian12")
4545
else
46-
puts " Image #{image_name} already exists! OK"
46+
puts " Yes, image #{image_name} already exists! OK"
4747
end
48-
49-
create_opts = " -v #{@pgpm_dir}:/root/pgpm"
50-
create_opts += ":z" if selinux_enabled?
51-
create_opts += " --privileged --annotation run.oci.keep_original_groups=1"
52-
create_opts += " --name #{@container_name} #{image_name}"
53-
54-
puts " Creating and starting container #{@container_name}"
55-
puts " podman run -dti #{create_opts}"
56-
system("podman run -dti #{create_opts}")
5748
end
5849

5950
def generate_deb_src_files
@@ -66,27 +57,33 @@ def generate_deb_src_files
6657
File.chmod 0740, "#{@pgpm_dir}/source/debian/rules" # rules file must be executable
6758
end
6859

69-
def run_pbuilder
70-
puts "Building a .deb package with pbuilder..."
71-
cmd_pref = "podman exec -w /root/pgpm/source #{@container_name} "
72-
system("#{cmd_pref} dpkg-buildpackage --build=source")
73-
exit(1) if $?.to_i > 0
60+
def run_build
61+
# podman run options
62+
create_opts = " -v #{@pgpm_dir}:/root/pgpm"
63+
create_opts += ":z" if selinux_enabled?
64+
create_opts += " --privileged --annotation run.oci.keep_original_groups=1"
65+
create_opts += " --name #{@container_name} #{image_name}"
66+
7467
dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc"
75-
system("#{cmd_pref} fakeroot pbuilder build ../#{dsc_fn}")
68+
deb_fn = "#{@spec.full_pkg_name}.deb"
69+
70+
# commands to run
71+
cmds = " /bin/bash -c 'cd /root/pgpm/source"
72+
cmds += " && dpkg-buildpackage --build=source"
73+
cmds += " && fakeroot pbuilder build ../#{dsc_fn}"
74+
cmds += " && mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/'"
75+
76+
puts " Creating and starting container #{@container_name} & running pbuilder"
77+
system("podman run -it #{create_opts} #{cmds}")
7678
exit(1) if $?.to_i > 0
7779
end
7880

7981
def copy_build_from_container
8082
puts "Moving .deb file from podman container into current directory..."
81-
cmd_pref = "podman exec #{@container_name} "
8283
deb_fn = "#{@spec.full_pkg_name}.deb"
83-
system("#{cmd_pref} mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/")
8484
FileUtils.mv("#{@pgpm_dir}/out/#{deb_fn}", Dir.pwd)
8585
end
8686

87-
def run_container_command(cmd)
88-
end
89-
9087
def cleanup
9188
puts "Cleaning up..."
9289

lib/pgpm/deb/spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def build_deps
4242
end
4343

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

4848
def source_version

lib/pgpm/deb/templates/changelog.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= source_name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium
1+
<%= self.package.name %>-<%= source_version %> (0-1) UNRELEASED; urgency=medium
22

33
* Initial release. (Closes: #nnnn) <nnnn is the bug number of your ITP>
44

lib/pgpm/package/packaging.rb

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

1111
def to_deb_spec(**opts)
12-
binding.break
1312
Pgpm::Deb::Spec.new(self, **opts)
1413
end
1514

lib/pgpm/scoped_object.rb

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

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

0 commit comments

Comments
 (0)