Skip to content

Commit 3122b37

Browse files
author
qount25
committed
Run build commands in podman through podman exec so later failed container build can be inspected
1 parent 164cc59 commit 3122b37

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lib/pgpm/deb/builder.rb

+19-11
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,32 @@ def generate_deb_src_files
5858
end
5959

6060
def run_build
61-
# podman run options
61+
# podman create options
6262
create_opts = " -v #{@pgpm_dir}:/root/pgpm"
6363
create_opts += ":z" if selinux_enabled?
64-
create_opts += " --privileged --tmpfs /tmp" #--privileged --cap-add=sys_admin --security-opt label:disable -v /proc:/proc
64+
create_opts += " --privileged --tmpfs /tmp"
6565
create_opts += " --name #{@container_name} #{image_name}"
6666

6767
dsc_fn = "#{@spec.package.name}-#{@spec.package.version.to_s}_0-1.dsc"
6868
deb_fn = "#{@spec.full_pkg_name}.deb"
6969

70-
# commands to run
71-
cmds = " /bin/bash -c 'cd /root/pgpm/source"
72-
cmds += " && dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error
73-
cmds += " && fakeroot pbuilder build ../#{dsc_fn}"
74-
cmds += " && mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/'"
75-
7670
puts " Creating and starting container #{@container_name} & running pbuilder"
77-
puts "podman run -it #{create_opts} #{cmds}"
78-
system("podman run -it #{create_opts} #{cmds}")
71+
system("podman create -it #{create_opts}")
72+
exit(1) if $?.to_i > 0
73+
system("podman start #{@container_name}")
7974
exit(1) if $?.to_i > 0
75+
76+
cmds = []
77+
cmds << "dpkg-buildpackage --build=source -d" # -d flag helps with dependencies error
78+
cmds << "fakeroot pbuilder build ../#{dsc_fn}"
79+
cmds << "mv /var/cache/pbuilder/result/#{deb_fn} /root/pgpm/out/"
80+
81+
puts " Building package with pbuilder..."
82+
cmds.each do |cmd|
83+
system("podman exec -w /root/pgpm/source #{@container_name} /bin/bash -c '#{cmd}'")
84+
exit(1) if $?.to_i > 0
85+
end
86+
8087
end
8188

8289
def copy_build_from_container
@@ -88,7 +95,8 @@ def copy_build_from_container
8895
def cleanup
8996
puts "Cleaning up..."
9097

91-
puts " Destroying podman container: #{@container_name}"
98+
puts " Stopping destroying podman container: #{@container_name}"
99+
system("podman container stop #{@container_name}")
92100
system("podman container rm #{@container_name}")
93101

94102
# Remove temporary files

0 commit comments

Comments
 (0)