1
1
# frozen_string_literal: true
2
2
3
3
require "English"
4
- require "debug"
5
4
6
5
module Pgpm
7
6
module Deb
@@ -13,7 +12,7 @@ def initialize(spec)
13
12
end
14
13
15
14
def build
16
- pull_image
15
+ prepare_image
17
16
start_container
18
17
patch_pbuilder
19
18
@@ -32,9 +31,16 @@ def build
32
31
33
32
private
34
33
35
- # Depends on postgres version and arch
34
+ # Only depends on the arch -- this is the image being pulled from
35
+ # a remote repo, which is then used to build a local image with correct
36
+ # postgres version installed inside its pbuilder's chroot.
37
+ def base_image_name
38
+ "quay.io/qount25/pgpm-debian-#{ @spec . arch } "
39
+ end
40
+
41
+ # Locally built image with correct chroot installed.
36
42
def image_name
37
- "quay.io/qount25/ pgpm-debian-pg#{ @spec . package . postgres_version } -#{ @spec . arch } "
43
+ "pgpm-debian-pg#{ @spec . package . postgres_version } -#{ @spec . arch } "
38
44
end
39
45
40
46
def prepare_versioned_source
@@ -102,18 +108,45 @@ def prepare_default_source
102
108
end
103
109
end
104
110
105
- def pull_image
111
+ def prepare_image
106
112
puts "Checking if podman image exists..."
107
113
# Check if image exists
108
114
system ( "podman image exists #{ image_name } " )
109
- if $CHILD_STATUS. to_i . positive? # image doesn't exist -- pull image from a remote repository
110
- puts " No. Pulling image #{ image_name } ..."
111
- system ( "podman pull #{ image_name } " )
115
+ if $CHILD_STATUS. to_i . positive?
116
+ puts " Image for the specific pg version doesn't exist. Will build."
117
+ system ( "podman image exists #{ base_image_name } " )
118
+ if $CHILD_STATUS. to_i . positive?
119
+ puts " Base image doesn't exist. Pulling it..."
120
+ system ( "podman pull #{ base_image_name } " )
121
+ end
122
+ build_local_image
112
123
else
113
124
puts " Yes, image #{ image_name } already exists! OK"
114
125
end
115
126
end
116
127
128
+ def build_local_image
129
+ puts " Building local #{ image_name } ..."
130
+ system ( "podman create -it --privileged --tmpfs /tmp --name pgpm-deb-tmp #{ base_image_name } " )
131
+ system ( "podman start pgpm-deb-tmp" )
132
+
133
+ # Generate pbuilder_install script.sh, copy it inside the image
134
+ pbuild_install_script_path = "#{ @pgpm_dir } /pbuilder_install_script.sh"
135
+ puts " Generating #{ pbuild_install_script_path } ..."
136
+ File . write "#{ pbuild_install_script_path } " , @spec . generate ( "pbuilder_install_script.sh" )
137
+ system ( "podman container cp #{ pbuild_install_script_path } pgpm-deb-tmp:/root/" )
138
+
139
+ # This command installs relevant postgresql packages into the chroot
140
+ # base image inside the container (along with some other necessary
141
+ # packages) and saves chroot base image with these changes.
142
+ puts " Updating chroot image..."
143
+ system ( "podman exec -w /root pgpm-deb-tmp /bin/bash -c 'fakeroot pbuilder execute --save-after-exec ./pbuilder_install_script.sh'" )
144
+
145
+ system ( "podman stop pgpm-deb-tmp" )
146
+ system ( "podman commit pgpm-deb-tmp #{ image_name } " )
147
+ system ( "podman container rm pgpm-deb-tmp" )
148
+ end
149
+
117
150
def generate_deb_src_files ( pkg_type = :versioned )
118
151
puts "Generating debian files..."
119
152
Dir . mkdir "#{ @pgpm_dir } /source-#{ pkg_type } /debian"
0 commit comments