simp-rake-helpers 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,11 @@
2
2
 
3
3
  require 'simp/rake'
4
4
  require 'json'
5
+ require 'simp/rake/build/constants'
6
+
5
7
  include Simp::Rake
6
8
 
7
- class SIMPBuildException < Exception
9
+ class SIMPBuildException < StandardError
8
10
  end
9
11
 
10
12
  require 'simp/build/release_mapper'
@@ -12,313 +14,730 @@ module Simp; end
12
14
  module Simp::Rake; end
13
15
  module Simp::Rake::Build
14
16
  class Auto < ::Rake::TaskLib
17
+ include Simp::Rake::Build::Constants
18
+
15
19
  def initialize( run_dir )
16
- @base_dir = run_dir
20
+ init_member_vars(run_dir)
21
+
17
22
  define
18
23
  end
19
24
 
20
25
  # define rake tasks
21
26
  def define
22
27
  namespace :build do
23
- desc <<-EOM
24
- Automatically detect and build a SIMP ISO for a target SIMP release.
25
-
26
- This task runs all other build tasks
27
-
28
- Arguments:
29
- * :release => SIMP release to build (e.g., '5.1.X')
30
- - :iso_paths => path to source ISO(s) and/or directories [Default: '.']
31
- NOTE: colon-delimited list
32
- - :tarball => SIMP build tarball file; if given, skips tar build. [Default: 'false']
33
- - :output_dir => path to write SIMP ISO. [Default: './SIMP_ISO']
34
- - :do_checksum => Use sha256sum checksum to compare each ISO. [Default: 'false']
35
- - :key_name => Key name to sign packages [Default: 'dev']
36
-
37
- ENV vars:
38
- - SIMP_BUILD_staging_dir => Path to stage big build assets
39
- [Default: './SIMP_ISO_STAGING']
40
- - SIMP_BUILD_rm_staging_dir => 'yes' forcibly removes the staging dir before starting
41
- - SIMP_BUILD_force_dirty => 'yes' tries to checks out subrepos even if dirty
42
- - SIMP_BUILD_docs => 'yes' builds & includes documentation
43
- - SIMP_BUILD_checkout => 'no' will skip the git repo checkouts
44
- - SIMP_BUILD_bundle => 'no' skips running bundle in each subrepo
45
- - SIMP_BUILD_unpack => 'no' skips the unpack section
46
- - SIMP_BUILD_unpack_merge => 'no' prevents auto-merging the unpacked DVD
47
- - SIMP_BUILD_prune => 'no' passes :prune=>false to iso:build
48
- - SIMP_BUILD_iso_name => Renames the output ISO filename [Default: false]
49
- - SIMP_BUILD_iso_tag => Appended to the output ISO's filename [Default: false]
50
- - SIMP_BUILD_verbose => 'yes' enables verbose reporting. [Default: 'no']
51
- - SIMP_BUILD_packer_vars => Write a packer vars.json to go with this ISO [Default: 'yes']
52
-
53
- Notes:
54
- - To skip `tar:build` (including `pkg:build`), use the `tarball` argument
55
- EOM
56
-
57
- task :auto, [:release,
58
- :iso_paths,
59
- :tarball,
60
- :output_dir,
61
- :do_checksum,
62
- :key_name,
63
- :packer_vars,
64
- ] do |t, args|
65
- # set up data
66
- # --------------------------------------------------------------------------
67
-
68
- args.with_defaults(
69
- :iso_paths => Dir.pwd,
70
- :tarball => 'false',
71
- :output_dir => '',
72
- :do_checksum => 'false',
73
- :key_name => 'dev',
74
- )
75
-
76
- # locals
77
- target_release = args[:release]
78
- iso_paths = File.expand_path(args[:iso_paths])
79
- tarball = (args.tarball =~ /^(false|)$/ ? false : args.tarball)
80
- output_dir = args[:output_dir].sub(/^$/, File.expand_path( 'SIMP_ISO', Dir.pwd ))
81
- do_checksum = (args.do_checksum =~ /^$/ ? 'false' : args.do_checksum)
82
- key_name = args[:key_name]
83
- staging_dir = ENV.fetch('SIMP_BUILD_staging_dir',
84
- File.expand_path( 'SIMP_ISO_STAGING', Dir.pwd ))
85
- do_packer_vars = ENV.fetch('SIMP_BUILD_packer_vars', 'yes') == 'yes'
86
- verbose = ENV.fetch('SIMP_BUILD_verbose', 'no') == 'yes'
87
-
88
- yaml_file = File.expand_path('build/release_mappings.yaml', @base_dir)
89
- pwd = Dir.pwd
90
- repo_root_dir = File.expand_path( @base_dir )
91
- method = ENV.fetch('SIMP_BUILD_puppetfile','tracking')
92
- do_rm_staging = ENV['SIMP_BUILD_rm_staging_dir'] == 'yes'
93
- do_docs = ENV['SIMP_BUILD_docs'] == 'yes' ? 'true' : 'false'
94
- do_merge = ENV['SIMP_BUILD_unpack_merge'] != 'no'
95
- do_prune = ENV['SIMP_BUILD_prune'] != 'no' ? 'true' : 'false'
96
- do_checkout = ENV['SIMP_BUILD_checkout'] != 'no'
97
- do_bundle = ENV['SIMP_BUILD_bundle'] == 'yes' ? true : false
98
- do_unpack = ENV['SIMP_BUILD_unpack'] != 'no'
99
- full_iso_name = ENV.fetch('SIMP_BUILD_iso_name', false)
100
- iso_name_tag = ENV.fetch('SIMP_BUILD_iso_tag', false)
101
-
102
- # Skip a bunch of unnecessary stuff if we're passed a tarball
103
- if tarball
104
- do_docs = false
105
- do_checkout = false
106
- do_bundle = false
107
- end
108
28
 
109
- @dirty_repos = nil
110
- @simp_output_iso = nil
29
+ # SIMP 6 Style
30
+ if @os_build_metadata
31
+ desc <<-EOM
32
+ Automatically detect and build a SIMP ISO for a target SIMP release.
33
+
34
+ This task runs all other build tasks
35
+
36
+ Arguments:
37
+ * :iso_paths => Path to source ISO(s) and/or directories [Default: '.']
38
+ NOTE: colon-delimited list
39
+ If not set, will build all enabled distributions
40
+ * :release => SIMP release to build (e.g., '6.X')
41
+ The Full list can be found in '#{File.join(@build_dir, 'release_mappings.yaml')}'
42
+ Default: #{[@simp_version.split('.').first, 'X'].join('.')}
43
+ * :output_dir => path to write SIMP ISO. [Default: './SIMP_ISO']
44
+ * :do_checksum => Use sha256sum checksum to compare each ISO. [Default: 'false']
45
+ * :key_name => Key name to sign packages [Default: 'dev']
46
+
47
+ ENV vars:
48
+ - SIMP_BUILD_isos => Path to the base OS ISO images
49
+ - SIMP_BUILD_distro => Distribution to build
50
+ See '#{File.join(@distro_build_dir, 'build_metadata.yaml')}'}
51
+ - SIMP_BUILD_prompt => 'no' disables asking questions.
52
+ Will default to a full build and *will* erase existing artifacts.
53
+ - SIMP_BUILD_staging_dir => Path to stage big build assets
54
+ [Default: './SIMP_ISO_STAGING']
55
+ - SIMP_BUILD_rm_staging_dir => 'yes' forcibly removes the staging dir before starting
56
+ - SIMP_BUILD_force_dirty => 'yes' tries to checks out subrepos even if dirty
57
+ - SIMP_BUILD_docs => 'yes' builds & includes documentation
58
+ - SIMP_BUILD_checkout => 'no' will skip the git repo checkouts
59
+ - SIMP_BUILD_bundle => 'no' skips running bundle in each subrepo
60
+ - SIMP_BUILD_unpack => 'no' skips the unpack section
61
+ - SIMP_BUILD_unpack_merge => 'no' prevents auto-merging the unpacked DVD
62
+ - SIMP_BUILD_prune => 'no' passes :prune=>false to iso:build
63
+ - SIMP_BUILD_iso_name => Renames the output ISO filename [Default: false]
64
+ - SIMP_BUILD_iso_tag => Appended to the output ISO's filename [Default: false]
65
+ - SIMP_BUILD_verbose => 'yes' enables verbose reporting. [Default: 'no']
66
+ - SIMP_BUILD_packer_vars => Write a packer vars.json to go with this ISO [Default: 'yes']
67
+ - SIMP_BUILD_signing_key => The name of the GPG key to use to sign packages. [Default: 'dev']
68
+ EOM
69
+
70
+ task :auto, [:iso_paths,
71
+ :release,
72
+ :output_dir,
73
+ :do_checksum,
74
+ :key_name
75
+ ] do |t, args|
76
+
77
+ args.with_defaults(
78
+ :iso_paths => ENV['SIMP_BUILD_isos'] || Dir.pwd,
79
+ :distribution => 'ALL',
80
+ :release => [@simp_version.split('.').first, 'X'].join('.'),
81
+ :output_dir => '',
82
+ :do_checksum => 'false',
83
+ :key_name => ENV['SIMP_BUILD_signing_key'] || 'dev'
84
+ )
85
+
86
+ iso_paths = File.expand_path(args[:iso_paths])
87
+ target_release = args[:release]
88
+ do_checksum = (args.do_checksum = ~ /^$/ ? 'false' : args.do_checksum)
89
+ key_name = args[:key_name]
90
+ do_packer_vars = ENV.fetch('SIMP_BUILD_packer_vars', 'yes') == 'yes'
91
+ verbose = ENV.fetch('SIMP_BUILD_verbose', 'no') == 'yes'
92
+ prompt = ENV.fetch('SIMP_BUILD_prompt', 'yes') != 'no'
93
+ pwd = Dir.pwd
94
+ repo_root_dir = File.expand_path( @base_dir )
95
+ method = ENV.fetch('SIMP_BUILD_puppetfile','tracking')
96
+ do_rm_staging = ENV['SIMP_BUILD_rm_staging_dir'] == 'yes'
97
+ do_docs = ENV['SIMP_BUILD_docs'] == 'yes' ? 'true' : 'false'
98
+ do_merge = ENV['SIMP_BUILD_unpack_merge'] != 'no'
99
+ do_prune = ENV['SIMP_BUILD_prune'] != 'no' ? 'true' : 'false'
100
+ do_checkout = ENV['SIMP_BUILD_checkout'] != 'no'
101
+ do_bundle = ENV['SIMP_BUILD_bundle'] == 'yes' ? true : false
102
+ do_unpack = ENV['SIMP_BUILD_unpack'] != 'no'
103
+ full_iso_name = ENV.fetch('SIMP_BUILD_iso_name', false)
104
+ iso_name_tag = ENV.fetch('SIMP_BUILD_iso_tag', false)
105
+ tarball = false
106
+
107
+ iso_status = {}
108
+
109
+ @os_build_metadata['distributions'].keys.sort.each do |distro|
110
+ @os_build_metadata['distributions'][distro].keys.sort.each do |version|
111
+ unless @os_build_metadata['distributions'][distro][version]['build']
112
+ if verbose
113
+ $stderr.puts("Skipping build for #{distro} #{version}")
114
+ end
115
+
116
+ next
117
+ end
118
+
119
+ @os_build_metadata['distributions'][distro][version]['arch'].sort.each do |arch|
120
+ begin
121
+ distro_build_dir = File.join(@distro_build_dir, distro, version, arch)
122
+
123
+ # For subtask mangling
124
+ $simp6_build_dir = distro_build_dir
125
+ $simp6_build_metadata = {
126
+ :distro => distro,
127
+ :version => version,
128
+ :arch => arch
129
+ }
130
+
131
+ output_dir = args[:output_dir].sub(/^$/, File.expand_path( 'SIMP_ISO', distro_build_dir ))
132
+
133
+ staging_dir = ENV.fetch('SIMP_BUILD_staging_dir', File.expand_path( 'SIMP_ISO_STAGING', distro_build_dir ))
134
+
135
+ yaml_file = File.expand_path('release_mappings.yaml', distro_build_dir)
136
+
137
+ tar_file = File.join(distro_build_dir, 'DVD_Overlay', "SIMP-#{@simp_version}-#{distro}-#{version}-#{arch}.tar.gz")
138
+
139
+ if File.exist?(tar_file)
140
+ if prompt
141
+ valid_entry = false
142
+ while !valid_entry do
143
+ puts("Existing tar file found at #{tar_file}")
144
+ print("Do you want to overwrite it? (y|N): ")
145
+
146
+ resp = $stdin.gets.chomp
147
+
148
+ if resp.empty? || (resp =~ /^(n|N)/)
149
+ tarball = tar_file
150
+ valid_entry = true
151
+ elsif resp =~ /^(y|Y)/
152
+ tarball = false
153
+ valid_entry = true
154
+
155
+ if verbose
156
+ $stderr.puts("Notice: Overwriting existing tarball at #{tar_file}")
157
+ $stderr.puts("Notice: PRESS CTRL-C WITHIN 5 SECONDS TO CANCEL")
158
+ end
159
+
160
+ sleep(5)
161
+ else
162
+ puts("Invalid input: '#{resp}', please try again")
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ if tarball
169
+ do_docs = false
170
+ do_checkout = false
171
+ do_bundle = false
172
+ end
173
+
174
+ @dirty_repos = nil
175
+ @simp_output_iso = nil
176
+
177
+ # Build environment sanity checks
178
+ # --------------------
179
+ if do_rm_staging && !do_unpack
180
+ fail SIMPBuildException, "ERROR: Mixing `SIMP_BUILD_rm_staging_dir=yes` and `SIMP_BUILD_unpack=no` is silly."
181
+ end
182
+
183
+ if File.exists?(output_dir) && !File.directory?(output_dir)
184
+ fail SIMPBuildException, "ERROR: ISO output dir exists but is not a directory:\n\n" +
185
+ " '#{output_dir}'\n\n"
186
+ end
187
+
188
+ # Look up ISOs against known build assets
189
+ # --------------------
190
+ target_data = get_target_data(target_release, iso_paths, yaml_file, do_checksum, verbose )
191
+
192
+ simp6_mock_cfg = File.join($simp6_build_dir, 'mock.cfg')
193
+
194
+ if File.exist?(simp6_mock_cfg)
195
+ target_data['mock'] = simp6_mock_cfg
196
+
197
+ if verbose
198
+ $stderr.puts("Notice: Using mock config at #{simp6_mock_cfg}")
199
+ end
200
+ end
201
+
202
+ # check out subrepos
203
+ # --------------------
204
+ if do_checkout && !tarball
205
+ puts
206
+ puts '='*80
207
+ puts "## Checking out subrepositories"
208
+ puts
209
+ puts " (skip with `SIMP_BUILD_checkout=no`)"
210
+ puts '='*80
211
+ Dir.chdir repo_root_dir
212
+ Rake::Task['deps:status'].invoke
213
+ if @dirty_repos && !ENV['SIMP_BUILD_force_dirty'] == 'yes'
214
+ raise SIMPBuildException, "ERROR: Dirty repos detected! I refuse to destroy uncommitted work."
215
+ else
216
+ puts
217
+ puts '-'*80
218
+ puts "#### Checking out subrepositories using method '#{method}'"
219
+ puts '-'*80
220
+ Rake::Task['deps:checkout'].invoke(method)
221
+ end
222
+
223
+ if do_bundle
224
+ puts
225
+ puts '-'*80
226
+ puts "#### Running bundler in all repos"
227
+ puts ' (Disable with `SIMP_BUILD_bundle=no`)'
228
+ puts '-'*80
229
+ Rake::Task['build:bundle'].invoke
230
+ else
231
+ puts
232
+ puts '-'*80
233
+ puts "#### SKIPPED: bundler in all repos"
234
+ puts ' (Force with `SIMP_BUILD_bundle=yes`)'
235
+ puts '-'*80
236
+ end
237
+ else
238
+ puts
239
+ puts '='*80
240
+ puts "#### skipping sub repository checkout (because `SIMP_BUILD_checkout=no`)"
241
+ puts
242
+ end
243
+
244
+ # build tarball
245
+ # --------------------
246
+ if tarball
247
+ puts
248
+ puts '-'*80
249
+ puts "#### Using pre-existing tarball:"
250
+ puts " '#{tarball}'"
251
+ puts
252
+ puts '-'*80
253
+
254
+ else
255
+ puts
256
+ puts '='*80
257
+ puts "#### Running tar:build"
258
+ puts '='*80
259
+
260
+ # Horrible state passing magic vars
261
+ $tarball_tgt = File.join(distro_build_dir, 'DVD_Overlay', "SIMP-#{@simp_version}-#{distro}-#{version}-#{arch}.tar.gz")
262
+
263
+ Rake::Task['tar:build'].invoke(target_data['mock'],key_name,do_docs)
264
+
265
+ tarball = $tarball_tgt
266
+ end
267
+
268
+ # yum sync
269
+ # --------------------
270
+ puts
271
+ puts '-'*80
272
+ puts "#### rake build:yum:sync[#{target_data['flavor']},#{target_data['os_version']}]"
273
+ puts '-'*80
274
+ Rake::Task['build:yum:sync'].invoke(target_data['flavor'],target_data['os_version'])
275
+
276
+ # If you have previously downloaded packages from yum, you may need to run
277
+ # $ rake build:yum:clean_cache
278
+
279
+ # Optionally, you may drop in custom packages you wish to have available during an install into build/yum_data/SIMP<simp_version>_<CentOS or RHEL><os_version>_<architecture>/packages
280
+ # TODO: ENV var for optional packages
281
+
282
+ prepare_staging_dir( staging_dir, do_rm_staging, repo_root_dir, verbose )
283
+ Dir.chdir staging_dir
284
+
285
+ #
286
+ # --------------------
287
+ if do_unpack
288
+ puts
289
+ puts '='*80
290
+ puts "#### unpack ISOs into staging directory"
291
+ puts " staging area: '#{staging_dir}'"
292
+ puts
293
+ puts " (skip with `SIMP_BUILD_unpack=no`)"
294
+ puts '='*80
295
+ puts
296
+
297
+ Dir.glob( File.join(staging_dir, "#{target_data['flavor']}*/") ).each do |f|
298
+ FileUtils.rm_f( f , :verbose => verbose )
299
+ end
300
+
301
+ target_data['isos'].each do |iso|
302
+ puts "---- rake unpack[#{iso},#{do_merge},#{Dir.pwd},isoinfo,#{target_data['os_version']}]"
303
+ Rake::Task['unpack'].reenable
304
+ Rake::Task['unpack'].invoke(iso,do_merge,Dir.pwd,'isoinfo',target_data['os_version'])
305
+ end
306
+ else
307
+ puts
308
+ puts '='*80
309
+ puts "#### skipping ISOs unpack (because `SIMP_BUILD_unpack=no`)"
310
+ puts
311
+ end
312
+
313
+ Dir.chdir repo_root_dir
314
+
315
+ puts
316
+ puts '='*80
317
+ puts "#### iso:build[#{tarball}]"
318
+ puts '='*80
319
+ puts
320
+
321
+ ENV['SIMP_ISO_verbose'] = 'yes' if verbose
322
+ ENV['SIMP_PKG_verbose'] = 'yes' if verbose
323
+ Rake::Task['iso:build'].invoke(tarball,staging_dir,do_prune)
324
+
325
+ _isos = Dir[ File.join(Dir.pwd,'SIMP-*.iso') ]
326
+ if _isos.size == 0
327
+ fail "ERROR: No SIMP ISOs found in '#{Dir.pwd}'"
328
+ elsif _isos.size > 1
329
+ warn "WARNING: More than one SIMP ISO found in '#{Dir.pwd}'"
330
+ _isos.each{ |i| warn i }
331
+ end
332
+
333
+ # NOTE: It is possible at this point (given the right
334
+ # `SIMP_BUILD_xxx=no` flags) that iso:build will not have set
335
+ # `@simp_output_iso`. In that case, look at the ISOs in the staging
336
+ # dir (there should only be one) and take our best guess.
337
+ if @simp_output_iso.nil?
338
+ @simp_output_iso = File.basename(_isos.first)
339
+ end
340
+
341
+ output_file = full_iso_name ? full_iso_name : @simp_output_iso
342
+ if iso_name_tag
343
+ output_file = output_file.sub(/\.iso$/i, "__#{iso_name_tag}.iso")
344
+ end
345
+
346
+ puts
347
+ puts '='*80
348
+ puts "#### Moving '#{@simp_output_iso}' into:"
349
+ puts " '#{output_dir}/#{output_file}'"
350
+ puts '='*80
351
+ puts
352
+
353
+ iso = File.join(output_dir,output_file)
354
+ FileUtils.mkdir_p File.dirname(iso), :verbose => verbose
355
+ FileUtils.mv(@simp_output_iso, iso, :verbose => verbose)
356
+
357
+ # write vars.json for packer build
358
+ # --------------------------------------
359
+ vars_file = iso.sub(/.iso$/, '.json')
360
+ puts
361
+ puts '='*80
362
+ puts "#### Checksumming #{iso}..."
363
+ puts '='*80
364
+ puts
365
+
366
+ sum = `sha256sum "#{iso}"`.split(/ +/).first
367
+
368
+ puts
369
+ puts '='*80
370
+ puts "#### Writing packer data to:"
371
+ puts " '#{vars_file}'"
372
+ puts '='*80
373
+ puts
374
+ box_distro_release = "SIMP-#{target_release}-#{File.basename(target_data['isos'].first).sub(/\.iso$/,'').sub(/-x86_64/,'')}"
375
+ packer_vars = {
376
+ 'box_simp_release' => target_release,
377
+ 'box_distro_release' => box_distro_release,
378
+ 'iso_url' => iso,
379
+ 'iso_checksum' => sum,
380
+ 'iso_checksum_type' => 'sha256',
381
+ 'new_password' => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
382
+ 'output_directory' => './OUTPUT',
383
+ }
384
+ File.open(vars_file, 'w'){|f| f.puts packer_vars.to_json }
385
+
386
+ puts
387
+ puts '='*80
388
+ puts "#### FINIS!"
389
+ puts '='*80
390
+ puts
391
+
392
+ iso_status[[distro, version, arch].join(' ')] = {
393
+ 'success' => true
394
+ }
395
+
396
+ rescue => e
397
+ iso_status[[distro, version, arch].join(' ')] = {
398
+ 'success' => false,
399
+ 'error' => e.to_s,
400
+ 'backtrace' => e.backtrace
401
+ }
402
+ end
403
+ end
404
+ end
405
+ end
111
406
 
407
+ successful_isos = []
408
+ failed_isos = []
112
409
 
113
- # Build environment sanity checks
114
- # --------------------
115
- if do_rm_staging && !do_unpack
116
- fail SIMPBuildException, "ERROR: Mixing `SIMP_BUILD_rm_staging_dir=yes` and `SIMP_BUILD_unpack=no` is silly."
117
- end
410
+ iso_status.keys.each do |iso|
411
+ if iso_status[iso]['success']
412
+ successful_isos << iso
413
+ else
414
+ failed_isos << iso
415
+ end
416
+ end
417
+
418
+ unless successful_isos.empty?
419
+ puts '='*80
420
+ puts("Successful ISOs:")
421
+ puts(%( * #{successful_isos.join("\n * ")}))
422
+ end
118
423
 
119
- if File.exists?(output_dir) && !File.directory?(output_dir)
120
- fail SIMPBuildException, "ERROR: ISO output dir exists but is not a directory:\n\n" +
121
- " '#{output_dir}'\n\n"
424
+ unless failed_isos.empty?
425
+ puts '='*80
426
+ puts("Failed ISOs:")
427
+ failed_isos.each do |iso|
428
+ puts(%( * #{iso}))
429
+ puts(%( * Error: #{iso_status[iso]['error']}))
430
+
431
+ if verbose
432
+ puts(%( * Backtrace: #{iso_status[iso]['backtrace'].join("\n")}))
433
+ else
434
+ puts(%( * Context: #{iso_status[iso]['backtrace'].first}))
435
+ end
436
+ end
437
+ end
122
438
  end
439
+ else
440
+ # Legacy
441
+ desc <<-EOM
442
+ Automatically detect and build a SIMP ISO for a target SIMP release.
443
+
444
+ This task runs all other build tasks
445
+
446
+ Arguments:
447
+ * :release => SIMP release to build (e.g., '5.1.X')
448
+ - :iso_paths => path to source ISO(s) and/or directories [Default: '.']
449
+ NOTE: colon-delimited list
450
+ - :tarball => SIMP build tarball file; if given, skips tar build. [Default: 'false']
451
+ - :output_dir => path to write SIMP ISO. [Default: './SIMP_ISO']
452
+ - :do_checksum => Use sha256sum checksum to compare each ISO. [Default: 'false']
453
+ - :key_name => Key name to sign packages [Default: 'dev']
454
+
455
+ ENV vars:
456
+ - SIMP_BUILD_staging_dir => Path to stage big build assets
457
+ [Default: './SIMP_ISO_STAGING']
458
+ - SIMP_BUILD_rm_staging_dir => 'yes' forcibly removes the staging dir before starting
459
+ - SIMP_BUILD_force_dirty => 'yes' tries to checks out subrepos even if dirty
460
+ - SIMP_BUILD_docs => 'yes' builds & includes documentation
461
+ - SIMP_BUILD_checkout => 'no' will skip the git repo checkouts
462
+ - SIMP_BUILD_bundle => 'no' skips running bundle in each subrepo
463
+ - SIMP_BUILD_unpack => 'no' skips the unpack section
464
+ - SIMP_BUILD_unpack_merge => 'no' prevents auto-merging the unpacked DVD
465
+ - SIMP_BUILD_prune => 'no' passes :prune=>false to iso:build
466
+ - SIMP_BUILD_iso_name => Renames the output ISO filename [Default: false]
467
+ - SIMP_BUILD_iso_tag => Appended to the output ISO's filename [Default: false]
468
+ - SIMP_BUILD_verbose => 'yes' enables verbose reporting. [Default: 'no']
469
+ - SIMP_BUILD_packer_vars => Write a packer vars.json to go with this ISO [Default: 'yes']
470
+
471
+ Notes:
472
+ - To skip `tar:build` (including `pkg:build`), use the `tarball` argument
473
+ EOM
474
+
475
+ task :auto, [:release,
476
+ :iso_paths,
477
+ :tarball,
478
+ :output_dir,
479
+ :do_checksum,
480
+ :key_name,
481
+ :packer_vars,
482
+ ] do |t, args|
483
+ # set up data
484
+ # --------------------------------------------------------------------------
485
+
486
+ args.with_defaults(
487
+ :release => [@simp_version.split('.').first, 'X'].join('.'),
488
+ :iso_paths => Dir.pwd,
489
+ :tarball => 'false',
490
+ :output_dir => '',
491
+ :do_checksum => 'false',
492
+ :key_name => 'dev',
493
+ )
494
+
495
+ # locals
496
+ target_release = args[:release]
497
+ iso_paths = File.expand_path(args[:iso_paths])
498
+ tarball = (args.tarball =~ /^(false|)$/ ? false : args.tarball)
499
+ output_dir = args[:output_dir].sub(/^$/, File.expand_path( 'SIMP_ISO', Dir.pwd ))
500
+ do_checksum = (args.do_checksum =~ /^$/ ? 'false' : args.do_checksum)
501
+ key_name = args[:key_name]
502
+ staging_dir = ENV.fetch('SIMP_BUILD_staging_dir',
503
+ File.expand_path( 'SIMP_ISO_STAGING', Dir.pwd ))
504
+ do_packer_vars = ENV.fetch('SIMP_BUILD_packer_vars', 'yes') == 'yes'
505
+ verbose = ENV.fetch('SIMP_BUILD_verbose', 'no') == 'yes'
506
+
507
+ yaml_file = File.expand_path('build/release_mappings.yaml', @base_dir)
508
+ pwd = Dir.pwd
509
+ repo_root_dir = File.expand_path( @base_dir )
510
+ method = ENV.fetch('SIMP_BUILD_puppetfile','tracking')
511
+ do_rm_staging = ENV['SIMP_BUILD_rm_staging_dir'] == 'yes'
512
+ do_docs = ENV['SIMP_BUILD_docs'] == 'yes' ? 'true' : 'false'
513
+ do_merge = ENV['SIMP_BUILD_unpack_merge'] != 'no'
514
+ do_prune = ENV['SIMP_BUILD_prune'] != 'no' ? 'true' : 'false'
515
+ do_checkout = ENV['SIMP_BUILD_checkout'] != 'no'
516
+ do_bundle = ENV['SIMP_BUILD_bundle'] == 'yes' ? true : false
517
+ do_unpack = ENV['SIMP_BUILD_unpack'] != 'no'
518
+ full_iso_name = ENV.fetch('SIMP_BUILD_iso_name', false)
519
+ iso_name_tag = ENV.fetch('SIMP_BUILD_iso_tag', false)
520
+
521
+ # Skip a bunch of unnecessary stuff if we're passed a tarball
522
+ if tarball
523
+ do_docs = false
524
+ do_checkout = false
525
+ do_bundle = false
526
+ end
527
+
528
+ @dirty_repos = nil
529
+ @simp_output_iso = nil
123
530
 
124
531
 
125
- # Look up ISOs against known build assets
126
- # --------------------
127
- target_data = get_target_data(target_release, iso_paths, yaml_file, do_checksum, verbose )
532
+ # Build environment sanity checks
533
+ # --------------------
534
+ if do_rm_staging && !do_unpack
535
+ fail SIMPBuildException, "ERROR: Mixing `SIMP_BUILD_rm_staging_dir=yes` and `SIMP_BUILD_unpack=no` is silly."
536
+ end
128
537
 
129
- # Quick map to match the filenames in the build structures
130
- target_data['flavor'] = 'RHEL' if target_data['flavor'] == 'RedHat'
538
+ if File.exists?(output_dir) && !File.directory?(output_dir)
539
+ fail SIMPBuildException, "ERROR: ISO output dir exists but is not a directory:\n\n" +
540
+ " '#{output_dir}'\n\n"
541
+ end
131
542
 
132
- # IDEA: check for prequisite build tools
133
543
 
134
- # check out subrepos
135
- # --------------------
136
- if do_checkout && !tarball
137
- puts
138
- puts '='*80
139
- puts "## Checking out subrepositories"
140
- puts
141
- puts " (skip with `SIMP_BUILD_checkout=no`)"
142
- puts '='*80
143
- Dir.chdir repo_root_dir
144
- Rake::Task['deps:status'].invoke
145
- if @dirty_repos && !ENV['SIMP_BUILD_force_dirty'] == 'yes'
146
- raise SIMPBuildException, "ERROR: Dirty repos detected! I refuse to destroy uncommitted work."
544
+ # Look up ISOs against known build assets
545
+ # --------------------
546
+ target_data = get_target_data(target_release, iso_paths, yaml_file, do_checksum, verbose )
547
+
548
+ # Quick map to match the filenames in the build structures
549
+ target_data['flavor'] = 'RHEL' if target_data['flavor'] == 'RedHat'
550
+
551
+ # IDEA: check for prequisite build tools
552
+
553
+ # check out subrepos
554
+ # --------------------
555
+ if do_checkout && !tarball
556
+ puts
557
+ puts '='*80
558
+ puts "## Checking out subrepositories"
559
+ puts
560
+ puts " (skip with `SIMP_BUILD_checkout=no`)"
561
+ puts '='*80
562
+ Dir.chdir repo_root_dir
563
+ Rake::Task['deps:status'].invoke
564
+ if @dirty_repos && !ENV['SIMP_BUILD_force_dirty'] == 'yes'
565
+ raise SIMPBuildException, "ERROR: Dirty repos detected! I refuse to destroy uncommitted work."
566
+ else
567
+ puts
568
+ puts '-'*80
569
+ puts "#### Checking out subrepositories using method '#{method}'"
570
+ puts '-'*80
571
+ Rake::Task['deps:checkout'].invoke(method)
572
+ end
573
+
574
+ if do_bundle
575
+ puts
576
+ puts '-'*80
577
+ puts "#### Running bundler in all repos"
578
+ puts ' (Disable with `SIMP_BUILD_bundle=no`)'
579
+ puts '-'*80
580
+ Rake::Task['build:bundle'].invoke
581
+ else
582
+ puts
583
+ puts '-'*80
584
+ puts "#### SKIPPED: bundler in all repos"
585
+ puts ' (Force with `SIMP_BUILD_bundle=yes`)'
586
+ puts '-'*80
587
+ end
147
588
  else
148
589
  puts
149
- puts '-'*80
150
- puts "#### Checking out subrepositories using method '#{method}'"
151
- puts '-'*80
152
- Rake::Task['deps:checkout'].invoke(method)
590
+ puts '='*80
591
+ puts "#### skipping sub repository checkout (because `SIMP_BUILD_checkout=no`)"
592
+ puts
153
593
  end
154
594
 
155
- if do_bundle
595
+ # build tarball
596
+ # --------------------
597
+ if tarball
156
598
  puts
157
599
  puts '-'*80
158
- puts "#### Running bundler in all repos"
159
- puts ' (Disable with `SIMP_BUILD_bundle=no`)'
600
+ puts "#### Using pre-existing tarball:"
601
+ puts " '#{tarball}'"
602
+ puts
160
603
  puts '-'*80
161
- Rake::Task['build:bundle'].invoke
604
+
162
605
  else
163
606
  puts
164
- puts '-'*80
165
- puts "#### SKIPPED: bundler in all repos"
166
- puts ' (Force with `SIMP_BUILD_bundle=yes`)'
167
- puts '-'*80
607
+ puts '='*80
608
+ puts "#### Running tar:build"
609
+ puts '='*80
610
+ $simp_tarballs = {}
611
+ Rake::Task['tar:build'].invoke(target_data['mock'],key_name,do_docs)
612
+ tarball = $simp_tarballs.fetch(target_data['flavor'])
168
613
  end
169
- else
170
- puts
171
- puts '='*80
172
- puts "#### skipping sub repository checkout (because `SIMP_BUILD_checkout=no`)"
173
- puts
174
- end
175
614
 
176
- # build tarball
177
- # --------------------
178
- if tarball
615
+ # yum sync
616
+ # --------------------
179
617
  puts
180
618
  puts '-'*80
181
- puts "#### Using pre-existing tarball:"
182
- puts " '#{tarball}'"
183
- puts
619
+ puts "#### rake build:yum:sync[#{target_data['flavor']},#{target_data['os_version']}]"
184
620
  puts '-'*80
621
+ Rake::Task['build:yum:sync'].invoke(target_data['flavor'],target_data['os_version'])
185
622
 
186
- else
187
- puts
188
- puts '='*80
189
- puts "#### Running tar:build"
190
- puts '='*80
191
- $simp_tarballs = {}
192
- Rake::Task['tar:build'].invoke(target_data['mock'],key_name,do_docs)
193
- tarball = $simp_tarballs.fetch(target_data['flavor'])
194
- end
623
+ # If you have previously downloaded packages from yum, you may need to run
624
+ # $ rake build:yum:clean_cache
195
625
 
196
- # yum sync
197
- # --------------------
198
- puts
199
- puts '-'*80
200
- puts "#### rake build:yum:sync[#{target_data['flavor']},#{target_data['os_version']}]"
201
- puts '-'*80
202
- Rake::Task['build:yum:sync'].invoke(target_data['flavor'],target_data['os_version'])
626
+ # Optionally, you may drop in custom packages you wish to have available during an install into build/yum_data/SIMP<simp_version>_<CentOS or RHEL><os_version>_<architecture>/packages
627
+ # TODO: ENV var for optional packages
203
628
 
204
- # If you have previously downloaded packages from yum, you may need to run
205
- # $ rake build:yum:clean_cache
629
+ prepare_staging_dir( staging_dir, do_rm_staging, repo_root_dir, verbose )
630
+ Dir.chdir staging_dir
206
631
 
207
- # Optionally, you may drop in custom packages you wish to have available during an install into build/yum_data/SIMP<simp_version>_<CentOS or RHEL><os_version>_<architecture>/packages
208
- # TODO: ENV var for optional packages
632
+ #
633
+ # --------------------
634
+ if do_unpack
635
+ puts
636
+ puts '='*80
637
+ puts "#### unpack ISOs into staging directory"
638
+ puts " staging area: '#{staging_dir}'"
639
+ puts
640
+ puts " (skip with `SIMP_BUILD_unpack=no`)"
641
+ puts '='*80
642
+ puts
209
643
 
210
- prepare_staging_dir( staging_dir, do_rm_staging, repo_root_dir, verbose )
211
- Dir.chdir staging_dir
644
+ Dir.glob( File.join(staging_dir, "#{target_data['flavor']}*/") ).each do |f|
645
+ FileUtils.rm_f( f , :verbose => verbose )
646
+ end
647
+
648
+ target_data['isos'].each do |iso|
649
+ puts "---- rake unpack[#{iso},#{do_merge},#{Dir.pwd},isoinfo,#{target_data['os_version']}]"
650
+ Rake::Task['unpack'].reenable
651
+ Rake::Task['unpack'].invoke(iso,do_merge,Dir.pwd,'isoinfo',target_data['os_version'])
652
+ end
653
+ else
654
+ puts
655
+ puts '='*80
656
+ puts "#### skipping ISOs unpack (because `SIMP_BUILD_unpack=no`)"
657
+ puts
658
+ end
659
+
660
+ Dir.chdir repo_root_dir
212
661
 
213
- #
214
- # --------------------
215
- if do_unpack
216
662
  puts
217
663
  puts '='*80
218
- puts "#### unpack ISOs into staging directory"
219
- puts " staging area: '#{staging_dir}'"
220
- puts
221
- puts " (skip with `SIMP_BUILD_unpack=no`)"
664
+ puts "#### iso:build[#{tarball}]"
222
665
  puts '='*80
223
666
  puts
224
667
 
225
- Dir.glob( File.join(staging_dir, "#{target_data['flavor']}*/") ).each do |f|
226
- FileUtils.rm_f( f , :verbose => verbose )
668
+ ENV['SIMP_ISO_verbose'] = 'yes' if verbose
669
+ ENV['SIMP_PKG_verbose'] = 'yes' if verbose
670
+ Rake::Task['iso:build'].invoke(tarball,staging_dir,do_prune)
671
+
672
+
673
+ _isos = Dir[ File.join(Dir.pwd,'SIMP-*.iso') ]
674
+ if _isos.size == 0
675
+ fail "ERROR: No SIMP ISOs found in '#{Dir.pwd}'"
676
+ elsif _isos.size > 1
677
+ warn "WARNING: More than one SIMP ISO found in '#{Dir.pwd}'"
678
+ _isos.each{ |i| warn i }
679
+ end
680
+
681
+ # NOTE: It is possible at this point (given the right
682
+ # `SIMP_BUILD_xxx=no` flags) that iso:build will not have set
683
+ # `@simp_output_iso`. In that case, look at the ISOs in the staging
684
+ # dir (there should only be one) and take our best guess.
685
+ if @simp_output_iso.nil?
686
+ @simp_output_iso = File.basename(_isos.first)
227
687
  end
228
688
 
229
- target_data['isos'].each do |iso|
230
- puts "---- rake unpack[#{iso},#{do_merge},#{Dir.pwd},isoinfo,#{target_data['os_version']}]"
231
- Rake::Task['unpack'].reenable
232
- Rake::Task['unpack'].invoke(iso,do_merge,Dir.pwd,'isoinfo',target_data['os_version'])
689
+ output_file = full_iso_name ? full_iso_name : @simp_output_iso
690
+ if iso_name_tag
691
+ output_file = output_file.sub(/\.iso$/i, "__#{iso_name_tag}.iso")
233
692
  end
234
- else
693
+
235
694
  puts
236
695
  puts '='*80
237
- puts "#### skipping ISOs unpack (because `SIMP_BUILD_unpack=no`)"
696
+ puts "#### Moving '#{@simp_output_iso}' into:"
697
+ puts " '#{output_dir}/#{output_file}'"
698
+ puts '='*80
238
699
  puts
239
- end
240
-
241
- Dir.chdir repo_root_dir
242
-
243
- puts
244
- puts '='*80
245
- puts "#### iso:build[#{tarball}]"
246
- puts '='*80
247
- puts
248
700
 
249
- ENV['SIMP_ISO_verbose'] = 'yes' if verbose
250
- ENV['SIMP_PKG_verbose'] = 'yes' if verbose
251
- Rake::Task['iso:build'].invoke(tarball,staging_dir,do_prune)
701
+ iso = File.join(output_dir,output_file)
702
+ FileUtils.mkdir_p File.dirname(iso), :verbose => verbose
703
+ FileUtils.mv(@simp_output_iso, iso, :verbose => verbose)
252
704
 
705
+ # write vars.json for packer build
706
+ # --------------------------------------
707
+ vars_file = iso.sub(/.iso$/, '.json')
708
+ puts
709
+ puts '='*80
710
+ puts "#### Checksumming #{iso}..."
711
+ puts '='*80
712
+ puts
253
713
 
254
- _isos = Dir[ File.join(Dir.pwd,'SIMP-*.iso') ]
255
- if _isos.size == 0
256
- fail "ERROR: No SIMP ISOs found in '#{Dir.pwd}'"
257
- elsif _isos.size > 1
258
- warn "WARNING: More than one SIMP ISO found in '#{Dir.pwd}'"
259
- _isos.each{ |i| warn i }
260
- end
714
+ sum = `sha256sum "#{iso}"`.split(/ +/).first
261
715
 
262
- # NOTE: It is possible at this point (given the right
263
- # `SIMP_BUILD_xxx=no` flags) that iso:build will not have set
264
- # `@simp_output_iso`. In that case, look at the ISOs in the staging
265
- # dir (there should only be one) and take our best guess.
266
- if @simp_output_iso.nil?
267
- @simp_output_iso = File.basename(_isos.first)
268
- end
716
+ puts
717
+ puts '='*80
718
+ puts "#### Writing packer data to:"
719
+ puts " '#{vars_file}'"
720
+ puts '='*80
721
+ puts
722
+ box_distro_release = "SIMP-#{target_release}-#{File.basename(target_data['isos'].first).sub(/\.iso$/,'').sub(/-x86_64/,'')}"
723
+ packer_vars = {
724
+ 'box_simp_release' => target_release,
725
+ 'box_distro_release' => box_distro_release,
726
+ 'iso_url' => iso,
727
+ 'iso_checksum' => sum,
728
+ 'iso_checksum_type' => 'sha256',
729
+ 'new_password' => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
730
+ 'output_directory' => './OUTPUT',
731
+ }
732
+ File.open(vars_file, 'w'){|f| f.puts packer_vars.to_json }
269
733
 
270
- output_file = full_iso_name ? full_iso_name : @simp_output_iso
271
- if iso_name_tag
272
- output_file = output_file.sub(/\.iso$/i, "__#{iso_name_tag}.iso")
734
+ puts
735
+ puts '='*80
736
+ puts "#### FINIS!"
737
+ puts '='*80
738
+ puts
273
739
  end
274
-
275
- puts
276
- puts '='*80
277
- puts "#### Moving '#{@simp_output_iso}' into:"
278
- puts " '#{output_dir}/#{output_file}'"
279
- puts '='*80
280
- puts
281
-
282
- iso = File.join(output_dir,output_file)
283
- FileUtils.mkdir_p File.dirname(iso), :verbose => verbose
284
- FileUtils.mv(@simp_output_iso, iso, :verbose => verbose)
285
-
286
- # write vars.json for packer build
287
- # --------------------------------------
288
- vars_file = iso.sub(/.iso$/, '.json')
289
- puts
290
- puts '='*80
291
- puts "#### Checksumming #{iso}..."
292
- puts '='*80
293
- puts
294
-
295
- sum = `sha256sum "#{iso}"`.split(/ +/).first
296
-
297
- puts
298
- puts '='*80
299
- puts "#### Writing packer data to:"
300
- puts " '#{vars_file}'"
301
- puts '='*80
302
- puts
303
- box_distro_release = "SIMP-#{target_release}-#{File.basename(target_data['isos'].first).sub(/\.iso$/,'').sub(/-x86_64/,'')}"
304
- packer_vars = {
305
- 'box_simp_release' => target_release,
306
- 'box_distro_release' => box_distro_release,
307
- 'iso_url' => iso,
308
- 'iso_checksum' => sum,
309
- 'iso_checksum_type' => 'sha256',
310
- 'new_password' => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
311
- 'output_directory' => './OUTPUT',
312
- }
313
- File.open(vars_file, 'w'){|f| f.puts packer_vars.to_json }
314
-
315
- puts
316
- puts '='*80
317
- puts "#### FINIS!"
318
- puts '='*80
319
- puts
320
740
  end
321
-
322
741
  end
323
742
 
324
743
  def get_target_data(target_release, iso_paths, yaml_file, do_checksum, verbose )
@@ -356,6 +775,7 @@ module Simp::Rake::Build
356
775
  " '#{staging_dir}'\n\n" +
357
776
  " Use SIMP_BUILD_staging_dir='path/to/staging/dir'\n\n"
358
777
  end
778
+
359
779
  if do_rm_staging
360
780
  puts
361
781
  puts '-'*80