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