simp-rake-helpers 2.3.2 → 2.4.0

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
  SHA1:
3
- metadata.gz: ce25412c6f102f127038c0ff8493905dfe4f1a54
4
- data.tar.gz: 4396a2d08526f13478e4d51b2c7402fb82111753
3
+ metadata.gz: bf37e26d7fd61c248ece71b5e56c632b38ff3237
4
+ data.tar.gz: fa3621dc06beb969d539fa96005f56d4d9c576f6
5
5
  SHA512:
6
- metadata.gz: 30be844d17330402b66b8f852d65113bbcbcd1d676667e869e65bdbc5b22ce00900ab96d81103fd5fe595e63acf28a5f0ca1d9285e49ad2b1a4d16a7f5cf514f
7
- data.tar.gz: 9fb77e3056d3510bc5b1182735341f62a4e7ba07347f3c83eeb0e5c5a54d90ef4daee4a1c5dce85113284046fa26841ae2bbc63b9ef9bcda3580f6a7271b1247
6
+ metadata.gz: 56d8d61349d574a4c289aa2535d8e1be5ad97ffcb57b5df32864884828698476682a3d7363e089f7ba8c18992cf5da10dafb4771c661fe8f33f4bfae62e1dbca
7
+ data.tar.gz: 4d255776d04b43274c6805d26142ee2b1c3cadbcc9cbcbf2081b45b3e6779d52c8d9facd07934e6052ea42bd4622c9c9c62bf353733df0665a78c42f9fa67861
@@ -1,3 +1,7 @@
1
+ ### 2.4.0 / 2016-06-29
2
+ * Add a Lua-based RPM template to the build stack allowing us to build *any*
3
+ Puppet module as an RPM without forking.
4
+
1
5
  ### 2.3.2 / 2016-06-29
2
6
  * Force a useful failure on repoclosure issues
3
7
 
@@ -598,36 +598,18 @@ protect=1
598
598
 
599
599
  Dir.chdir(dir) do
600
600
  if File.exist?('Rakefile')
601
- # Read the package metadata file and proceed accordingly.
602
- module_metadata = default_metadata
603
- if File.exist?('build/package_metadata.yaml')
604
- module_metadata.merge!(YAML.load(File.read('build/package_metadata.yaml')))
605
- end
606
-
607
- # @simp_version should be set in the main Rakefile
608
- build_module = false
609
- Array(module_metadata['valid_versions']).each do |version_regex|
610
- build_module = Regexp.new("^#{version_regex}$").match(@simp_version)
611
- break if build_module
612
- end
613
-
614
- if build_module
615
- unique_build = (get_cpu_limit != 1)
616
- %x{rake pkg:rpm[#{chroot},unique_build,#{snapshot_release}]}
617
-
618
- # Glob all generated rpms, and add their metadata to a result array.
619
- pkginfo = Hash.new
620
- Dir.glob('dist/*.rpm') do |rpm|
621
- if not rpm =~ /.*.src.rpm/ then
622
- # get_info from each generated rpm, not the spec file, so macros in the
623
- # metadata have already been resolved in the mock chroot.
624
- pkginfo = Simp::RPM.get_info(rpm)
625
- result << [pkginfo,module_metadata]
626
- end
601
+ unique_build = (get_cpu_limit != 1)
602
+ %x{rake pkg:rpm[#{chroot},unique_build,#{snapshot_release}]}
603
+
604
+ # Glob all generated rpms, and add their metadata to a result array.
605
+ pkginfo = Hash.new
606
+ Dir.glob('dist/*.rpm') do |rpm|
607
+ if not rpm =~ /.*.src.rpm/ then
608
+ # get_info from each generated rpm, not the spec file, so macros in the
609
+ # metadata have already been resolved in the mock chroot.
610
+ pkginfo = Simp::RPM.get_info(rpm)
611
+ result << [pkginfo,module_metadata]
627
612
  end
628
- else
629
- puts "Warning: #{Simp::RPM.get_info(Dir.glob('build/*.spec').first)[:name]} is not \
630
- valid against SIMP version #{@simp_version.gsub("%{?snapshot_release}","")} and will not be built."
631
613
  end
632
614
  else
633
615
  puts "Warning: Could not find Rakefile in '#{dir}'"
@@ -0,0 +1,300 @@
1
+ module Simp; end
2
+ module Simp::Rake; end
3
+ module Simp::Rake::Helpers; end
4
+ module Simp::Rake::Helpers::RPM_Spec
5
+
6
+ def self.template
7
+ return <<-EOF
8
+ %{lua:
9
+
10
+ --
11
+ -- When you build you must to pass this along so that we know how
12
+ -- to get the preliminary information.
13
+ -- This directory should hold the following items:
14
+ -- * 'build' directory
15
+ -- * 'CHANGELOG' <- The RPM formatted Changelog
16
+ -- * 'metadata.json'
17
+ --
18
+ -- Example:
19
+ -- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
20
+ --
21
+
22
+ src_dir = rpm.expand('%{pup_module_info_dir}')
23
+ if string.match(src_dir, '^%%') or (posix.stat(src_dir, 'type') ~= 'directory') then
24
+ src_dir = './'
25
+ end
26
+
27
+ -- These UNKNOWN entries should break the build if something bad happens
28
+
29
+ module_name = "UNKNOWN"
30
+ module_version = "UNKNOWN"
31
+ module_license = "UNKNOWN"
32
+
33
+ -- Default to 0
34
+ module_release = '0'
35
+
36
+ }
37
+
38
+ %{lua:
39
+ -- Pull the Relevant Metadata out of the Puppet module metadata.json.
40
+
41
+ metadata = ''
42
+ metadata_file = io.open(src_dir .. "/metadata.json","r")
43
+ if metadata_file then
44
+ metadata = metadata_file:read("*all")
45
+ end
46
+
47
+ -- This starts as an empty string so that we can build it later
48
+ module_requires = ''
49
+
50
+ }
51
+
52
+ %{lua:
53
+
54
+ -- Get the Module Name and put it in the correct format
55
+
56
+ local name_match = string.match(metadata, '"name":%s+"(.-)"%s*,')
57
+
58
+ if name_match then
59
+ local i = 0
60
+ for str in string.gmatch(name_match,'[^-]+') do
61
+ if i ~= 0 then
62
+ if i == 1 then
63
+ module_name = str
64
+ else
65
+ module_name = (module_name .. '-' .. str)
66
+ end
67
+ end
68
+
69
+ i = i+1
70
+ end
71
+ end
72
+
73
+ }
74
+
75
+ %{lua:
76
+
77
+ -- Get the Module Version
78
+ -- This will not be processed at all
79
+
80
+ local version_match = string.match(metadata, '"version":%s+"(.-)"%s*,')
81
+
82
+ if version_match then
83
+ module_version = version_match
84
+ end
85
+
86
+ }
87
+
88
+ %{lua:
89
+
90
+ -- Get the Module License
91
+ -- This will not be processed at all
92
+
93
+ local license_match = string.match(metadata, '"license":%s+"(.-)"%s*,')
94
+
95
+ if license_match then
96
+ module_license = license_match
97
+ end
98
+
99
+ }
100
+
101
+ %{lua:
102
+
103
+ -- Get the Module Summary
104
+ -- This will not be processed at all
105
+
106
+ local summary_match = string.match(metadata, '"summary":%s+"(.-)"%s*,')
107
+
108
+ if summary_match then
109
+ module_summary = summary_match
110
+ end
111
+
112
+ }
113
+
114
+ %{lua:
115
+
116
+ -- Get the Module Source line for the URL string
117
+ -- This will not be processed at all
118
+
119
+ local source_match = string.match(metadata, '"source":%s+"(.-)"%s*,')
120
+
121
+ if source_match then
122
+ module_source = source_match
123
+ end
124
+
125
+ }
126
+
127
+ %{lua:
128
+
129
+ -- Snag the RPM-specific items out of the 'build/rpm_metadata' directory
130
+
131
+ -- First, the Release Number
132
+
133
+ local rel_file = io.open(src_dir .. "/build/rpm_metadata/release", "r")
134
+ if rel_file then
135
+ for line in rel_file:lines() do
136
+ is_comment = string.match(line, "^%s*#")
137
+ is_blank = string.match(line, "^%s*$")
138
+
139
+ if not (is_comment or is_blank) then
140
+ module_release = line
141
+ break
142
+ end
143
+ end
144
+ end
145
+
146
+ }
147
+
148
+ %{lua:
149
+
150
+ -- Next, the Requirements
151
+ local req_file = io.open(src_dir .. "/build/rpm_metadata/requires", "r")
152
+ if req_file then
153
+ for line in req_file:lines() do
154
+ valid_line = (string.match(line, "^Requires: ") or string.match(line, "^Obsoletes: ") or string.match(line, "^Provides: "))
155
+
156
+ if valid_line then
157
+ module_requires = (module_requires .. "\\n" .. line)
158
+ end
159
+ end
160
+ end
161
+ }
162
+
163
+ %define module_name %{lua: print(module_name)}
164
+ %define base_name pupmod-%{module_name}
165
+
166
+ %{lua:
167
+ -- Determine which Variant we are going to build
168
+
169
+ local variant = rpm.expand("%{_variant}")
170
+ local variant_version = nil
171
+
172
+ local foo = ""
173
+
174
+ local i = 0
175
+ for str in string.gmatch(variant,'[^-]+') do
176
+ if i == 0 then
177
+ variant = str
178
+ elseif i == 1 then
179
+ variant_version = str
180
+ else
181
+ break
182
+ end
183
+
184
+ i = i+1
185
+ end
186
+
187
+ rpm.define("variant " .. variant)
188
+
189
+ if variant == "pe" then
190
+ rpm.define("puppet_user pe-puppet")
191
+ else
192
+ rpm.define("puppet_user puppet")
193
+ end
194
+
195
+ if variant == "pe" then
196
+ if variant_version and ( rpm.vercmp(variant_version,'4') >= 0 ) then
197
+ rpm.define("_sysconfdir /etc/puppetlabs/code")
198
+ else
199
+ rpm.define("_sysconfdir /etc/puppetlabs/puppet")
200
+ end
201
+ elseif variant == "p4" then
202
+ rpm.define("_sysconfdir /etc/puppetlabs/code")
203
+ else
204
+ rpm.define("_sysconfdir /etc/puppet")
205
+ end
206
+ }
207
+
208
+ Summary: %{module_name} Puppet Module
209
+ %if 0%{?_variant:1}
210
+ Name: %{base_name}-%{_variant}
211
+ %else
212
+ Name: %{base_name}
213
+ %endif
214
+
215
+ Version: %{lua: print(module_version)}
216
+ Release: %{lua: print(module_release)}
217
+ License: %{lua: print(module_license)}
218
+ Group: Applications/System
219
+ Source: %{base_name}-%{version}-%{release}.tar.gz
220
+ URL: %{lua: print(module_source)}
221
+ BuildRoot: %{_tmppath}/%{base_name}-%{version}-%{release}-buildroot
222
+ BuildArch: noarch
223
+
224
+ %if "%{variant}" == "pe"
225
+ Requires: pe-puppet
226
+ %else
227
+ Requires: puppet
228
+ %endif
229
+
230
+ %{lua: print(module_requires)}
231
+
232
+ Prefix: %{_sysconfdir}/environments/simp/modules
233
+
234
+ %description
235
+ %{lua: print(module_summary)}
236
+
237
+ %prep
238
+ %setup -q -n %{base_name}-%{version}
239
+
240
+ %build
241
+
242
+ %install
243
+ [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
244
+
245
+ mkdir -p %{buildroot}/%{prefix}
246
+
247
+ rm -rf .git
248
+ rm -f *.lock
249
+ rm -rf spec/fixtures/modules
250
+ rm -rf dist
251
+ rm -rf junit
252
+ rm -rf log
253
+
254
+ curdir=`pwd`
255
+ dirname=`basename $curdir`
256
+ cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
257
+
258
+ %clean
259
+ [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
260
+
261
+ mkdir -p %{buildroot}/%{prefix}
262
+
263
+ %files
264
+ %defattr(0640,root,%{puppet_user},0750)
265
+ %{prefix}/%{module_name}
266
+
267
+ %changelog
268
+ %{lua:
269
+ -- Finally, the CHANGELOG
270
+
271
+ -- A default CHANGELOG in case we cannot find a real one
272
+
273
+ default_changelog = [===[
274
+ * $date Auto Changelog <auto@no.body> - $version-$release
275
+ - Latest release of $name
276
+ ]===]
277
+
278
+ default_lookup_table = {
279
+ date = os.date("%a %b %d %Y"),
280
+ version = module_version,
281
+ release = module_release,
282
+ name = module_name
283
+ }
284
+
285
+ changelog = io.open(src_dir .. "/CHANGELOG","r")
286
+ if changelog then
287
+ first_line = changelog:read()
288
+ if string.match(first_line, "^*%s+%a%a%a%s+%a%a%a%s+%d%d?%s+%d%d%d%d%s+.+") then
289
+ changelog:seek("set",0)
290
+ print(changelog:read("*all"))
291
+ else
292
+ print((default_changelog:gsub('$(%w+)', default_lookup_table)))
293
+ end
294
+ else
295
+ print((default_changelog:gsub('$(%w+)', default_lookup_table)))
296
+ end
297
+ }
298
+ EOF
299
+ end
300
+ end
@@ -2,5 +2,5 @@ module Simp; end
2
2
  module Simp::Rake; end
3
3
 
4
4
  class Simp::Rake::Helpers
5
- VERSION = '2.3.2'
5
+ VERSION = '2.4.0'
6
6
  end
@@ -7,6 +7,7 @@ require 'rake/tasklib'
7
7
  require 'fileutils'
8
8
  require 'find'
9
9
  require 'simp/rpm'
10
+ require 'simp/rake/helpers/rpm_spec'
10
11
 
11
12
  module Simp; end
12
13
  module Simp::Rake
@@ -41,14 +42,28 @@ module Simp::Rake
41
42
  def initialize( base_dir, unique_name=nil )
42
43
  @base_dir = base_dir
43
44
  @pkg_name = File.basename(@base_dir)
44
- @spec_file = Dir.glob("#{@base_dir}/build/*.spec").first
45
- @pkg_dir = "#{@base_dir}/dist"
45
+ @pkg_dir = File.join(@base_dir, 'dist')
46
+ @pkg_tmp_dir = File.join(@pkg_dir, 'tmp')
46
47
  @exclude_list = [ File.basename(@pkg_dir) ]
47
48
  @clean_list = []
48
49
  @ignore_changes_list = []
49
50
  @chroot_name = unique_name
50
51
  @mock_root_dir = ENV.fetch('SIMP_BUILD_MOCK_root','/var/lib/mock')
51
52
 
53
+ local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
54
+ unless local_spec.empty?
55
+ @spec_file = local_spec.first
56
+ else
57
+ FileUtils.mkdir_p(@pkg_tmp_dir) unless File.directory?(@pkg_tmp_dir)
58
+
59
+ @spec_tempfile = File.open(File.join(@pkg_tmp_dir, "#{@pkg_name}.spec"), 'w')
60
+ @spec_tempfile.write(Simp::Rake::Helpers::RPM_Spec.template)
61
+ @spec_tempfile.flush
62
+
63
+ @spec_file = @spec_tempfile.path
64
+ FileUtils.chmod(0640, @spec_file)
65
+ end
66
+
52
67
  # The following are required to build successful RPMs using the new
53
68
  # LUA-based RPM template
54
69
 
@@ -96,12 +111,17 @@ module Simp::Rake
96
111
  if chroot
97
112
  @chroot_name = @chroot_name || "#{@spec_info[:name]}__#{ENV.fetch( 'USER', 'USER' )}"
98
113
  mock_cmd = mock_pre_check( chroot, @chroot_name, unique ) + " --root #{chroot}"
99
-
100
114
  # Need to do this in case there is already a directory in /tmp
101
115
  rand_dirname = (0...10).map { ('a'..'z').to_a[rand(26)] }.join
102
116
  rand_tmpdir = %(/tmp/#{rand_dirname}_tmp)
103
117
 
118
+ # Hack to work around the fact that we have conflicting '-D' entries
119
+ # TODO: Refactor this
120
+ mock_cmd = mock_cmd.split(/-D '.*?'/).join
121
+ mock_cmd = "#{mock_cmd} -D 'pup_module_info_dir #{rand_tmpdir}'"
122
+
104
123
  sh %Q(#{mock_cmd} --chroot 'mkdir -p #{rand_tmpdir}')
124
+ sh %Q(#{mock_cmd} --chroot 'sed -i /pup_module_info_dir/d ~/.rpmmacros')
105
125
 
106
126
  @puppet_module_info_files .each do |copy_in|
107
127
  if File.exist?(copy_in)
@@ -125,6 +145,11 @@ module Simp::Rake
125
145
  @mfull_pkg_name = "#{@dir_name}-#{@spec_info[:release]}"
126
146
  @full_pkg_name = @mfull_pkg_name.gsub("%{?snapshot_release}","")
127
147
  @tar_dest = "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
148
+
149
+ if @tar_dest =~ /UNKNOWN/
150
+ fail("Error: Could not determine package information from 'metadata.json'. Got '#{File.basename(@tar_dest)}'")
151
+ end
152
+
128
153
  @variants = (ENV['SIMP_BUILD_VARIANTS'].to_s.split(',') + ['default'])
129
154
  end
130
155
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-rake-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-29 00:00:00.000000000 Z
12
+ date: 2016-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -408,6 +408,7 @@ files:
408
408
  - lib/simp/rake/build/vermap.yaml
409
409
  - lib/simp/rake/fixtures.rb
410
410
  - lib/simp/rake/helpers.rb
411
+ - lib/simp/rake/helpers/rpm_spec.rb
411
412
  - lib/simp/rake/helpers/version.rb
412
413
  - lib/simp/rake/pkg.rb
413
414
  - lib/simp/rake/pupmod/helpers.rb