ood_packaging 0.0.1.rc.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d76f705e0592bc694ee1e658e75da269f269489712392b3a412bc7db7ab566e7
4
+ data.tar.gz: c8eb63270d72d241ae87b1b82d9daeb1bb78382d529d636637fb2c8db1c5d9cb
5
+ SHA512:
6
+ metadata.gz: 6abb5c9b384d917d91570578518be7f53a3b28568f4fa6bf50568d7903b7eae916b62be9b32e37607302f7227b1af3c1b811679b2ce17d05243c2b52503b224b
7
+ data.tar.gz: fb24936ba8e69d351b00032b5afe02fc3520629ea694d91a068bad906185275d0d2ce1a5c65a206ded893e70b1992c7dcae92378d0aa8959aed270486696f6a1
data/bin/ood_packaging ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optparse'
5
+ begin
6
+ require 'ood_packaging'
7
+ # If gem is not installed, load from location in git repo
8
+ rescue LoadError
9
+ $LOAD_PATH.unshift(File.expand_path(File.join(__dir__, '../lib')))
10
+ require 'ood_packaging'
11
+ end
12
+
13
+ options = {}
14
+ OptionParser.new do |opts|
15
+ opts.banner = 'Usage: ood_packaging [options] package'
16
+
17
+ opts.on('-w', '--work=DIR', String, 'Work directory path') do |v|
18
+ options[:work_dir] = v
19
+ end
20
+
21
+ opts.on('-o', '--output=DIR', String, 'Output directory path') do |v|
22
+ options[:output_dir] = v
23
+ end
24
+
25
+ opts.on('-d', '--dist=DIST', String, 'Distribution to build') do |v|
26
+ options[:dist] = v
27
+ end
28
+
29
+ opts.on('-V', '--version=VERSION', String, 'Version of package to build') do |v|
30
+ options[:version] = v
31
+ end
32
+
33
+ opts.on('-T', '--tar', 'Create tar archive for package') do
34
+ options[:tar] = true
35
+ end
36
+
37
+ opts.on('-t', '--tar-only', 'Only create tar archive') do
38
+ options[:tar_only] = true
39
+ end
40
+
41
+ opts.on('-G', '--gpg-name', String, 'GPG key name') do |v|
42
+ options[:gpg_name] = v
43
+ end
44
+
45
+ opts.on('-g', '--gpg-pubkey', String, 'GPG public key path') do |v|
46
+ options[:gpg_pubkey] = v
47
+ end
48
+
49
+ opts.on('-S', '--skip-gpg', 'Skip GPG signing') do
50
+ options[:gpg_sign] = false
51
+ end
52
+
53
+ opts.on('--skip-clean-output', 'Skip clean up of output directory') do
54
+ options[:clean_output_dir] = false
55
+ end
56
+
57
+ opts.on('--skip-clean-work', 'Skip clean up of work directory') do
58
+ options[:clean_work_dir] = false
59
+ end
60
+
61
+ opts.on('-s', '--skip-download', 'Skip source download') do
62
+ options[:skip_download] = true
63
+ end
64
+
65
+ opts.on('-A', '--attach', 'Attach to build box after build') do
66
+ options[:attach] = true
67
+ end
68
+
69
+ opts.on('--debug', 'Show debug output') do
70
+ options[:debug] = true
71
+ end
72
+
73
+ opts.on('-h', '--help', 'Show this help message') do
74
+ puts opts
75
+ exit
76
+ end
77
+ end.parse!(ARGV)
78
+
79
+ if ARGV.size != 1
80
+ puts 'ERROR: Must provide package path'.red
81
+ exit 1
82
+ end
83
+ options[:package] = ARGV[0]
84
+
85
+ OodPackaging::Package.new(options).run!
@@ -0,0 +1,304 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ood_packaging/utils'
4
+ require 'ood_packaging/string_ext'
5
+ require 'English'
6
+ require 'rake'
7
+ require 'rake/file_utils'
8
+ require 'yaml'
9
+
10
+ # Class to handle builds of packages from within buildbox container
11
+ class OodPackaging::Build
12
+ include OodPackaging::Utils
13
+ include FileUtils
14
+
15
+ attr_accessor :build_box
16
+
17
+ def initialize
18
+ @build_box = OodPackaging::BuildBox.new(dist: ENV['DIST'])
19
+ end
20
+
21
+ def config
22
+ @config ||= begin
23
+ c = packaging_config
24
+ c.merge!(c[build_box.dist]) if c.key?(build_box.dist)
25
+ c.transform_keys(&:to_sym)
26
+ end
27
+ end
28
+
29
+ def package
30
+ ENV['PACKAGE']
31
+ end
32
+
33
+ def debug?
34
+ ENV['DEBUG'] == 'true'
35
+ end
36
+
37
+ def gpg_sign?
38
+ ENV['GPG_SIGN'] == 'true'
39
+ end
40
+
41
+ def version
42
+ ENV['VERSION'].gsub(/^v/, '')
43
+ end
44
+
45
+ def rpm_version
46
+ version.split('-', 2)[0]
47
+ end
48
+
49
+ def rpm_release
50
+ v = version.split('-', 2)
51
+ return '1' if v.size < 2
52
+
53
+ v[1].gsub('-', '.')
54
+ end
55
+
56
+ def rpm_defines
57
+ defines = ["--define 'git_tag #{ENV['VERSION']}'"]
58
+ defines.concat ["--define 'package_version #{rpm_version}'"]
59
+ defines.concat ["--define 'package_release #{rpm_release}'"]
60
+ defines.concat ["--define 'scl #{config[:scl]}'"] if config[:scl]
61
+ defines
62
+ end
63
+
64
+ def cmd_suffix
65
+ return '' if debug?
66
+
67
+ ' 2>/dev/null 1>/dev/null'
68
+ end
69
+
70
+ def spec_dir
71
+ @spec_dir ||= if Dir.exist?('/package/rpm')
72
+ '/package/rpm'
73
+ elsif Dir.exist?('/package/packaging/rpm')
74
+ '/package/packaging/rpm'
75
+ else
76
+ '/package'
77
+ end
78
+ end
79
+
80
+ def deb_build_dir
81
+ @deb_build_dir ||= if Dir.exist?('/package/deb/build')
82
+ '/package/deb/build'
83
+ else
84
+ '/package/build'
85
+ end
86
+ end
87
+
88
+ def debian_dir
89
+ @debian_dir ||= if Dir.exist?('/package/deb/debian')
90
+ '/package/deb/debian'
91
+ else
92
+ '/package/debian'
93
+ end
94
+ end
95
+
96
+ def deb_work_dir
97
+ File.join(work_dir, deb_name)
98
+ end
99
+
100
+ def spec_file
101
+ @spec_file ||= Dir["#{spec_dir}/*.spec"][0]
102
+ end
103
+
104
+ def output_dir
105
+ File.join('/output', build_box.dist)
106
+ end
107
+
108
+ def work_dir
109
+ File.join('/work', build_box.dist)
110
+ end
111
+
112
+ def packaging_config
113
+ @packaging_config ||= begin
114
+ path = File.join(spec_dir, 'packaging.yaml')
115
+ path = File.join(debian_dir, 'packaging.yaml') if build_box.deb?
116
+ if File.exist?(path)
117
+ YAML.load_file(path)
118
+ else
119
+ {}
120
+ end
121
+ end
122
+ end
123
+
124
+ def deb_name
125
+ "#{package}-#{version}"
126
+ end
127
+
128
+ def rpms
129
+ @rpms ||= Dir["#{output_dir}/*.rpm"].grep_v(/.src.rpm$/)
130
+ end
131
+
132
+ def run!
133
+ env_dump! if debug?
134
+ bootstrap_rpm! if build_box.rpm?
135
+ bootstrap_deb! if build_box.deb?
136
+ install_dependencies!
137
+ rpmbuild! if build_box.rpm?
138
+ debuild! if build_box.deb?
139
+ copy_output!
140
+ gpg_sign! if build_box.rpm? && gpg_sign?
141
+ sanity!
142
+ end
143
+
144
+ def env_dump!
145
+ ENV.sort.to_h.each_pair do |k, v|
146
+ puts "#{k}=#{v}"
147
+ end
148
+ end
149
+
150
+ def bootstrap_rpm!
151
+ puts '== Bootstrap RPM =='.blue
152
+ bootstrap_gpg! if gpg_sign?
153
+ if podman_runtime?
154
+ puts "\tBootstrap /root".blue
155
+ sh "cp -r #{ctr_rpmmacros} #{ctr_gpg_dir} /root/"
156
+ sh "sed -i 's|/home/ood|/root|g' /root/.rpmmacros"
157
+ end
158
+ puts "\tBootstrap work dir".blue
159
+ sh "mkdir -p #{work_dir}/{RPMS,SRPMS,SOURCES,SPECS,rpmbuild/BUILD}"
160
+ bootstrap_copy_source!
161
+ bootstrap_get_source!
162
+ end
163
+
164
+ def bootstrap_gpg!
165
+ puts "\tBootstrap GPG".blue
166
+ sh "sed -i 's|@GPG_NAME@|#{ENV['GPG_NAME']}|g' #{ctr_rpmmacros}"
167
+ sh "gpg --batch --passphrase-file #{gpg_passphrase} --import #{gpg_private_key}#{cmd_suffix}"
168
+ sh "sudo rpm --import #{ENV['GPG_PUBKEY']}#{cmd_suffix}" if ENV['GPG_PUBKEY']
169
+ end
170
+
171
+ def bootstrap_copy_source!
172
+ puts "\tCopy sources".blue
173
+ if build_box.rpm?
174
+ sh "find #{spec_dir} -maxdepth 1 -type f -exec cp {} #{work_dir}/SOURCES/ \\;"
175
+ sh "find #{spec_dir} -maxdepth 1 -mindepth 1 -type d -exec cp -r {} #{work_dir}/SOURCES/ \\;"
176
+ elsif build_box.deb?
177
+ sh "cp -a #{deb_build_dir}/* #{work_dir}/"
178
+ end
179
+ end
180
+
181
+ def bootstrap_get_source!
182
+ if ENV['SKIP_DOWNLOAD'] == 'true'
183
+ puts "\tSKIP_DOWNLOAD detected, skipping download sources".blue
184
+ else
185
+ puts "\tDownloading sources defined in #{spec_file}".blue
186
+ sh "spectool #{rpm_defines.join(' ')} -g -R -S #{spec_file}#{cmd_suffix}"
187
+ end
188
+ end
189
+
190
+ def bootstrap_deb!
191
+ puts '== Bootstrap DEB =='.blue
192
+ unless Dir.exist?(work_dir)
193
+ puts "\tCreating #{work_dir}".blue
194
+ sh "mkdir -p #{work_dir}"
195
+ end
196
+ bootstrap_copy_source!
197
+ puts "\tExtract source".blue
198
+ Dir.chdir(work_dir) do
199
+ sh "tar -xf #{deb_name}.tar.gz"
200
+ end
201
+ puts "\tBootstrap debian build files".blue
202
+ Dir.chdir(deb_work_dir) do
203
+ sh "dh_make -s -y --createorig -f ../#{deb_name}.tar.gz#{cmd_suffix} || true"
204
+ sh "dch -b -v #{version} 'Release #{version}'#{cmd_suffix}"
205
+ end
206
+ end
207
+
208
+ def install_dependencies!
209
+ puts '== Install Dependencies =='.blue
210
+ if build_box.rpm?
211
+ install_rpm_dependencies!
212
+ elsif build_box.deb?
213
+ install_deb_dependencies!
214
+ end
215
+ end
216
+
217
+ def install_rpm_dependencies!
218
+ cmd = ['sudo']
219
+ cmd.concat [build_box.package_manager, 'builddep'] if build_box.dnf?
220
+ cmd.concat ['yum-builddep'] if build_box.package_manager == 'yum'
221
+ cmd.concat ['-y']
222
+ cmd.concat rpm_defines
223
+ cmd.concat ['--spec'] if build_box.dnf?
224
+ cmd.concat [spec_file]
225
+ sh "#{cmd.join(' ')}#{cmd_suffix}"
226
+ end
227
+
228
+ def install_deb_dependencies!
229
+ sh "sudo apt update -y#{cmd_suffix}"
230
+ cmd = [
231
+ 'mk-build-deps --install --remove --root-cmd sudo',
232
+ "--tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes'"
233
+ ]
234
+ Dir.chdir(deb_work_dir) do
235
+ sh "#{cmd.join(' ')}#{cmd_suffix}"
236
+ end
237
+ end
238
+
239
+ def rpmbuild!
240
+ puts "== RPM build spec=#{spec_file} ==".blue
241
+ cmd = ['rpmbuild', '-ba']
242
+ cmd.concat rpm_defines
243
+ cmd.concat [spec_file]
244
+ sh "#{cmd.join(' ')}#{cmd_suffix}"
245
+ end
246
+
247
+ def debuild!
248
+ puts "== DEB build package=#{deb_work_dir} ==".blue
249
+ prepend_path = ''
250
+ prepend_path = "--prepend-path=#{config[:prepend_path]}" if config[:prepend_path]
251
+ Dir.chdir(deb_work_dir) do
252
+ sh "debuild --no-lintian --preserve-env #{prepend_path}#{cmd_suffix}"
253
+ end
254
+ end
255
+
256
+ def copy_output!
257
+ puts '== Copy output =='.blue
258
+ unless Dir.exist?(output_dir)
259
+ puts "\tCreating #{output_dir}".blue
260
+ sh "mkdir -p #{output_dir}"
261
+ end
262
+ if build_box.rpm?
263
+ puts "\tcopy #{work_dir}/**/*.rpm -> #{output_dir}/".blue
264
+ sh "find #{work_dir} -type f -name '*.rpm' -exec cp {} #{output_dir}/ \\;"
265
+ elsif build_box.deb?
266
+ puts "\tcopy #{work_dir}/*.deb #{output_dir}/".blue
267
+ sh "cp #{work_dir}/*.deb #{output_dir}/"
268
+ end
269
+ end
270
+
271
+ def gpg_sign!
272
+ puts '== GPG sign RPMs =='.blue
273
+ rpms.each do |rpm|
274
+ puts "\tGPG signing #{rpm}".blue
275
+ cmd = []
276
+ # Work around differences in RHEL
277
+ cmd.concat ['cat /dev/null | setsid'] unless build_box.dnf?
278
+ cmd.concat ['rpmsign', '--addsign', rpm]
279
+ sh "#{cmd.join(' ')}#{cmd_suffix}"
280
+ end
281
+ end
282
+
283
+ def sanity!
284
+ puts '== Sanity tests =='.blue
285
+ failure = false
286
+ if build_box.rpm? && gpg_sign?
287
+ rpms.each do |rpm|
288
+ puts "\tTest GPG signing #{rpm}".blue
289
+ output = `rpm -K #{rpm} 2>&1`
290
+ exit_code = $CHILD_STATUS.exitstatus
291
+ puts output if debug?
292
+ if exit_code != 0
293
+ puts "\tGPG check failure: exit code #{exit_code}".red
294
+ failure = true
295
+ end
296
+ if output !~ /(pgp|OK)/
297
+ puts "\tRPM not GPG signed".red
298
+ failure = true
299
+ end
300
+ end
301
+ end
302
+ exit 1 if failure
303
+ end
304
+ end
@@ -0,0 +1,35 @@
1
+ FROM <%= base_image %>
2
+ MAINTAINER Trey Dockendorf <tdockendorf@osc.edu>
3
+ ENV LANG=en_US.UTF-8
4
+ ENV LC_CTYPE=en_US.UTF-8
5
+ <% if dist == 'el7' -%>
6
+ RUN yum update -y && yum clean all && rm -rf /var/cache/yum/*
7
+ RUN yum install -y yum-utils epel-release centos-release-scl && yum clean all && rm -rf /var/cache/yum/*
8
+ RUN yum install -y <%= scl_ruby %>-ruby sudo which wget @buildsys-build \
9
+ rpm-build rpmdevtools rpm-sign scl-utils-build && \
10
+ yum clean all && rm -rf /var/cache/yum/*
11
+ <% elsif dist =~ /^el/ -%>
12
+ RUN dnf update -y && dnf clean all && rm -rf /var/cache/dnf/*
13
+ RUN dnf install -y dnf-utils epel-release langpacks-en glibc-all-langpacks && dnf clean all && rm -rf /var/cache/dnf/*
14
+ RUN dnf config-manager --set-enabled powertools && dnf clean all && rm -rf /var/cache/dnf/*
15
+ RUN dnf module enable -y ruby:<%= ruby_version %> && dnf clean all && rm -rf /var/cache/dnf/*
16
+ RUN dnf module enable -y nodejs:<%= nodejs_version %> && dnf clean all && rm -rf /var/cache/dnf/*
17
+ RUN dnf install -y ruby sudo which wget \
18
+ gcc-c++ gcc make patch \
19
+ rpm-build rpmdevtools rpm-sign scl-utils-build && \
20
+ dnf clean all && rm -rf /var/cache/dnf/*
21
+ <% elsif dist =~ /^ubuntu|debian/ -%>
22
+ ENV DEBIAN_FRONTEND=noninteractive
23
+ RUN apt update -y && apt upgrade -y && apt clean all -y
24
+ RUN apt update -y && apt install -y locales && locale-gen $LANG && \
25
+ apt clean all -y
26
+ RUN apt update -y && apt install -y apt-transport-https ca-certificates \
27
+ init debhelper devscripts dh-make build-essential lintian equivs \
28
+ sudo rake wget curl ruby && \
29
+ ln -snf /bin/bundle2.7 /bin/bundle && \
30
+ apt clean all -y
31
+ RUN echo "deb https://deb.nodesource.com/node_<%= nodejs_version %>.x <%= codename %> main" > /etc/apt/sources.list.d/nodesource.list
32
+ RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nodesource.gpg
33
+ <% end -%>
34
+ COPY . /build
35
+ RUN /bin/bash /build/install.sh
@@ -0,0 +1,30 @@
1
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
2
+ Version: GnuPG v2.0.22 (GNU/Linux)
3
+
4
+ mQENBFqB7y4BCADA2233uSAJC9EG3MM2EmmDjKCDy8Q9w3D1g48/roBUvONLveac
5
+ sx+rCSbP9Oc6sRJdxkQwppKKxKTwP5zGUGZto3wacaw2hTVfA7xFUfgcfZn3b0Az
6
+ fSTR2FlTnJ35THO1MkVNv/55D+qBOoEhrAGeUdB7TMGp9y+A6eHRYa0UdxY/rccY
7
+ xvz2oQOD6BH2s7IzLNUVLOifiu9Nrk213dghKOZjYwWERrpXj/EryuLm7wpKN349
8
+ pixk6zP4SIKj0L4HTwMqEcTCAxBKfidmUQ+JILvTRlTCItFPTcXJxqSI6jVA6Iu0
9
+ sZlO3XolEVdeGXL0MVjHVIpNZrV7vnTUFWPrABEBAAG0L09uRGVtYW5kIFJlbGVh
10
+ c2UgU2lnbmluZyBLZXkgPHBhY2thZ2VzQG9zYy5lZHU+iQE5BBMBAgAjBQJage8u
11
+ AhsDBwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQS3L+K5LTF1UQzgf5AQ8Q
12
+ Fy6JhxYaa56FHALiYCKJn+YHSbI4uZE6umpnV/14lU2Timw/xwNiH2ndlnl3a8be
13
+ NcYPYkX+7T5nWQty7YK3aIEEMeMY/I8Cb0RKaCoJwETbu9u4dKguAy19fj0h0jGC
14
+ v0lrBHNWfv572pr+TOcdVP2CFyfHybl6MvWFshM5mUxSeMItSa8KDVaWfZiPHzQe
15
+ YrL4ZcWvqLfBK/m8alvggg9zaOIyDKM30lbil66pY/rbveQyGW7SbpxiUh1rNsV4
16
+ aQOAVJRQC+uJn44OeTuB9nRR5nFLA70i+MtPbQNd3QiOHxuZN7c4sLkvmQslf1HZ
17
+ 7XoiYp0GlWMoI+YVXrkBDQRage8uAQgAut5ko4fkPkBfldawTCvTxnxnoa14RVwy
18
+ 3PcKxhaPmvHzdSjqquYYktgHIIGs8/UOrsFNPdHU6x02v0psaMwL8JX6JqFypPri
19
+ YltdXNU/NqlImzfBOkHnAhDiIEI/j34LkEpXhUCmJzeTGAu8wXS3tgx4cHgbfycg
20
+ MjmX7QBNghDzC3S+3Kt7wG4pNRlwyFd8r46CL5Yc6+UE9oNvnHdCy3W6OwCYCgXd
21
+ 919Bsf2Lpy1jGWV3YEiFgYv+pmF0T56vD1Rz+KbIhDEzQ4f/Q0dBZpcjZzQtSJQR
22
+ Wh5LX/8JzK0l3PrWOrVmW1GmKQ1DPIkAT2iR35ydgEbi/wuk+izeyQARAQABiQEf
23
+ BBgBAgAJBQJage8uAhsMAAoJEEty/iuS0xdVPtUH/16Kd1xX3PSGzOFatNJvfOR5
24
+ 5oCuVqMLm4sFXdrp0Spnn2B7Dx58jL0slwtWMh6xdtD/CKH/ihnM/um3h5JT0EvE
25
+ 9XTBfXwOkKgtdxgrHVeoT8gYNaw/0/kIlPavK5QviSNA64qUdFUvtg01FeyKmZ/R
26
+ jaRKJZUy+orHYZLo41uj7iGA5Op4gL70ydTnnYFcCb/eLOuGKci1yUzchjxY6YAa
27
+ 9/ZHhpAqcKsIqZWpzLimLTTH2E43YYVbRcyP9Csfm7qFG8m7RwjXdbquzfkMkujq
28
+ weYYi8Av2oajeR3NLoVvCPP2R3yT1YtDCuMRP8Pe4q9gmh7WKwdr38f6/an4VSI=
29
+ =uztj
30
+ -----END PGP PUBLIC KEY BLOCK-----
@@ -0,0 +1,3 @@
1
+ require 'ood_packaging/tasks'
2
+
3
+ task :default => 'ood_packaging:package:build'
@@ -0,0 +1,21 @@
1
+ #!/bin/bash
2
+ # Changes the '<%= ctr_user %>' user's UID and GID to the values specified
3
+ # in $OOD_UID and $OOD_GID.
4
+ set -e
5
+ set -o pipefail
6
+ if [[ "$DEBUG" == "true" ]]; then
7
+ set -x
8
+ fi
9
+
10
+ chown -R "$OOD_UID:$OOD_GID" <%= ctr_home %>
11
+ groupmod -o -g "$OOD_GID" <%= ctr_user %>
12
+ usermod -o -u "$OOD_UID" -g "$OOD_GID" <%= ctr_user %> 2>/dev/null 1>/dev/null
13
+
14
+ set +e
15
+ SCL_SOURCE="$(command -v scl_source)"
16
+ [[ "${SCL_SOURCE}" ]] && source "${SCL_SOURCE}" enable "<%= scl_ruby %>" &> /dev/null
17
+ set -e
18
+
19
+ if [[ $# -gt 0 ]]; then
20
+ exec "$@"
21
+ fi
@@ -0,0 +1,88 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ function header()
5
+ {
6
+ echo
7
+ echo "----- $@ -----"
8
+ }
9
+
10
+ function run()
11
+ {
12
+ echo "+ $@"
13
+ "$@"
14
+ }
15
+
16
+ export HOME=/root
17
+
18
+ <% if rpm? -%>
19
+ header "Add OnDemand build repo"
20
+ cat > /etc/yum.repos.d/ondemand-web.repo <<EOF
21
+ [ondemand-web]
22
+ name=Open OnDemand Web Repo
23
+ baseurl=https://yum.osc.edu/ondemand/build/<%= ondemand_repo_version %>/web/el\$releasever/\$basearch/
24
+ enabled=1
25
+ gpgcheck=0
26
+ EOF
27
+ run rpm --import /build/RPM-GPG-KEY-ondemand
28
+ <% end -%>
29
+
30
+ header "Creating users"
31
+ run groupadd <%= ctr_user %>
32
+ run useradd --home-dir <%= ctr_home %> --create-home --gid <%= ctr_user %> --password '<%= ctr_user %>' <%= ctr_user %>
33
+
34
+ header "Add sudo"
35
+ cat > /etc/sudoers.d/ood <<EOF
36
+ Defaults:<%= ctr_user %> !requiretty, !authenticate
37
+ %<%= ctr_user %> ALL=NOPASSWD:ALL
38
+ EOF
39
+ run chmod 440 /etc/sudoers.d/ood
40
+
41
+ <% if rpm? -%>
42
+ header "Setup RPM env"
43
+ sudo -u <%= ctr_user %> -H cat > <%= ctr_rpmmacros %> <<EOF
44
+ %_topdir /work/<%= dist %>
45
+ <%- # Workaround to weird issue with debuginfo stripping -%>
46
+ <% if dist == 'el7' -%>
47
+ %_builddir %{_topdir}/rpmbuild/BUILD
48
+ <% end -%>
49
+ %_signature gpg
50
+ %_gpg_path <%= ctr_gpg_dir %>
51
+ %_gpg /usr/bin/gpg
52
+ %_gpg_name @GPG_NAME@
53
+ # Modified macro from /usr/lib/rpm/macros to add pinentry-mode and passphrase-file
54
+ # pinentry-mode only needed on EL8
55
+ %__gpg_check_password_cmd %{__gpg} \\
56
+ gpg --batch --no-verbose --passphrase-file <%= gpg_passphrase %> -u "%{_gpg_name}" -so -
57
+ %__gpg_sign_cmd %{__gpg} \\
58
+ gpg --no-verbose --no-armor --batch \\
59
+ <%- if dnf? -%>
60
+ --pinentry-mode loopback \\
61
+ <%- end -%>
62
+ --passphrase-file <%= gpg_passphrase %> \\
63
+ %{?_gpg_sign_cmd_extra_args:%{_gpg_sign_cmd_extra_args}} \\
64
+ %{?_gpg_digest_algo:--digest-algo %{_gpg_digest_algo}} \\
65
+ --no-secmem-warning \\
66
+ -u \"%{_gpg_name}\" -sbo %{__signature_filename} %{__plaintext_filename}
67
+ EOF
68
+ <% end -%>
69
+ <%- if dnf? -%>
70
+ run install -d -m 0700 -o ood -g ood <%= ctr_gpg_dir %>
71
+ echo "allow-loopback-pinentry" >> <%= ctr_gpg_dir %>/gpg-agent.conf
72
+ <%- end -%>
73
+
74
+ header "Install ood_packaging gem"
75
+ <%- if rpm? && !dnf? -%>
76
+ run scl enable <%= scl_ruby %> -- gem install --no-doc /build/*.gem
77
+ <%- else -%>
78
+ run gem install --no-doc /build/*.gem
79
+ <%- end -%>
80
+
81
+ header "Copy in launch scripts"
82
+ run mkdir -p <%= ctr_scripts_dir %>
83
+ run install -m 0755 /build/inituidgid.sh <%= ctr_scripts_dir %>/
84
+ run install -m 0755 /build/setuser.rb <%= ctr_scripts_dir %>/
85
+ run install -m 0644 /build/Rakefile <%= ctr_scripts_dir %>/
86
+
87
+ header "Cleaning up"
88
+ run rm -rf /build
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'etc'
5
+
6
+ username = ARGV[0]
7
+ user = Etc.getpwnam(username)
8
+
9
+ Process.initgroups(username, user.gid)
10
+ Process::Sys.setgid(user.gid)
11
+ Process::Sys.setuid(user.uid)
12
+
13
+ ENV['USER'] = user.name
14
+ ENV['HOME'] = user.dir
15
+
16
+ exec(ARGV.drop(1).join(' '))