simp-rake-helpers 1.0.15 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ require 'simp/rake/build/constants'
2
+
3
+ module Simp; end
4
+ module Simp::Rake; end
5
+ module Simp::Rake::Build
6
+
7
+ class Spec < ::Rake::TaskLib
8
+ include Simp::Rake::Build::Constants
9
+
10
+ def initialize( base_dir )
11
+ init_member_vars( base_dir )
12
+ @mock = ENV['mock'] || '/usr/bin/mock'
13
+ define_tasks
14
+ end
15
+
16
+ def define_tasks
17
+ namespace :spec do
18
+
19
+ desc "Bump spec files. Bump all spec files' release numbers up by one.
20
+ * :list - Flag to just print the current version numbers."
21
+ task :bump,[:list] do |t,args|
22
+ (
23
+ Dir.glob("#{@spec_dir}/*.spec") +
24
+ Dir.glob("#{@src_dir}/puppet/modules/*/pkg/pupmod-*.spec")
25
+ ).each do |spec|
26
+ if args.list then
27
+ File.open(spec).each do |line|
28
+ if line =~ /Name:\s*(.*)/ then
29
+ print $1.chomp + ' -> '
30
+ next
31
+ elsif line =~ /Version:\s*(.*)/ then
32
+ print $1.chomp + '-'
33
+ next
34
+ elsif line =~ /Release:\s*(.*)/ then
35
+ puts $1.chomp
36
+ next
37
+ end
38
+ end
39
+ else
40
+ tmpfile = File.open("#{@spec_dir}/~#{File.basename(spec)}","w+")
41
+ File.open(spec).each do |line|
42
+ if line =~ /Release:/ then
43
+ tmpfile.puts "Release: #{line.split(/\s/)[1].to_i + 1}"
44
+ else
45
+ tmpfile.puts line.chomp
46
+ end
47
+ end
48
+ tmpfile.close
49
+ mv(tmpfile.path,spec)
50
+ end
51
+ end
52
+ end # End of bump task
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/rake -T
2
+
3
+ require 'simp/rake/build/constants'
4
+
5
+ module Simp; end
6
+ module Simp::Rake; end
7
+ module Simp::Rake::Build
8
+
9
+ class Tar < ::Rake::TaskLib
10
+ include Simp::Rake::Build::Constants
11
+
12
+ def initialize( base_dir )
13
+ init_member_vars( base_dir )
14
+ define_tasks
15
+ end
16
+
17
+ # define rake tasks
18
+ def define_tasks
19
+ namespace :tar do
20
+
21
+ directory "#{@dvd_dir}/staging"
22
+
23
+ def get_simp_version
24
+ simp_rpm = Dir.glob("#{@base_dir}/build/SIMP/RPMS/*/simp-[0-9]*.rpm").max_by {|f| File.mtime(f)}
25
+ fail("Could not find simp main RPM in output directory!") unless simp_rpm
26
+ simp_version = File.basename(simp_rpm).gsub(".noarch.rpm","").gsub("simp-","")
27
+
28
+ return simp_version
29
+ end
30
+
31
+ ##############################################################################
32
+ # Main tasks
33
+ ##############################################################################
34
+
35
+ desc <<-EOM
36
+ Build the DVD tarball(s).
37
+
38
+ * :chroot - The mock chroot to use for pkg:build
39
+ * :key - What key to use for signing the RPMs
40
+ * :docs - Whether or not to build the documentation
41
+ * :snapshot_release - Append the timestamp to the SIMP tarball(s)
42
+ EOM
43
+ task :build,[:chroot,:key,:docs,:snapshot_release] => ['pkg:build','pkg:checksig'] do |t,args|
44
+ args.with_defaults(:docs => 'true')
45
+
46
+ validate_in_mock_group?
47
+
48
+ Parallel.map(
49
+ @target_dists,
50
+ :in_processes => get_cpu_limit,
51
+ :process => t.name
52
+ ) do |dist|
53
+ base_dir = "#{@dvd_dir}/#{dist}/staging"
54
+ destdir = "#{base_dir}/SIMP"
55
+
56
+ # Build the staging area
57
+ mkdir_p(destdir)
58
+ Simp::RPM.copy_wo_vcs(@dvd_src,".",base_dir)
59
+
60
+ # Copy in the GPG Public Keys
61
+ mkdir_p("#{destdir}/GPGKEYS")
62
+ ln(Dir.glob("#{@build_dir}/GPGKEYS/RPM-GPG-KEY*"), "#{destdir}/GPGKEYS", :force => true)
63
+
64
+ # Copy in the auto-build RPMs
65
+ Dir.chdir("#{@build_dir}/SIMP/RPMS") do
66
+ Dir.glob('*').each do |type|
67
+ dest_type = type
68
+ if File.directory?(type) then
69
+ if type =~ /i.*86/ then
70
+ dest_type = 'i386'
71
+ end
72
+
73
+ mkdir_p("#{destdir}/#{dest_type}")
74
+ Dir.chdir(type) do
75
+ ln(Dir.glob("*.#{type}.rpm"),"#{destdir}/#{dest_type}", :force => true)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ if args.docs.casecmp('true') == 0 then
82
+ # Finally, the PDF docs if they exist.
83
+ pdfs = Dir.glob("#{@src_dir}/doc/pdf/*")
84
+ if ! pdfs.empty? then
85
+ pdfs.each do |pdf|
86
+ cp(pdf,base_dir)
87
+ end
88
+ else
89
+ # If we don't have PDFs in the directory, yank them out of the
90
+ # RPM itself!
91
+ simp_doc_rpm = Dir.glob("#{@build_dir}/SIMP/RPMS/*/simp-doc*.rpm").last
92
+ if not simp_doc_rpm then
93
+ raise(Exception,"Error: Could not find simp-doc*.rpm in the build, something went very wrong")
94
+ end
95
+
96
+ Dir.mktmpdir { |dir|
97
+ Dir.chdir(dir) do
98
+ %x{rpm2cpio #{simp_doc_rpm} | cpio -u --quiet --warning none -ivd ./usr/share/doc/simp-*/pdf/SIMP*.pdf 2>&1 > /dev/null}
99
+ pdf_docs = Dir.glob("usr/share/doc/simp-*/pdf/*.pdf")
100
+
101
+ if pdf_docs.empty? then
102
+ raise(Exception,"Error: Could not find any PDFs in the simp-doc RPM, aborting.")
103
+ end
104
+
105
+ pdf_docs.each do |pdf|
106
+ cp(pdf,base_dir)
107
+ end
108
+ end
109
+ }
110
+ end
111
+ end
112
+ end
113
+
114
+ #Seeing race conditions when this is parallelized.
115
+ @simp_tarballs = {}
116
+ @target_dists.each do |dist|
117
+ base_dir = "#{@dvd_dir}/#{dist}/staging"
118
+ dvd_name = [ 'SIMP', 'DVD', dist, get_simp_version ]
119
+ dvd_tarball = "#{dvd_name.join('-')}.tar.gz"
120
+ Dir.chdir(base_dir) do
121
+ sh %{tar --owner 0 --group 0 --exclude-vcs --mode=u=rwX,g=rX,o=rX -cpzf "../#{dvd_tarball}" ./*}
122
+ mv("../#{dvd_tarball}",@dvd_dir)
123
+ end
124
+
125
+ puts "Package DVD: #{@dvd_dir}/#{dvd_tarball}"
126
+ @simp_tarballs[dist] = "#{@dvd_dir}/#{dvd_tarball}"
127
+ rm_rf(base_dir)
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
@@ -0,0 +1,115 @@
1
+ require 'ruby-progressbar'
2
+ require 'simp/rake/build/constants'
3
+
4
+ module Simp; end
5
+ module Simp::Rake; end
6
+ module Simp::Rake::Build
7
+
8
+ class Unpack < ::Rake::TaskLib
9
+ include Simp::Rake::Build::Constants
10
+
11
+ def initialize( base_dir )
12
+ init_member_vars( base_dir )
13
+ @mock = ENV['mock'] || '/usr/bin/mock'
14
+ define_tasks
15
+ end
16
+
17
+ def define_tasks
18
+ #!/usr/bin/rake -T
19
+
20
+ desc "Unpack an ISO. Unpacks either a RHEL or CentOS ISO into
21
+ <targetdir>/<RHEL|CentOS><version>-<arch>.
22
+ * :iso_path - Full path to the ISO image to unpack.
23
+ * :merge - If true, then automatically merge any existing
24
+ directories. Defaults to prompting.
25
+ * :targetdir - The parent directory for the to-be-created directory
26
+ containing the unpacked ISO. Defaults to the current directory.
27
+ * :isoinfo - The isoinfo executable to use to extract stuff from the ISO.
28
+ Defaults to 'isoinfo'.
29
+ * :version - optional override for the <version> number (e.g., '7.0' instead of '7')
30
+
31
+ "
32
+ task :unpack,[:iso_path, :merge, :targetdir, :isoinfo, :version] do |t,args|
33
+ args.with_defaults(
34
+ :iso_path => '',
35
+ :isoinfo => 'isoinfo',
36
+ :targetdir => Dir.pwd,
37
+ :merge => false,
38
+ :version => false,
39
+ )
40
+
41
+ iso_path = args.iso_path
42
+ iso_info = which(args.isoinfo)
43
+ targetdir = args.targetdir
44
+ merge = args.merge
45
+ version = args.version
46
+
47
+ # Checking for valid arguments
48
+ File.exist?(args.iso_path) or
49
+ fail "Error: You must provide the full path and filename of the ISO image."
50
+
51
+ %x{file #{iso_path}}.split(":")[1..-1].to_s =~ /ISO/ or
52
+ fail "Error: The file provided is not a valid ISO."
53
+
54
+ pieces = File.basename(iso_path,'.iso').split('-')
55
+
56
+ # Mappings of ISO name to target directory name.
57
+ # This is a hash of hashes to provide room for growth.
58
+ dvd_map = {
59
+ # RHEL structure as provided from RHN:
60
+ # rhel-server-<version>-<arch>-<whatever>
61
+ 'rhel' => {
62
+ 'baseos' => 'RHEL',
63
+ 'version' => version || pieces[2],
64
+ 'arch' => pieces[3]
65
+ },
66
+ # CentOS structure as provided from the CentOS website:
67
+ # CentOS-<version>-<arch>-<whatever>
68
+ 'CentOS' => {
69
+ 'baseos' => 'CentOS',
70
+ 'version' => version || pieces[1],
71
+ 'arch' => pieces[2]
72
+ }
73
+ }
74
+
75
+ # Determine the target directory
76
+ map = dvd_map[pieces[0]]
77
+ map.nil? and fail "Error: Could not find a mapping for '#{iso_path}'."
78
+ out_dir = "#{File.expand_path(targetdir)}/#{map['baseos']}#{map['version']}-#{map['arch']}"
79
+
80
+ # Attempt a merge
81
+ if File.exist?(out_dir) and merge.to_s.strip == 'false' then
82
+ puts "Directory '#{out_dir}' already exists! Would you like to merge? [Yn]?"
83
+ if not $stdin.gets.strip.match(/^(y.*|$)/i) then
84
+ puts "Skipping #{iso_path}"
85
+ next
86
+ end
87
+ end
88
+
89
+ puts "Target dir: #{out_dir}"
90
+ mkdir_p(out_dir)
91
+
92
+ # Unpack the ISO
93
+ iso_toc = %x{#{iso_info} -Rf -i #{iso_path}}.split("\n")
94
+ iso_toc.each do |iso_entry|
95
+ iso_toc.delete(File.dirname(iso_entry))
96
+ end
97
+
98
+ progress = ProgressBar.create(:title => 'Unpacking', :total => iso_toc.size)
99
+
100
+ iso_toc.each do |iso_entry|
101
+ target = "#{out_dir}#{iso_entry}"
102
+ if not File.exist?(target) then
103
+ FileUtils.mkdir_p(File.dirname(target))
104
+ system("#{iso_info} -R -x #{iso_entry} -i #{iso_path} > #{target}")
105
+ end
106
+ if progress then
107
+ progress.increment
108
+ else
109
+ print "#"
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/rake -T
2
+ require 'open3'
3
+ require 'simp/rpm'
4
+ require 'simp/rake/build/constants'
5
+
6
+ module Simp; end
7
+ module Simp::Rake; end
8
+ module Simp::Rake::Build
9
+
10
+ class Upload < ::Rake::TaskLib
11
+ include Simp::Rake::Build::Constants
12
+
13
+ def initialize( base_dir )
14
+ init_member_vars( base_dir )
15
+ @mock = ENV['mock'] || '/usr/bin/mock'
16
+ define_tasks
17
+ end
18
+
19
+ def define_tasks
20
+
21
+ namespace :upload do
22
+
23
+ ##############################################################################
24
+ # Helper methods
25
+ ##############################################################################
26
+
27
+ # Get a list of all packages that have been updated since the passed
28
+ # date or git identifier (tag, branch, or commit).
29
+
30
+ def get_updated_packages(start,script_format)
31
+ pkg_info = Hash.new
32
+ printed_info = false
33
+
34
+ to_check = []
35
+ # Find all static RPMs and GPGKEYS that we may need to update so
36
+ # that we can see if we have newer versions to upload!
37
+ Find.find(@build_dir) do |file|
38
+ next if file == @build_dir
39
+ Find.prune if file !~ /^#{@build_dir}\/(Ext.*(\.rpm)?|GPGKEYS)/
40
+ to_check << file if File.file?(file)
41
+ end
42
+
43
+ # Smash in all of the file files!
44
+ to_check += Dir.glob("#{@spec_dir}/*.spec")
45
+ to_check += Dir.glob("#{@src_dir}/puppet/modules/*/pkg/*.spec")
46
+
47
+ to_check.each do |file|
48
+
49
+ is_commit = false
50
+ oldstart = start
51
+ humanstart = ''
52
+ # Before changing the directory, see if we've got a commit or a
53
+ # date. If we've got a tag or branch from the top level, then we
54
+ # need to get the date from there and use it later.
55
+ Dir.chdir(@spec_dir) do
56
+ stdin,stdout,stderr = Open3.popen3('git','rev-list',start)
57
+ stderr.read !~ /^fatal:/ and is_commit = true
58
+
59
+ if is_commit then
60
+ # Snag the date.
61
+ start, humanstart = `git log #{start} --pretty=format:"%ct##%cd" --max-count=1`.chomp.split('##')
62
+ else
63
+ printed_info = true
64
+ end
65
+ end
66
+
67
+ !printed_info and puts "Info: Comparing to '#{humanstart}' based on input of '#{oldstart}'"
68
+
69
+ Dir.chdir(File.dirname(file)) do
70
+ # Get the file HEAD commit
71
+ # If we're not in a git repo, this will explode, but that's just
72
+ # fine.
73
+ current_head = `git rev-list HEAD --max-count=1`.chomp
74
+
75
+ begin
76
+ # Convert the spec files to something more human readable...
77
+ pkg_info[file] = {
78
+ :is_new => false
79
+ }
80
+ pkg_info[file][:alias] = file
81
+ if file =~ /.spec$/ then
82
+ if script_format then
83
+ pkg_info[file][:alias] = "#{@build_dir}/RPMS/#{Simp::RPM.new(file).name}*.rpm"
84
+ else
85
+ pkg_info[file][:alias] = Simp::RPM.new(file).name
86
+ end
87
+ end
88
+ rescue
89
+ raise "Error: There was an issue getting information from #{file}"
90
+ end
91
+
92
+ commit_head = nil
93
+ # It turns out that an invalid date will just return
94
+ # everything
95
+ commit_head = `git log --before="#{start}" --pretty=format:%H --max-count=1 #{File.basename(file)}`.chomp
96
+
97
+ # Did we find something different?
98
+ if commit_head.empty? then
99
+ pkg_info[file][:is_new] = true
100
+ else
101
+ pkg_info[file][:is_new] = !system('git','diff','--quiet',commit_head,File.basename(file))
102
+ end
103
+ end
104
+ end
105
+
106
+ return pkg_info
107
+ end
108
+
109
+ desc <<-EOM
110
+ Get a list of modified packages.
111
+
112
+ The package list is created from the given date or git identifier (tag, branch, or hash)
113
+ EOM
114
+ task :get_modified,[:start,:script_format] do |t,args|
115
+ args.with_defaults(:script_format => false)
116
+
117
+ args.start or raise "Error: You must specify a 'start'"
118
+
119
+ updated_pkgs = get_updated_packages(args.start, args.script_format)
120
+ updated_pkgs.keys.sort.each do |k|
121
+ updated_pkgs[k][:is_new] and puts "Updated: #{updated_pkgs[k][:alias]}"
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ "5": "7"
3
+ "4": "6"
4
+ "2": "5"
@@ -1,3 +1,5 @@
1
+ require 'rake/tasklib'
2
+
1
3
  module Simp; end
2
4
  module Simp::Rake
3
5
  class Fixtures < ::Rake::TaskLib