Skip to content

Commit 0a1c5f2

Browse files
author
qount25
committed
Pgpm::Deb::Builder #prepare and #create_container methods
1 parent 06df6f3 commit 0a1c5f2

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

exe/pgpm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ module Pgpm
9999
p = Pgpm::ScopedObject.new(p, os, arch)
100100
spec = p.to_deb_spec
101101
end
102-
binding.break
103102
builder = Pgpm::Deb::Builder.new(spec)
104103
builder.build
105104
end

lib/pgpm/deb/builder.rb

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

77
def initialize(spec)
88
@spec = spec
9+
@image_name = "pgpm-debian12"
10+
@container_name = "pgpm-debian12_build-#{Time.now.to_i}_#{rand(10000)}"
911
end
1012

1113
def build
1214
puts "build()"
13-
p @spec
14-
#create_container
15+
prepare
1516
#generate_deb_src_files
17+
create_container
1618
#run_pbuilder
1719
#copy_build_from_container
18-
#destroy_container
20+
#cleanup
1921
end
2022

2123
private
2224

25+
def prepare
26+
puts "Preparing build..."
27+
puts " Creating container dir structure..."
28+
@pgpm_dir = Dir.mktmpdir
29+
Dir.mkdir "#{@pgpm_dir}/source"
30+
Dir.mkdir "#{@pgpm_dir}/out"
31+
puts " Copying #{@spec.package.source.to_s} to #{@pgpm_dir}/source/"
32+
FileUtils.copy_entry @spec.package.source.to_s, "#{@pgpm_dir}/source/"
33+
end
34+
2335
def create_container
24-
# pull pgpm-enabled debian podman image if doesn't exist locally
25-
# create a new container with that image
26-
# and @spec.package.source mounted into the container
36+
puts "Creating a podman container..."
37+
# Check if image exists
38+
system("podman image exists #{@image_name}")
39+
if $?.to_i > 0 # image doesn't exist -- pull image from a remote repository
40+
puts " Pulling image #{@image_name}..."
41+
# TODO
42+
else
43+
puts " Image #{@image_name} already exists! OK"
44+
end
45+
46+
create_opts = " -v #{@pgpm_dir}:/root/pgpm"
47+
create_opts += ":z" if selinux_enabled?
48+
create_opts += " --privileged"
49+
create_opts += " --name #{@container_name} #{@image_name}"
50+
51+
puts " Creating and starting container #{@container_name}"
52+
puts " podman run -dti #{create_opts}"
53+
system("podman run -dti #{create_opts}")
2754
end
2855

2956
def generate_deb_src_files
@@ -40,16 +67,18 @@ def run_pbuilder
4067
def copy_build_from_container
4168
end
4269

43-
def copy_into_container(dest_dir_in_container)
44-
end
45-
46-
def copy_from_container(dest_dir_on_host)
70+
def run_container_command(cmd)
4771
end
4872

49-
def destroy_container
73+
def cleanup
5074
end
5175

52-
def run_container_command(cmd)
76+
# Needed because SELinux requires :z suffix for mounted directories to
77+
# be accessible -- otherwise we get "Permission denied" when cd into a
78+
# mounted dir inside the container.
79+
def selinux_enabled?
80+
# This returns true or false by itself
81+
system("sestatus | grep 'SELinux status' | grep -o 'enabled'")
5382
end
5483

5584
def safe_package_name

0 commit comments

Comments
 (0)