ood_packaging 0.0.1.r2.0 → 0.0.1.rc.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08137cd4ccfc377bfd70ad3ef9f10b1af265f873397323848fab54c546ae0e5e'
4
- data.tar.gz: d180ca4601d18558d9d37e607fb1ac5c27406d893709bd2cd1c837565140c834
3
+ metadata.gz: d76f705e0592bc694ee1e658e75da269f269489712392b3a412bc7db7ab566e7
4
+ data.tar.gz: c8eb63270d72d241ae87b1b82d9daeb1bb78382d529d636637fb2c8db1c5d9cb
5
5
  SHA512:
6
- metadata.gz: 37002fb96167b8310a3cb42bd6a3d4980ba0410d96b8eb3921e44de456a481c2f6c07f6dfda1b02da960043e12bfa0b474eac4fc2dda89021c9f0ff04610e7ed
7
- data.tar.gz: e93b9c5b83b07637220354dedf9b17acdabaee8f53c2b9225ff9ac4adf7034c4b10c94ed2497a468f516a7c393094d04df6ff5b4091802648597fa4948241f4a
6
+ metadata.gz: 6abb5c9b384d917d91570578518be7f53a3b28568f4fa6bf50568d7903b7eae916b62be9b32e37607302f7227b1af3c1b811679b2ce17d05243c2b52503b224b
7
+ data.tar.gz: fb24936ba8e69d351b00032b5afe02fc3520629ea694d91a068bad906185275d0d2ce1a5c65a206ded893e70b1992c7dcae92378d0aa8959aed270486696f6a1
data/bin/ood_packaging CHANGED
@@ -2,9 +2,13 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'optparse'
5
- libdir = File.expand_path(File.join(__dir__, '../lib'))
6
- $LOAD_PATH.unshift(libdir) if Dir.exist?(libdir)
7
- require 'ood_packaging'
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
8
12
 
9
13
  options = {}
10
14
  OptionParser.new do |opts|
@@ -39,11 +39,11 @@ class OodPackaging::Build
39
39
  end
40
40
 
41
41
  def version
42
- ENV['VERSION']
42
+ ENV['VERSION'].gsub(/^v/, '')
43
43
  end
44
44
 
45
45
  def rpm_version
46
- version.gsub(/^v/, '').split('-', 2)[0]
46
+ version.split('-', 2)[0]
47
47
  end
48
48
 
49
49
  def rpm_release
@@ -53,12 +53,8 @@ class OodPackaging::Build
53
53
  v[1].gsub('-', '.')
54
54
  end
55
55
 
56
- def deb_version
57
- version.gsub(/^v/, '').gsub('-', '.')
58
- end
59
-
60
56
  def rpm_defines
61
- defines = ["--define 'git_tag #{version}'"]
57
+ defines = ["--define 'git_tag #{ENV['VERSION']}'"]
62
58
  defines.concat ["--define 'package_version #{rpm_version}'"]
63
59
  defines.concat ["--define 'package_release #{rpm_release}'"]
64
60
  defines.concat ["--define 'scl #{config[:scl]}'"] if config[:scl]
@@ -76,8 +72,6 @@ class OodPackaging::Build
76
72
  '/package/rpm'
77
73
  elsif Dir.exist?('/package/packaging/rpm')
78
74
  '/package/packaging/rpm'
79
- elsif Dir.exist?('/package/packaging')
80
- '/package/packaging'
81
75
  else
82
76
  '/package'
83
77
  end
@@ -94,8 +88,6 @@ class OodPackaging::Build
94
88
  def debian_dir
95
89
  @debian_dir ||= if Dir.exist?('/package/deb/debian')
96
90
  '/package/deb/debian'
97
- elsif Dir.exist?('/package/packaging/deb')
98
- '/package/packaging/deb'
99
91
  else
100
92
  '/package/debian'
101
93
  end
@@ -130,7 +122,7 @@ class OodPackaging::Build
130
122
  end
131
123
 
132
124
  def deb_name
133
- "#{package}-#{deb_version}"
125
+ "#{package}-#{version}"
134
126
  end
135
127
 
136
128
  def rpms
@@ -138,7 +130,6 @@ class OodPackaging::Build
138
130
  end
139
131
 
140
132
  def run!
141
- fix_env!
142
133
  env_dump! if debug?
143
134
  bootstrap_rpm! if build_box.rpm?
144
135
  bootstrap_deb! if build_box.deb?
@@ -150,10 +141,6 @@ class OodPackaging::Build
150
141
  sanity!
151
142
  end
152
143
 
153
- def fix_env!
154
- ENV.delete('GEM_PATH')
155
- end
156
-
157
144
  def env_dump!
158
145
  ENV.sort.to_h.each_pair do |k, v|
159
146
  puts "#{k}=#{v}"
@@ -194,17 +181,10 @@ class OodPackaging::Build
194
181
  def bootstrap_get_source!
195
182
  if ENV['SKIP_DOWNLOAD'] == 'true'
196
183
  puts "\tSKIP_DOWNLOAD detected, skipping download sources".blue
197
- return
198
- end
199
- output = `spectool #{rpm_defines.join(' ')} -l -R -S #{spec_file} 2>&1 | grep 'Source0:'`.strip
200
- exit_code = $CHILD_STATUS.exitstatus
201
- if exit_code.zero?
202
- source = File.join(work_dir, 'SOURCES', File.basename(output))
203
- tar = File.join(work_dir, 'SOURCES', ENV['TAR_NAME'])
204
- sh "mv #{tar} #{source}" if !File.exist?(source) && File.exist?(tar)
184
+ else
185
+ puts "\tDownloading sources defined in #{spec_file}".blue
186
+ sh "spectool #{rpm_defines.join(' ')} -g -R -S #{spec_file}#{cmd_suffix}"
205
187
  end
206
- puts "\tDownloading sources defined in #{spec_file}".blue
207
- sh "spectool #{rpm_defines.join(' ')} -g -R -S #{spec_file}#{cmd_suffix}"
208
188
  end
209
189
 
210
190
  def bootstrap_deb!
@@ -221,7 +201,7 @@ class OodPackaging::Build
221
201
  puts "\tBootstrap debian build files".blue
222
202
  Dir.chdir(deb_work_dir) do
223
203
  sh "dh_make -s -y --createorig -f ../#{deb_name}.tar.gz#{cmd_suffix} || true"
224
- sh "dch -b -v #{deb_version} --controlmaint 'Release #{deb_version}'#{cmd_suffix}"
204
+ sh "dch -b -v #{version} 'Release #{version}'#{cmd_suffix}"
225
205
  end
226
206
  end
227
207
 
@@ -247,14 +227,9 @@ class OodPackaging::Build
247
227
 
248
228
  def install_deb_dependencies!
249
229
  sh "sudo apt update -y#{cmd_suffix}"
250
- tool = [
251
- 'DEBIAN_FRONTEND=noninteractive apt-cudf-get --solver aspcud',
252
- '-o APT::Get::Assume-Yes=1 -o APT::Get::Allow-Downgrades=1',
253
- '-o Debug::pkgProblemResolver=0 -o APT::Install-Recommends=0'
254
- ]
255
230
  cmd = [
256
231
  'mk-build-deps --install --remove --root-cmd sudo',
257
- "--tool='#{tool.join(' ')}'"
232
+ "--tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes'"
258
233
  ]
259
234
  Dir.chdir(deb_work_dir) do
260
235
  sh "#{cmd.join(' ')}#{cmd_suffix}"
@@ -2,35 +2,31 @@ FROM <%= base_image %>
2
2
  MAINTAINER Trey Dockendorf <tdockendorf@osc.edu>
3
3
  ENV LANG=en_US.UTF-8
4
4
  ENV LC_CTYPE=en_US.UTF-8
5
- ENV USER=<%= ctr_user %>
6
- ENV GEM_PATH=<%= ctr_gems_dir %>:
7
- <% if scl? -%>
5
+ <% if dist == 'el7' -%>
8
6
  RUN yum update -y && yum clean all && rm -rf /var/cache/yum/*
9
7
  RUN yum install -y yum-utils epel-release centos-release-scl && yum clean all && rm -rf /var/cache/yum/*
10
8
  RUN yum install -y <%= scl_ruby %>-ruby sudo which wget @buildsys-build \
11
9
  rpm-build rpmdevtools rpm-sign scl-utils-build && \
12
10
  yum clean all && rm -rf /var/cache/yum/*
13
- RUN rm -f /etc/yum.repos.d/CentOS-Vault.repo /etc/yum.repos.d/CentOS-Sources.repo
14
- RUN head -n 13 /etc/yum.repos.d/CentOS-SCLo-scl.repo > /etc/yum.repos.d/CentOS-SCLo.repo
15
- RUN head -n 13 /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo >> /etc/yum.repos.d/CentOS-SCLo.repo
16
- RUN rm -f /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo /etc/yum.repos.d/CentOS-SCLo-scl.repo
17
- <% elsif dnf? -%>
11
+ <% elsif dist =~ /^el/ -%>
18
12
  RUN dnf update -y && dnf clean all && rm -rf /var/cache/dnf/*
19
13
  RUN dnf install -y dnf-utils epel-release langpacks-en glibc-all-langpacks && dnf clean all && rm -rf /var/cache/dnf/*
20
14
  RUN dnf config-manager --set-enabled powertools && dnf clean all && rm -rf /var/cache/dnf/*
21
- RUN dnf module enable -y ruby:<%= ruby_version %> nodejs:<%= nodejs_version %> && dnf clean all && rm -rf /var/cache/dnf/*
22
- RUN dnf install -y systemd ruby nodejs sudo which wget \
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 \
23
18
  gcc-c++ gcc make patch \
24
19
  rpm-build rpmdevtools rpm-sign scl-utils-build && \
25
20
  dnf clean all && rm -rf /var/cache/dnf/*
26
- <% elsif deb? -%>
21
+ <% elsif dist =~ /^ubuntu|debian/ -%>
27
22
  ENV DEBIAN_FRONTEND=noninteractive
28
23
  RUN apt update -y && apt upgrade -y && apt clean all -y
29
24
  RUN apt update -y && apt install -y locales && locale-gen $LANG && \
30
25
  apt clean all -y
31
26
  RUN apt update -y && apt install -y apt-transport-https ca-certificates \
32
- init debhelper devscripts dh-make build-essential apt-cudf lintian equivs \
33
- sudo rake wget curl ruby bundler && \
27
+ init debhelper devscripts dh-make build-essential lintian equivs \
28
+ sudo rake wget curl ruby && \
29
+ ln -snf /bin/bundle2.7 /bin/bundle && \
34
30
  apt clean all -y
35
31
  RUN echo "deb https://deb.nodesource.com/node_<%= nodejs_version %>.x <%= codename %> main" > /etc/apt/sources.list.d/nodesource.list
36
32
  RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor > /etc/apt/trusted.gpg.d/nodesource.gpg
@@ -72,10 +72,10 @@ echo "allow-loopback-pinentry" >> <%= ctr_gpg_dir %>/gpg-agent.conf
72
72
  <%- end -%>
73
73
 
74
74
  header "Install ood_packaging gem"
75
- <%- if scl? -%>
76
- run scl enable <%= scl_ruby %> -- gem install --no-doc --bindir <%= ctr_scripts_dir %> --install-dir <%= ctr_gems_dir %> /build/*.gem
75
+ <%- if rpm? && !dnf? -%>
76
+ run scl enable <%= scl_ruby %> -- gem install --no-doc /build/*.gem
77
77
  <%- else -%>
78
- run gem install --no-doc --bindir <%= ctr_scripts_dir %> --install-dir <%= ctr_gems_dir %> /build/*.gem
78
+ run gem install --no-doc /build/*.gem
79
79
  <%- end -%>
80
80
 
81
81
  header "Copy in launch scripts"
@@ -21,17 +21,17 @@ class OodPackaging::BuildBox
21
21
 
22
22
  def initialize(config = {})
23
23
  @config = config
24
- raise ArgumentError, 'Must provide dist' if dist.nil?
24
+ raise ArgumentError, 'Must provide dist' if @config[:dist].nil?
25
25
 
26
26
  # rubocop:disable Style/GuardClause
27
- unless valid_dist?(dist)
28
- raise ArgumentError, "Invalid dist selected: #{dist}. Valid choices are #{valid_dists.join(' ')}"
27
+ unless valid_dist?(@config[:dist])
28
+ raise ArgumentError, "Invalid dist selected: #{@config[:dist]}. Valid choices are #{valid_dists.join(' ')}"
29
29
  end
30
30
  # rubocop:enable Style/GuardClause
31
31
  end
32
32
 
33
33
  def dist
34
- @dist ||= ENV['OOD_PACKAGING_DIST'] || @config[:dist]
34
+ @dist ||= @config[:dist]
35
35
  end
36
36
 
37
37
  def rpm?
@@ -95,7 +95,7 @@ class OodPackaging::BuildBox
95
95
  end
96
96
 
97
97
  def image_version
98
- (ENV['OOD_PACKAGING_BUILD_BOX_VERSION'] || OodPackaging::VERSION).gsub(/^v/, '')
98
+ ENV['OOD_PACKAGING_BUILD_BOX_VERSION'] || OodPackaging::VERSION
99
99
  end
100
100
 
101
101
  def image_tag
@@ -133,10 +133,6 @@ class OodPackaging::BuildBox
133
133
  sh [container_runtime, 'push', image_tag].join(' ')
134
134
  end
135
135
 
136
- def pull!
137
- sh [container_runtime, 'pull', image_tag].join(' ')
138
- end
139
-
140
136
  def save!(path)
141
137
  sh [container_runtime, 'save', image_tag, '| gzip >', path].join(' ')
142
138
  end
@@ -21,6 +21,8 @@ class OodPackaging::Package
21
21
  @config = config
22
22
  @config[:dist] = 'el8' if tar_only?
23
23
  @build_box = OodPackaging::BuildBox.new(config)
24
+ @clean_work_dir = config[:clean_work_dir].nil? ? true : config[:clean_work_dir]
25
+ @clean_output_dir = config[:clean_output_dir].nil? ? true : config[:clean_output_dir]
24
26
  raise ArgumentError, 'Package is required' if package.nil?
25
27
  raise ArgumentError, 'Version is required' if version.nil?
26
28
  raise ArgumentError, "Package #{package} is not a directory" unless Dir.exist?(package)
@@ -31,18 +33,12 @@ class OodPackaging::Package
31
33
  @container_name ||= SecureRandom.uuid
32
34
  end
33
35
 
34
- def debug?
36
+ def debug
35
37
  return true if ENV['OOD_PACKAGING_DEBUG'] == 'true'
36
38
 
37
39
  @config[:debug].nil? ? false : @config[:debug]
38
40
  end
39
41
 
40
- def cmd_suffix
41
- return '' if debug?
42
-
43
- ' 2>/dev/null 1>/dev/null'
44
- end
45
-
46
42
  def attach?
47
43
  return true if ENV['OOD_PACKAGING_ATTACH'] == 'true'
48
44
 
@@ -53,22 +49,10 @@ class OodPackaging::Package
53
49
  @work_dir ||= File.expand_path(@config[:work_dir])
54
50
  end
55
51
 
56
- def clean_work_dir
57
- return false if ENV['OOD_PACKAGING_CLEAN_WORK_DIR'] == 'false'
58
-
59
- @config[:clean_work_dir].nil? ? true : @config[:clean_work_dir]
60
- end
61
-
62
52
  def output_dir
63
53
  @output_dir ||= File.expand_path(@config[:output_dir])
64
54
  end
65
55
 
66
- def clean_output_dir
67
- return false if ENV['OOD_PACKAGING_CLEAN_OUTPUT_DIR'] == 'false'
68
-
69
- @config[:clean_output_dir].nil? ? true : @config[:clean_output_dir]
70
- end
71
-
72
56
  def package
73
57
  @config[:package]
74
58
  end
@@ -91,21 +75,20 @@ class OodPackaging::Package
91
75
 
92
76
  def package_name
93
77
  name = File.basename(package)
94
- case name
95
- when /deb|rpm/
78
+ if name =~ /deb|rpm/
96
79
  name = if File.basename(File.dirname(package)) == 'packages'
97
80
  File.basename(File.dirname(File.dirname(package)))
98
81
  else
99
82
  File.basename(File.dirname(package))
100
83
  end
101
- when 'packaging'
102
- name = File.basename(File.dirname(package))
103
84
  end
104
85
  name
105
86
  end
106
87
 
107
88
  def gpg_files
108
89
  [
90
+ OpenStruct.new(private_key: File.join(proj_root, 'ondemand.sec'), passphrase: File.join(proj_root, '.gpgpass')),
91
+ OpenStruct.new(private_key: File.join(package, 'ondemand.sec'), passphrase: File.join(package, '.gpgpass')),
109
92
  OpenStruct.new(private_key: @config[:gpg_private_key], passphrase: @config[:gpg_passphrase]),
110
93
  OpenStruct.new(private_key: ENV['OOD_PACKAGING_GPG_PRIVATE_KEY'],
111
94
  passphrase: ENV['OOD_PACKAGING_GPG_PASSPHRASE'])
@@ -123,12 +106,8 @@ class OodPackaging::Package
123
106
  !gpg_files.nil?
124
107
  end
125
108
 
126
- def default_gpg_name
127
- 'OnDemand Release Signing Key'
128
- end
129
-
130
109
  def gpg_name
131
- @config[:gpg_name].nil? ? default_gpg_name : @config[:gpg_name]
110
+ @config[:gpg_name].nil? ? 'OnDemand Release Signing Key' : @config[:gpg_name]
132
111
  end
133
112
 
134
113
  def container_init
@@ -144,23 +123,10 @@ class OodPackaging::Package
144
123
  package
145
124
  end
146
125
 
147
- def tar_name
148
- version = if build_box.rpm?
149
- rpm_version
150
- else
151
- deb_version
152
- end
153
- "#{package_name}-#{version}"
154
- end
155
-
156
126
  def rpm_tar_dest_dir
157
- [
158
- File.join(package, 'rpm'),
159
- File.join(package, 'packaging/rpm'),
160
- File.join(package, 'packaging')
161
- ].each do |dir|
162
- return dir if Dir.exist?(dir)
163
- end
127
+ dir = File.join(package, 'rpm')
128
+ return dir if Dir.exist?(dir)
129
+
164
130
  File.join(package, 'packaging/rpm')
165
131
  end
166
132
 
@@ -191,8 +157,8 @@ class OodPackaging::Package
191
157
  cmd = []
192
158
  cmd.concat exec_launchers if docker_runtime?
193
159
  cmd.concat ['scl', 'enable', scl_ruby, '--'] if podman_runtime? && build_box.scl?
194
- cmd.concat [File.join(ctr_scripts_dir, 'rake')]
195
- cmd.concat ['-q'] unless debug?
160
+ cmd.concat ['rake']
161
+ cmd.concat ['-q'] unless debug
196
162
  cmd.concat ['-f', File.join(ctr_scripts_dir, 'Rakefile'), 'ood_packaging:package:build']
197
163
  cmd
198
164
  end
@@ -218,31 +184,33 @@ class OodPackaging::Package
218
184
  end
219
185
 
220
186
  def clean!
221
- sh "rm -rf #{work_dir}", verbose: debug? if clean_work_dir
222
- sh "rm -rf #{output_dir}", verbose: debug? if clean_output_dir
187
+ sh "rm -rf #{work_dir}", verbose: debug if @clean_work_dir
188
+ sh "rm -rf #{output_dir}", verbose: debug if @clean_output_dir
223
189
  end
224
190
 
225
191
  def bootstrap!
226
- sh "mkdir -p #{work_dir}", verbose: debug?
227
- sh "mkdir -p #{output_dir}", verbose: debug?
192
+ sh "mkdir -p #{work_dir}", verbose: debug
193
+ sh "mkdir -p #{output_dir}", verbose: debug
228
194
  end
229
195
 
230
196
  def tar!
231
197
  cmd = ['git', 'ls-files', '.', '|', tar, '-c']
232
198
  if build_box.rpm?
233
199
  dir = rpm_tar_dest_dir
200
+ version = rpm_version
234
201
  else
235
202
  dir = deb_tar_dest_dir.tap { |p| sh "mkdir -p #{p}" }
203
+ version = deb_version
236
204
  cmd.concat ["--transform 'flags=r;s,packaging/deb,debian,'"]
237
205
  end
238
- tar_file = "#{dir}/#{tar_name}.tar.gz"
239
- cmd.concat ["--transform 's,^,#{tar_name}/,'"]
206
+ tar_file = "#{dir}/#{package_name}-#{version}.tar.gz"
207
+ cmd.concat ["--transform 's,^,#{package_name}-#{version}/,'"]
240
208
  cmd.concat ['-T', '-', '|', "gzip > #{tar_file}"]
241
209
 
242
210
  sh "rm #{tar_file}" if File.exist?(tar_file)
243
211
  puts "Create tar archive #{tar_file}".blue
244
212
  Dir.chdir(tar_path) do
245
- sh cmd.join(' '), verbose: debug?
213
+ sh cmd.join(' '), verbose: debug
246
214
  end
247
215
  end
248
216
 
@@ -256,19 +224,19 @@ class OodPackaging::Package
256
224
  tar! if tar?
257
225
  container_start!
258
226
  container_exec!(exec_rake)
259
- puts "Build SUCCESS: package=#{package} dist=#{build_box.dist}".green
260
227
  rescue RuntimeError
228
+ # ret = 1
261
229
  puts "Build FAILED package=#{package} dist=#{build_box.dist}".red
262
230
  raise
231
+ else
232
+ puts "Build SUCCESS: package=#{package} dist=#{build_box.dist}".green
263
233
  ensure
264
234
  container_exec!(exec_attach, ['-i', '-t']) if attach?
265
- container_kill! if container_running? && !attach?
235
+ container_kill! if container_running?
266
236
  end
267
237
 
268
238
  def container_running?
269
- cmd = "#{container_runtime} inspect #{container_name} 2>/dev/null 1>/dev/null"
270
- puts cmd if debug?
271
- `#{cmd}`
239
+ `#{container_runtime} inspect #{container_name} 2>/dev/null 1>/dev/null`
272
240
  $CHILD_STATUS.success?
273
241
  end
274
242
 
@@ -279,9 +247,9 @@ class OodPackaging::Package
279
247
  cmd.concat container_mounts
280
248
  cmd.concat [build_box.image_tag]
281
249
  cmd.concat [container_init]
282
- cmd.concat ['1>/dev/null'] unless debug?
250
+ cmd.concat ['1>/dev/null'] unless debug
283
251
  puts "Starting container #{container_name} using image #{build_box.image_tag}".blue
284
- sh cmd.join(' '), verbose: debug?
252
+ sh cmd.join(' '), verbose: debug
285
253
  end
286
254
 
287
255
  def container_exec!(exec_cmd, extra_args = [])
@@ -293,33 +261,29 @@ class OodPackaging::Package
293
261
  cmd.concat [container_name]
294
262
  cmd.concat exec_cmd
295
263
  puts "Build STARTED: package=#{package} dist=#{build_box.dist} exec=#{exec_cmd[-1]}".blue
296
- sh cmd.join(' '), verbose: debug?
297
- true
298
- rescue RuntimeError
299
- container_kill! if container_running? && !attach?
300
- raise
264
+ sh cmd.join(' '), verbose: debug
301
265
  end
302
266
 
303
267
  def container_kill!
304
268
  puts "Killing container #{container_name}".blue
305
269
  cmd = [container_runtime, 'kill', container_name]
306
- cmd.concat [cmd_suffix] unless debug?
307
- sh cmd.join(' '), verbose: debug?
270
+ cmd.concat ['1>/dev/null', '2>/dev/null'] unless debug
271
+ sh cmd.join(' '), verbose: debug
308
272
  end
309
273
 
310
274
  def container_env
311
275
  env = {
312
276
  'DIST' => build_box.dist,
313
277
  'PACKAGE' => package_name,
314
- 'VERSION' => version,
315
- 'TAR_NAME' => "#{tar_name}.tar.gz",
316
278
  'GPG_SIGN' => gpg_sign,
317
279
  'GPG_NAME' => gpg_name,
318
280
  'SKIP_DOWNLOAD' => @config[:skip_download],
319
281
  'OOD_UID' => Process.uid,
320
282
  'OOD_GID' => Process.gid,
321
- 'DEBUG' => debug?
283
+ 'DEBUG' => debug
322
284
  }
285
+ env['VERSION'] = rpm_version if build_box.rpm?
286
+ env['VERSION'] = deb_version if build_box.deb?
323
287
  env['GPG_PUBKEY'] = '/gpg.pub' if @config[:gpg_pubkey]
324
288
  env
325
289
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ood_packaging'
3
+ require 'ood_packaging/options'
4
+ require 'ood_packaging/package'
5
+ require 'ood_packaging/utils'
4
6
  require 'rake'
5
7
  require 'rake/tasklib'
6
8
 
@@ -7,14 +7,6 @@ require 'ood_packaging/utils'
7
7
  namespace :ood_packaging do
8
8
  include OodPackaging::Utils
9
9
 
10
- desc 'Set version'
11
- task :version, [:version] do |_task, args|
12
- version_file = File.join(proj_root, 'lib/ood_packaging/version.rb')
13
- version = args[:version].gsub(/^v/, '')
14
- sh "#{sed} -i -r \"s| VERSION =.*| VERSION = '#{version}'|g\" #{version_file}"
15
- sh 'bundle install'
16
- end
17
-
18
10
  namespace :buildbox do
19
11
  desc 'Build buildbox image'
20
12
  task :build, [:dist] do |_task, args|
@@ -28,12 +20,6 @@ namespace :ood_packaging do
28
20
  @build_box.push!
29
21
  end
30
22
 
31
- desc 'Pull buildbox image'
32
- task :pull, [:dist] do |_task, args|
33
- @build_box = OodPackaging::BuildBox.new(args)
34
- @build_box.pull!
35
- end
36
-
37
23
  desc 'Save buildbox image'
38
24
  task :save, [:dist, :path] do |_task, args|
39
25
  @build_box = OodPackaging::BuildBox.new(args)
@@ -50,9 +36,8 @@ namespace :ood_packaging do
50
36
  OodPackaging::RakeTask.new(:internal, [:package, :dist]) do |t, args|
51
37
  name = args[:package].split(':').last
52
38
  t.package = File.join(proj_root, 'packages', name)
53
- dist = args[:dist] || ENV['OOD_PACKAGING_DIST']
54
- t.dist = dist
55
- t.version = OodPackaging.package_version(name, dist)
39
+ t.dist = args[:dist]
40
+ t.version = OodPackaging.package_version(name, args[:dist])
56
41
  t.work_dir = File.join(proj_root, 'tmp/work')
57
42
  t.output_dir = File.join(proj_root, 'tmp/output')
58
43
  end
@@ -15,13 +15,6 @@ module OodPackaging::Utils
15
15
  end
16
16
  end
17
17
 
18
- def sed
19
- @sed ||= begin
20
- `which gsed 1>/dev/null 2>&1`
21
- $CHILD_STATUS.success? ? 'gsed' : 'sed'
22
- end
23
- end
24
-
25
18
  def podman_runtime?
26
19
  @podman_runtime ||= ENV['CONTAINER_RT'] == 'podman' || ENV['container'] == 'podman'
27
20
  end
@@ -55,7 +48,7 @@ module OodPackaging::Utils
55
48
  end
56
49
 
57
50
  def ondemand_repo_version
58
- '2.0'
51
+ '2.1'
59
52
  end
60
53
 
61
54
  def ruby_version
@@ -67,17 +60,13 @@ module OodPackaging::Utils
67
60
  end
68
61
 
69
62
  def nodejs_version
70
- '12'
63
+ '14'
71
64
  end
72
65
 
73
66
  def ctr_scripts_dir
74
67
  '/ondemand-packaging'
75
68
  end
76
69
 
77
- def ctr_gems_dir
78
- File.join(ctr_scripts_dir, 'gems')
79
- end
80
-
81
70
  def gpg_private_key
82
71
  File.join(ctr_scripts_dir, 'ondemand.sec')
83
72
  end
@@ -2,25 +2,25 @@
2
2
 
3
3
  # Version code for OodPackaging
4
4
  module OodPackaging
5
- VERSION = '0.0.1.r2.0'
5
+ VERSION = '0.0.1.rc.3'
6
6
  PACKAGE_VERSION = {
7
7
  'ondemand-release' => {
8
- '(ubuntu|debian)' => '2.0.0',
9
- 'default' => '2.0'
8
+ '(ubuntu|debian)' => '2.1.0',
9
+ 'default' => '2.1'
10
10
  },
11
11
  'ondemand-release-latest' => {
12
12
  '(ubuntu|debian)' => '1',
13
- 'default' => '1-7'
13
+ 'default' => '1-6'
14
14
  },
15
- 'ondemand-runtime' => '2.0-2',
16
- 'passenger' => '6.0.14',
15
+ 'ondemand-runtime' => '2.1',
16
+ 'passenger' => '6.0.11',
17
17
  'cjose' => '0.6.1',
18
18
  'mod_auth_openidc' => '2.4.5',
19
19
  'sqlite' => '3.26.0-4',
20
20
  'ondemand_exporter' => '0.9.0',
21
21
  'ondemand-compute' => {
22
- '(ubuntu|debian)' => '2.0',
23
- 'default' => '2.0'
22
+ '(ubuntu|debian)' => '2.1.0',
23
+ 'default' => '2.1'
24
24
  },
25
25
  'python-websockify' => '0.8.0',
26
26
  'turbovnc' => '2.2.5'
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require 'erb'
5
+ require 'tempfile'
6
+
7
+ # Package utilities
8
+ module PackageUtils
9
+ def version
10
+ @version ||= if ENV['VERSION']
11
+ ENV['VERSION'].to_s
12
+ else
13
+ tag? ? git_tag : "#{git_tag}-#{git_hash}"
14
+ end
15
+ end
16
+
17
+ def build_timestamp
18
+ @build_timestamp ||= Time.now.strftime('%s')
19
+ end
20
+
21
+ def git_hash
22
+ @git_hash ||= `git rev-parse HEAD`.strip[0..6]
23
+ end
24
+
25
+ def git_tag
26
+ @git_tag ||= `git describe --tags --abbrev=0`.chomp
27
+ end
28
+
29
+ def numeric_tag
30
+ @numeric_tag ||= git_tag.delete_prefix('v')
31
+ end
32
+
33
+ def tag?
34
+ @tag ||= `git describe --exact-match --tags HEAD 2>/dev/null`.to_s != ''
35
+ end
36
+
37
+ def podman_runtime?
38
+ @podman_runtime ||= ENV['CONTAINER_RT'] == 'podman'
39
+ end
40
+
41
+ def docker_runtime?
42
+ !podman_runtime?
43
+ end
44
+
45
+ def container_runtime
46
+ podman_runtime? ? 'podman' : 'docker'
47
+ end
48
+
49
+ def tar
50
+ @tar ||= begin
51
+ `which gtar 1>/dev/null 2>&1`
52
+ $CHILD_STATUS.success? ? 'gtar' : 'tar'
53
+ end
54
+ end
55
+
56
+ def src_dir
57
+ ENV['OOD_SRC_DIR'] || '.'
58
+ end
59
+
60
+ def user
61
+ @user ||= Etc.getpwnam(Etc.getlogin)
62
+ end
63
+
64
+ def build_dir(args)
65
+ @build_dir ||= "#{src_dir}/build/#{build_box_image(args).gsub(':', '-')}".tap { |d| sh "mkdir -p #{d}" }
66
+ end
67
+
68
+ # TODO: continue vendor/ convention? Seems as good as any other name.
69
+ def vendor_src_dir
70
+ 'vendor/ood/src'.tap { |p| sh "mkdir -p #{p}" }
71
+ end
72
+
73
+ def vendor_build_dir
74
+ 'vendor/ood/build'.tap { |p| sh "mkdir -p #{p}" }
75
+ end
76
+
77
+ def dist_dir(args)
78
+ dist = args[:dist].to_s
79
+ version = args[:version].to_s
80
+ "dist/#{dist}#{version}"
81
+ end
82
+
83
+ def known_images
84
+ {
85
+ 'ubuntu-20.04': '1'
86
+ }.freeze
87
+ end
88
+
89
+ def build_box_image(args)
90
+ base_name = "#{args[:dist]}-#{args[:version]}"
91
+ @version_lookup ||= Hash.new('1').merge(known_images)
92
+
93
+ "#{build_box_name}:#{base_name}-#{@version_lookup[base_name.to_sym]}"
94
+ end
95
+
96
+ def build_box_name
97
+ ENV['OOD_BUILD_BOX'] || 'ood-buildbox'
98
+ end
99
+
100
+ def image_exists?(image_name)
101
+ `#{container_runtime} inspect --type image --format exists #{image_name} || true`.chomp.eql?('exists')
102
+ end
103
+
104
+ def build_cmd(file, image)
105
+ args = [container_runtime, 'build', '-t', image, '-f', file]
106
+ args.concat '.' if docker_runtime?
107
+ args.join(' ')
108
+ end
109
+
110
+ def template_file(filename)
111
+ cwd = File.expand_path(__dir__).to_s
112
+ content = File.read("#{cwd}/templates/#{filename}")
113
+ content = ERB.new(content, trim_mode: '-').result(binding)
114
+
115
+ begin
116
+ t = Tempfile.new('ood-docker')
117
+ t.write(content)
118
+ t.path
119
+ ensure
120
+ t.close
121
+ end
122
+ end
123
+
124
+ def ctr_home
125
+ "/home/#{ctr_user}"
126
+ end
127
+
128
+ def ctr_user
129
+ 'ood'
130
+ end
131
+
132
+ def ctr_run_args
133
+ [
134
+ '--rm', '--user', "#{ctr_user}:#{ctr_user}",
135
+ '-e', 'LC_CTYPE=en_US.UTF-8'
136
+ ].concat(rt_specific_flags)
137
+ end
138
+
139
+ def rt_specific_flags
140
+ if podman_runtime?
141
+ # SELinux doesn't like it if you're mounting from $HOME
142
+ ['--security-opt', 'label=disable', '--userns=keep-id']
143
+ else
144
+ []
145
+ end
146
+ end
147
+
148
+ def arch
149
+ 'x86_64'
150
+ end
151
+
152
+ def spec_location
153
+ sf = Dir.glob('packaging/rpm/*.spec').first
154
+ raise StandardError, 'Cannot find spec file in packaging/rpm' if sf.nil?
155
+
156
+ sf
157
+ end
158
+
159
+ def spec_file
160
+ File.basename(spec_location)
161
+ end
162
+
163
+ def rpm_build_args
164
+ [git_tag_define, version_define, '-ba', '--nodeps', '-vv', spec_file]
165
+
166
+ # if git_prerelease_tag.size >= 2
167
+ # git_prerelease_verison = git_prerelease_tag[0]
168
+ # git_prerelease_verison = git_prerelease_verison[1..-1] if git_prerelease_verison.start_with?('v')
169
+ # version_define = "--define 'package_version #{git_prerelease_verison}'"
170
+ # if git_tag.size >= 2
171
+ # prerelease = git_prerelease_tag[1].gsub('-', '.')
172
+ # release_define = "--define 'package_release 0.#{prerelease}'"
173
+ # else
174
+ # release_define = "--define 'package_release 0.#{git_prerelease_tag[1]}.1'"
175
+ # end
176
+ # else
177
+ # version_define = "--define 'package_version #{git_tag_version}'"
178
+ # release_define = if git_tag.size >= 2
179
+ # "--define 'package_release #{git_tag[1]}'"
180
+ # else
181
+ # ''
182
+ # end
183
+ # end
184
+ end
185
+
186
+ def version_define
187
+ git_tag = version.split('-')
188
+ git_tag_version = git_tag[0]
189
+ git_tag_version = git_tag_version[1..] if git_tag_version.start_with?('v')
190
+
191
+ "--define 'package_version #{git_tag_version}'"
192
+ end
193
+
194
+ def git_tag_define
195
+ "--define 'git_tag #{version}'"
196
+ end
197
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc 'Package OnDemand'
4
+ namespace :package do
5
+ require_relative 'package_utils'
6
+ include PackageUtils
7
+
8
+ desc 'Tar and zip OnDemand into packaging dir with version name v#<version>'
9
+ task :tar, [:output_dir] do |_task, args|
10
+ version = ENV['VERSION'] || ENV['CI_COMMIT_TAG']
11
+ version = version.gsub(/^v/, '') unless version.nil?
12
+
13
+ chdir src_dir do
14
+ unless version
15
+ latest_commit = `git rev-list --tags --max-count=1`.strip[0..6]
16
+ latest_tag = `git describe --tags #{latest_commit}`.strip[1..]
17
+ datetime = Time.now.strftime('%Y%m%d-%H%M')
18
+ version = "#{latest_tag}-#{datetime}-#{latest_commit}"
19
+ end
20
+
21
+ dir = (args[:output_dir] || 'packaging/rpm').to_s.tap { |p| sh "mkdir -p #{p}" }
22
+ sh "git ls-files | #{tar} -c --transform 's,^,ondemand-#{version}/,' -T - | gzip > #{dir}/v#{version}.tar.gz"
23
+ end
24
+ end
25
+
26
+ # TODO: refactor these 2 tar tasks. Debian and RHEL expect slightly different names and
27
+ # what's worse is the whole v prefixing mess
28
+ task :debian_tar, [:output_dir] do |_task, args|
29
+ dir = (args[:output_dir] || 'packaging').to_s.tap { |p| sh "mkdir -p #{p}" }
30
+ tar_file = "#{dir}/#{ood_package_tar}"
31
+
32
+ sh "rm #{tar_file}" if File.exist?(tar_file)
33
+ sh "git ls-files | #{tar} -c --transform 's,^,#{versioned_ood_package}/,' -T - | gzip > #{tar_file}"
34
+ end
35
+
36
+ task :version do
37
+ puts package_version
38
+ end
39
+
40
+ task :deb, [:dist, :version] => [:build_box] do |_task, args|
41
+ dir = build_dir(args)
42
+ Rake::Task['package:debian_tar'].invoke(dir)
43
+ sh "#{tar} -xzf #{dir}/#{ood_package_tar} -C #{dir}"
44
+
45
+ work_dir = "/build/#{versioned_ood_package}"
46
+
47
+ base_args = ctr_run_args
48
+ base_args.concat ['-v', "#{dir}:/build", '-w', work_dir.to_s]
49
+ base_args.concat ['-e', "DEBUILD_DPKG_BUILDPACKAGE_OPTS='-us -uc -I -i'"]
50
+ base_args.concat ['-e', 'HOME=/home/ood', '-e', 'USER=ood']
51
+ base_args.concat ['-e', "VERSION=#{ENV['VERSION']}"] unless ENV['VERSION'].nil?
52
+ base_args.concat [build_box_image(args)]
53
+ sh "#{container_runtime} run #{base_args.join(' ')} debmake -b':ruby'"
54
+
55
+ debuild_args = ['debuild', '--no-lintian']
56
+ sh "#{container_runtime} run #{base_args.join(' ')} #{debuild_args.join(' ')}"
57
+ end
58
+
59
+ task :bootstrap_rpm, [:dist, :version] => [:verify_args] do |_task, args|
60
+ chdir src_dir do
61
+ build_dir(args).tap do |d|
62
+ src_dir = "#{d}/rpmbuild/SOURCES".tap { |s| sh "mkdir -p #{s}" }
63
+ dist_dir(args).tap { |dd| sh "mkdir -p #{dd}" }
64
+ Rake::Task['package:tar'].invoke(src_dir)
65
+
66
+ FileUtils.cp Dir.glob('packaging/rpm/*.{fc,te,ico,png,tar.gz}'), src_dir
67
+ FileUtils.cp spec_location, d
68
+ end
69
+ end
70
+ end
71
+
72
+ desc 'Build an RPM'
73
+ task :rpm, [:dist, :version] => [:build_box, :bootstrap_rpm] do |_task, args|
74
+ dir = build_dir(args)
75
+ image = build_box_image(args)
76
+
77
+ base_args = ctr_run_args
78
+ base_args.concat ['-v', "#{dir}:#{ctr_home}", '-w', "'#{ctr_home}'"]
79
+ base_args.concat ['-e', "HOME=#{ctr_home}"]
80
+
81
+ chdir src_dir do
82
+ sh "#{container_runtime} run #{base_args.join(' ')} #{image} rpmbuild #{rpm_build_args.join(' ')}"
83
+ FileUtils.cp Dir.glob("#{dir}/rpmbuild/RPMS/#{arch}/*.rpm"), dist_dir(args)
84
+ end
85
+ end
86
+
87
+ namespace :rpm do
88
+ desc 'Build nightly RPM'
89
+ task :nightly, [:dist, :extra_args] do |_task, args|
90
+ version_major, version_minor = git_tag.gsub(/^v/, '').split('.', 3)
91
+ date = Time.now.strftime('%Y%m%d')
92
+ id = ENV['CI_PIPELINE_ID'] || Time.now.strftime('%H%M%S')
93
+ ENV['VERSION'] = "#{version_major}.#{version_minor}.#{date}-#{id}.#{git_hash}.nightly"
94
+ Rake::Task['package:rpm'].invoke(args[:dist], args[:extra_args])
95
+ end
96
+ end
97
+
98
+ task :verify_args, [:dist, :version] do |_task, args|
99
+ raise 'Need to specify :dist and :version' if args[:dist].nil? || args[:version].nil?
100
+ end
101
+
102
+ desc 'Create buildbox for Open OnDemand'
103
+ task :build_box, [:dist, :version] => [:verify_args] do |_task, args|
104
+ cmd = build_cmd(
105
+ template_file("Dockerfile.#{args[:dist]}.erb"),
106
+ build_box_image(args)
107
+ )
108
+
109
+ sh cmd unless image_exists?(build_box_image(args))
110
+ end
111
+ end
@@ -0,0 +1,21 @@
1
+ FROM centos:8
2
+
3
+ # install all the dependencies
4
+ RUN dnf -y update
5
+ RUN dnf install -y dnf-utils
6
+ RUN dnf config-manager --set-enabled powertools
7
+ RUN dnf -y module enable nodejs:12 ruby:2.7
8
+ RUN dnf install -y \
9
+ make gcc gcc-c++ git rsync rpm-build redhat-rpm-config
10
+ RUN dnf install -y libselinux libselinux-devel
11
+ RUN dnf install -y selinux-policy selinux-policy-devel
12
+ RUN dnf install -y scl-utils
13
+
14
+ RUN dnf install -y https://yum.osc.edu/ondemand/latest/ondemand-release-web-latest-1-6.noarch.rpm
15
+ RUN dnf install -y \
16
+ ondemand-runtime ondemand-scldevel ondemand-build ondemand-ruby ondemand-python ondemand-nodejs
17
+
18
+ RUN dnf clean all && rm -rf /var/cache/dnf/*
19
+
20
+ RUN groupadd <%= ctr_user %> && \
21
+ useradd --create-home --gid <%= ctr_user %> <%= ctr_user %>
@@ -0,0 +1,15 @@
1
+ from ubuntu:20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+
5
+ RUN apt update && \
6
+ apt install -y \
7
+ ruby=1:2.7+1 ruby-dev=1:2.7+1 \
8
+ nodejs npm \
9
+ make g++ gcc sqlite3 libsqlite3-dev \
10
+ debmake debhelper
11
+
12
+ RUN groupadd <%= ctr_user %> && \
13
+ useradd --create-home --gid <%= ctr_user %> <%= ctr_user %>
14
+
15
+ RUN ln -s /bin/bundle2.7 /bin/bundle
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ood_packaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.r2.0
4
+ version: 0.0.1.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Dockendorf
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-19 00:00:00.000000000 Z
12
+ date: 2021-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -94,6 +94,10 @@ files:
94
94
  - lib/ood_packaging/tasks.rb
95
95
  - lib/ood_packaging/utils.rb
96
96
  - lib/ood_packaging/version.rb
97
+ - lib/tasks/package_utils.rb
98
+ - lib/tasks/packaging.rb
99
+ - lib/tasks/templates/Dockerfile.el.erb
100
+ - lib/tasks/templates/Dockerfile.ubuntu.erb
97
101
  homepage: https://github.com/OSC/ondemand-packaging
98
102
  licenses:
99
103
  - MIT
@@ -113,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
117
  - !ruby/object:Gem::Version
114
118
  version: 1.3.1
115
119
  requirements: []
116
- rubygems_version: 3.2.33
120
+ rubygems_version: 3.1.2
117
121
  signing_key:
118
122
  specification_version: 4
119
123
  summary: Open OnDemand packaging library