simp-rake-helpers 5.3.0 → 5.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -2
- data/.travis.yml +54 -37
- data/CHANGELOG.md +40 -2
- data/Gemfile +1 -0
- data/README.md +70 -82
- data/lib/simp/rake/build/auto.rb +6 -0
- data/lib/simp/rake/build/pkg.rb +2 -2
- data/lib/simp/rake/build/rpmdeps.rb +6 -3
- data/lib/simp/rake/helpers/assets/rpm_spec/simpdefault.spec +284 -71
- data/lib/simp/rake/helpers/version.rb +1 -1
- data/lib/simp/rake/pkg.rb +38 -18
- data/lib/simp/rake/rubygem.rb +1 -1
- data/lib/simp/rpm.rb +49 -6
- data/spec/acceptance/00_pkg_rpm_custom_scriptlets_spec.rb +117 -0
- data/spec/acceptance/10_pkg_rpm_spec.rb +153 -0
- data/spec/acceptance/20_pkg_rpm_safely_upgrading_obsolete_modules_spec.rb +175 -0
- data/spec/acceptance/development/docker_env.sh +29 -0
- data/spec/acceptance/development/rerun_acceptance_tests.sh +15 -0
- data/spec/acceptance/development/vagrant_rsync.sh +23 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/CHANGELOG +2 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/Rakefile +3 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/custom/overrides +14 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/metadata.json +33 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/CHANGELOG +2 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/Rakefile +3 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/custom/overrides +14 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/metadata.json +33 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/CHANGELOG +2 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/Rakefile +3 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/metadata.json +33 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/CHANGELOG +2 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/Rakefile +3 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/metadata.json +33 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/CHANGELOG +2 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/Rakefile +3 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/custom/overrides +14 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/metadata.json +33 -0
- data/spec/acceptance/files/mock_packages/pupmod-puppetlabs-stdlib.spec +32 -0
- data/spec/acceptance/files/mock_packages/pupmod-simp-foo.spec +32 -0
- data/spec/acceptance/files/mock_packages/pupmod-simp-simplib.spec +32 -0
- data/spec/acceptance/files/mock_packages/rpmbuild.sh +25 -0
- data/spec/acceptance/files/mock_packages/simp-adapter/etc/simp/adapter_config.yaml +3 -0
- data/spec/acceptance/files/mock_packages/simp-adapter/usr/local/sbin/simp_rpm_helper +406 -0
- data/spec/acceptance/files/mock_packages/simp-adapter.spec +43 -0
- data/spec/acceptance/files/testpackage_custom_scriptlet/CHANGELOG +2 -0
- data/spec/acceptance/files/testpackage_custom_scriptlet/Rakefile +3 -0
- data/spec/acceptance/files/testpackage_custom_scriptlet/build/rpm_metadata/custom/overrides +18 -0
- data/spec/acceptance/files/testpackage_custom_scriptlet/build/rpm_metadata/requires +1 -0
- data/spec/acceptance/files/testpackage_custom_scriptlet/metadata.json +33 -0
- data/spec/acceptance/nodesets/default.yml +2 -4
- data/spec/acceptance/support/pkg_rpm_helpers.rb +81 -0
- data/spec/lib/simp/rake/build/files/unmanaged_mod/build/rpm_metadata/requires +2 -1
- data/spec/lib/simp/rake/build/rpmdeps_spec.rb +2 -1
- data/spec/spec_helper_acceptance.rb +20 -1
- metadata +44 -17
- data/spec/acceptance/pkg_rpm_spec.rb +0 -164
@@ -1,70 +1,160 @@
|
|
1
1
|
%{lua:
|
2
2
|
|
3
|
+
-- This RPM spec file can build
|
3
4
|
--
|
4
|
-
--
|
5
|
-
--
|
6
|
-
--
|
7
|
-
--
|
8
|
-
--
|
9
|
-
--
|
10
|
-
--
|
11
|
-
--
|
12
|
-
--
|
13
|
-
--
|
14
|
-
-- - 'name' - package name
|
15
|
-
-- - 'version' - package version
|
16
|
-
-- - 'license' - package license
|
17
|
-
-- - 'summary' - package summary
|
18
|
-
-- - 'source' - package source
|
5
|
+
-- ## Usage
|
6
|
+
--
|
7
|
+
-- ### pup_module_info_dir
|
8
|
+
--
|
9
|
+
-- When you build, you must define the macro 'pup_module_info_dir' so that rpm
|
10
|
+
-- knows where to find preliminary information.
|
11
|
+
--
|
12
|
+
-- If 'pup_module_info_dir' isn't defined or available, rpm will look in
|
13
|
+
-- '_sourcedir' for the files, falling back to the current directory as a last
|
14
|
+
-- resort.
|
19
15
|
--
|
20
16
|
-- Example:
|
21
|
-
-- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
|
22
17
|
--
|
23
|
-
--
|
24
|
-
--
|
18
|
+
-- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
|
19
|
+
--
|
20
|
+
-- ### relevant files
|
21
|
+
--
|
22
|
+
-- 'pup_module_info_dir' should be a directory that contains the following items:
|
23
|
+
--
|
24
|
+
-- * 'metadata.json' <- REQUIRED file that must contain the
|
25
|
+
-- following metadata:
|
26
|
+
-- - 'name' - package name
|
27
|
+
-- - 'version' - package version
|
28
|
+
-- - 'license' - package license
|
29
|
+
-- - 'summary' - package summary
|
30
|
+
-- - 'source' - package source
|
31
|
+
-- * 'build/rpm_metadata/requires' <- optional list of 'Requires',
|
32
|
+
-- 'Provides', and 'Obsoletes' to
|
33
|
+
-- supplement those auto-generated in
|
34
|
+
-- this spec file.
|
35
|
+
-- * 'build/rpm_metadata/release' <- optional RPM release number to use in
|
36
|
+
-- lieu of the number '0' hard-coded in
|
37
|
+
-- this spec file.
|
38
|
+
-- * 'CHANGELOG' <- optional RPM-formatted CHANGELOG to
|
39
|
+
-- use in lieu of the minimal changelog
|
40
|
+
-- entry auto-generated in this file.
|
41
|
+
-- * 'build/rpm_metadata/custom/' <- optional directory to place files to
|
42
|
+
-- add custom scriptlets and triggers.
|
43
|
+
--
|
25
44
|
--
|
26
45
|
|
27
|
-
|
46
|
+
local LUA_DEBUG = ((rpm.expand('%{lua_debug}') or '0') == '1')
|
28
47
|
|
29
|
-
|
30
|
-
|
48
|
+
-- Print debugging info to STDERR (if LUA_DEBUG is true)
|
49
|
+
function lua_stderr( msg )
|
50
|
+
if LUA_DEBUG then
|
51
|
+
-- io.stderr:write(tostring(msg):gsub("%f[^%z\n]","LUA #stderr#: "))
|
52
|
+
-- io.stderr:write(tostring(msg))
|
53
|
+
io.stderr:write(msg)
|
54
|
+
end
|
55
|
+
end
|
31
56
|
|
32
|
-
|
33
|
-
|
57
|
+
|
58
|
+
local function get_src_dir()
|
59
|
+
local src_dir = rpm.expand('%{pup_module_info_dir}')
|
60
|
+
if src_dir:match('^%%') or (posix.stat(src_dir, 'type') ~= 'directory') then
|
61
|
+
lua_stderr("WARNING: -D pup_module_info_dir ("..tostring(src_dir)..") could not be used!\n")
|
62
|
+
lua_stderr(" falling back to src_dir = _sourcedir\n")
|
63
|
+
|
64
|
+
-- FIXME?: rpmlint considers the use of _sourcedir to be an Error:
|
65
|
+
-- (see: https://fedoraproject.org/wiki/Packaging:RPM_Source_Dir)
|
66
|
+
src_dir = rpm.expand('%{_sourcedir}')
|
67
|
+
|
68
|
+
if (posix.stat((src_dir .. "/metadata.json"), 'type') ~= 'regular') then
|
69
|
+
lua_stderr("WARNING: couldn't find metadata.json in '"..tostring(src_dir).."'!\n")
|
70
|
+
lua_stderr(" falling back to src_dir = posix.getcwd() ("..posix.getcwd()..")\n")
|
71
|
+
|
72
|
+
src_dir = posix.getcwd()
|
73
|
+
end
|
34
74
|
end
|
75
|
+
return src_dir
|
35
76
|
end
|
36
77
|
|
78
|
+
-- path to project directory / source files
|
79
|
+
src_dir = get_src_dir()
|
80
|
+
|
81
|
+
-- directory to look for customizations (e.g., scriptlets, triggers)
|
82
|
+
custom_content_dir = src_dir .. "/build/rpm_metadata/custom/"
|
83
|
+
|
84
|
+
-- list of custom content to inject into the spec file
|
85
|
+
custom_content_table = {}
|
86
|
+
|
87
|
+
-- list of scriptlets/triggers that have been declared (to avoid duplicates)
|
88
|
+
declared_scriptlets_table = {}
|
89
|
+
|
90
|
+
-- patterns to recognize scriptlet and trigger declarations
|
91
|
+
--
|
92
|
+
-- NOTE: Lua patterns are not regexes , and do not support alternation.
|
93
|
+
-- So, we try to stay efficient by iterating through as few patterns as
|
94
|
+
-- possible by short-ciruiting several matches.
|
95
|
+
-- (e.g. '^%%pre' matches both '%pre' and '%pretrans')
|
96
|
+
--
|
97
|
+
SCRIPTLET_PATTERNS = {
|
98
|
+
'^%%pre',
|
99
|
+
'^%%post',
|
100
|
+
'^%%trigger'
|
101
|
+
}
|
102
|
+
|
37
103
|
-- These UNKNOWN entries should break the build if something bad happens
|
38
104
|
|
39
105
|
package_name = "UNKNOWN"
|
40
106
|
package_version = "UNKNOWN"
|
41
107
|
module_license = "UNKNOWN"
|
42
108
|
|
43
|
-
--
|
44
109
|
-- Default to 0
|
45
|
-
--
|
46
|
-
|
47
110
|
package_release = 0
|
48
|
-
}
|
49
111
|
|
50
|
-
|
51
|
-
|
112
|
+
lua_stderr("\n")
|
113
|
+
lua_stderr("--------------------------------------------------------------------------------\n")
|
114
|
+
lua_stderr("RPM/LUA build environment:\n")
|
115
|
+
lua_stderr("------:\n")
|
116
|
+
lua_stderr("LUA _VERSION = '".._VERSION.."'\n")
|
117
|
+
lua_stderr("posix.getcwd() = '"..posix.getcwd().."'\n")
|
118
|
+
lua_stderr("\n")
|
119
|
+
lua_stderr("macros:\n")
|
120
|
+
lua_stderr("------:\n")
|
121
|
+
lua_stderr("'%{pup_module_info_dir}' = '"..rpm.expand('%{pup_module_info_dir}').."'\n")
|
122
|
+
lua_stderr("_specdir = '"..rpm.expand('%{_specdir}').."'\n")
|
123
|
+
lua_stderr("_buildrootdir = '"..rpm.expand('%{_buildrootdir}').."'\n")
|
124
|
+
lua_stderr("buildroot = '"..rpm.expand('%{buildroot}').."'\n")
|
125
|
+
lua_stderr("RPM_BUILD_ROOT = '"..rpm.expand('%{RPM_BUILD_ROOT}').."'\n")
|
126
|
+
lua_stderr("\n")
|
127
|
+
lua_stderr("local variables:\n")
|
128
|
+
lua_stderr("------:\n")
|
129
|
+
lua_stderr("src_dir = '".. src_dir .."'\n")
|
130
|
+
lua_stderr("custom_content_dir = '"..custom_content_dir.."'\n# ---\n")
|
131
|
+
lua_stderr("--------------------------------------------------------------------------------\n")
|
132
|
+
lua_stderr("\n")
|
52
133
|
|
53
|
-
metadata = ''
|
54
|
-
metadata_file = io.open(src_dir .. "/metadata.json","r")
|
55
|
-
if metadata_file then
|
56
|
-
metadata = metadata_file:read("*all")
|
57
134
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
135
|
+
-- Pull the Relevant Metadata out of the Puppet module metadata.json.
|
136
|
+
function read_metadata(src_dir)
|
137
|
+
local metadata = ''
|
138
|
+
local metadata_file = src_dir .. "/metadata.json"
|
139
|
+
local metadata_fh = io.open(metadata_file,'r')
|
140
|
+
if metadata_fh then
|
141
|
+
metadata = metadata_fh:read("*all")
|
142
|
+
|
143
|
+
-- Ignore the first curly brace
|
144
|
+
metadata = metadata:gsub("{}?", '|', 1)
|
145
|
+
|
146
|
+
-- Ignore all keys that are below the first level
|
147
|
+
metadata = metadata:gsub("{.-}", '')
|
148
|
+
metadata = metadata:gsub("%[.-%]", '')
|
149
|
+
else
|
150
|
+
error("Could not open 'metadata.json': ".. metadata_file, 0)
|
151
|
+
end
|
152
|
+
return metadata
|
66
153
|
end
|
67
154
|
|
155
|
+
|
156
|
+
metadata = read_metadata(src_dir)
|
157
|
+
|
68
158
|
-- This starts as an empty string so that we can build it later
|
69
159
|
module_requires = ''
|
70
160
|
|
@@ -74,7 +164,7 @@ module_requires = ''
|
|
74
164
|
|
75
165
|
-- Get the Module Name and put it in the correct format
|
76
166
|
|
77
|
-
local name_match =
|
167
|
+
local name_match = metadata:match('"name":%s+"(.-)"%s*,')
|
78
168
|
|
79
169
|
module_author = ''
|
80
170
|
module_name = ''
|
@@ -83,7 +173,7 @@ if name_match then
|
|
83
173
|
package_name = ('pupmod-' .. name_match)
|
84
174
|
|
85
175
|
local i = 0
|
86
|
-
for str in
|
176
|
+
for str in name_match:gmatch('[^-]+') do
|
87
177
|
if i == 0 then
|
88
178
|
module_author = str
|
89
179
|
else
|
@@ -106,7 +196,7 @@ end
|
|
106
196
|
|
107
197
|
-- Get the Module Version
|
108
198
|
|
109
|
-
local version_match =
|
199
|
+
local version_match = metadata:match('"version":%s+"(.-)"%s*,')
|
110
200
|
|
111
201
|
if version_match then
|
112
202
|
package_version = version_match
|
@@ -120,7 +210,7 @@ end
|
|
120
210
|
|
121
211
|
-- Get the Module License
|
122
212
|
|
123
|
-
local license_match =
|
213
|
+
local license_match = metadata:match('"license":%s+"(.-)"%s*,')
|
124
214
|
|
125
215
|
if license_match then
|
126
216
|
module_license = license_match
|
@@ -134,7 +224,7 @@ end
|
|
134
224
|
|
135
225
|
-- Get the Module Summary
|
136
226
|
|
137
|
-
local summary_match =
|
227
|
+
local summary_match = metadata:match('"summary":%s+"(.-)"%s*,')
|
138
228
|
|
139
229
|
if summary_match then
|
140
230
|
module_summary = summary_match
|
@@ -148,7 +238,7 @@ end
|
|
148
238
|
|
149
239
|
-- Get the Module Source line for the URL string
|
150
240
|
|
151
|
-
local source_match =
|
241
|
+
local source_match = metadata:match('"source":%s+"(.-)"%s*,')
|
152
242
|
|
153
243
|
if source_match then
|
154
244
|
module_source = source_match
|
@@ -173,8 +263,8 @@ end
|
|
173
263
|
|
174
264
|
if rel_file then
|
175
265
|
for line in rel_file:lines() do
|
176
|
-
is_comment =
|
177
|
-
is_blank =
|
266
|
+
is_comment = line:match("^%s*#")
|
267
|
+
is_blank = line:match("^%s*$")
|
178
268
|
|
179
269
|
if not (is_comment or is_blank) then
|
180
270
|
package_release = line
|
@@ -197,7 +287,7 @@ end
|
|
197
287
|
|
198
288
|
if req_file then
|
199
289
|
for line in req_file:lines() do
|
200
|
-
valid_line = (
|
290
|
+
valid_line = (line:match("^Requires: ") or line:match("^Obsoletes: ") or line:match("^Provides: "))
|
201
291
|
|
202
292
|
if valid_line then
|
203
293
|
module_requires = (module_requires .. "\n" .. line)
|
@@ -238,7 +328,10 @@ URL: %{lua: print(module_source)}
|
|
238
328
|
BuildRoot: %{_tmppath}/%{package_name}-%{version}-%{release}-buildroot
|
239
329
|
BuildArch: noarch
|
240
330
|
|
241
|
-
Requires(pre
|
331
|
+
Requires(pre): simp-adapter >= 0.0.1
|
332
|
+
Requires(preun): simp-adapter >= 0.0.1
|
333
|
+
Requires(preun): simp-adapter >= 0.0.1
|
334
|
+
Requires(postun): simp-adapter >= 0.0.1
|
242
335
|
|
243
336
|
%if ("%{package_name}" != "pupmod-simp-simplib") && ("%{package_name}" != "pupmod-puppetlabs-stdlib")
|
244
337
|
Requires: pupmod-simp-simplib >= 1.2.6
|
@@ -300,29 +393,149 @@ rm -rf %{buildroot}/%{prefix}/%{module_name}/log
|
|
300
393
|
|
301
394
|
mkdir -p %{buildroot}/%{prefix}
|
302
395
|
|
303
|
-
%
|
304
|
-
%defattr(0640,root,root,0750)
|
305
|
-
%{prefix}/%{module_name}
|
396
|
+
%{lua:
|
306
397
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
398
|
+
-- returns true if 'scriptlet_name' has already been declared
|
399
|
+
function is_scriplet_declared(scriptlet_name, declared_scriptlets_table)
|
400
|
+
for _,name in ipairs(declared_scriptlets_table) do
|
401
|
+
if (name == scriptlet_name) then
|
402
|
+
return true
|
403
|
+
end
|
404
|
+
end
|
405
|
+
return false
|
406
|
+
end
|
311
407
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
408
|
+
-- returns true if 'line' is a scriptlet or trigger header
|
409
|
+
function is_valid_scriptlet_header(line)
|
410
|
+
local match = false
|
411
|
+
for _, patt in ipairs(SCRIPTLET_PATTERNS) do
|
412
|
+
if line:match(patt) then
|
413
|
+
match = true
|
414
|
+
break
|
415
|
+
end
|
416
|
+
end
|
417
|
+
return match
|
418
|
+
end
|
419
|
+
|
420
|
+
--
|
421
|
+
-- adds content to the custom_content_table
|
422
|
+
--
|
423
|
+
function define_custom_content(
|
424
|
+
content,
|
425
|
+
custom_content_table,
|
426
|
+
declared_scriptlets_table
|
427
|
+
)
|
428
|
+
lua_stderr("# evaluating extra content: \n".. (content:gsub("%f[^%z\n]"," | ")) .."\n")
|
429
|
+
|
430
|
+
if content then
|
431
|
+
local _content = ''
|
432
|
+
local recording = true
|
433
|
+
|
434
|
+
for line in content:gmatch("([^\n]*)\n?") do
|
435
|
+
|
436
|
+
-- skip duplicate scriptlets
|
437
|
+
if is_valid_scriptlet_header(line) then
|
438
|
+
local _line = line:gsub("^%s+",""):gsub("%s+$","")
|
439
|
+
if is_scriplet_declared(_line, declared_scriptlets_table) then
|
440
|
+
lua_stderr("WARNING: scriptlet '".._line..
|
441
|
+
"' has already been declared (skipping scriptlet).\n")
|
442
|
+
recording = false
|
443
|
+
else
|
444
|
+
lua_stderr('+ "'.._line..'" is recognized as a scriptlet/trigger.\n')
|
445
|
+
recording = true
|
446
|
+
table.insert(declared_scriptlets_table, _line)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
if recording then
|
451
|
+
_content = _content .. line .. "\n"
|
452
|
+
else
|
453
|
+
lua_stderr(" skipping line '"..line.."'\n")
|
454
|
+
end
|
455
|
+
end
|
456
|
+
table.insert(custom_content_table, _content )
|
457
|
+
end
|
458
|
+
end
|
316
459
|
|
317
|
-
# when $1 = 1, this is the uninstall of the previous version during an upgrade
|
318
|
-
# when $1 = 0, this is the uninstall of the only version during an erase
|
319
|
-
%preun
|
320
|
-
/usr/local/sbin/simp_rpm_helper --rpm_dir=%{prefix}/%{module_name} --rpm_section='preun' --rpm_status=$1
|
321
460
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
461
|
+
function load_custom_content_files(custom_content_dir, custom_content_table, declared_scriptlets_table)
|
462
|
+
if (posix.stat(custom_content_dir, 'type') == 'directory') then
|
463
|
+
for i,basename in pairs(posix.dir(custom_content_dir)) do
|
464
|
+
local file = custom_content_dir .. basename
|
465
|
+
-- only accept files that are not dot files (".filename")
|
466
|
+
if (basename:match('^[^%.]') and (posix.stat(file, 'type') == 'regular')) then
|
467
|
+
lua_stderr("INFO: found custom RPM spec file snippet: '" .. file .. "'\n")
|
468
|
+
local file_handle = io.open(file,'r')
|
469
|
+
if file_handle then
|
470
|
+
local _content = file_handle:read("*all")
|
471
|
+
define_custom_content(_content, custom_content_table, declared_scriptlets_table)
|
472
|
+
else
|
473
|
+
lua_stderr("WARNING: could not read '"..file.."'\n")
|
474
|
+
end
|
475
|
+
file_handle:close()
|
476
|
+
else
|
477
|
+
lua_stderr("WARNING: skipping invalid filename '"..basename.."'\n")
|
478
|
+
end
|
479
|
+
end
|
480
|
+
else
|
481
|
+
lua_stderr("WARNING: not found: " .. custom_content_dir .. "\n")
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
-- Declares default scriptlets for SIMP 6.X (referenced from 6.1.0)
|
486
|
+
--
|
487
|
+
-- In order to keep the package-maintained pupmod-*-* pacakges
|
488
|
+
-- Packages notify /usr/local/sbin/simp_rpm_helper, which
|
489
|
+
-- See: https://github.com/simp/simp-adapter/blob/master/src/sbin/simp_rpm_helper
|
490
|
+
--
|
491
|
+
-- This function should be called last
|
492
|
+
--
|
493
|
+
function declare_default_scriptlets(custom_content_table, declared_scriptlets_table)
|
494
|
+
local DEFAULT_SCRIPTLETS = {
|
495
|
+
['pre'] = {upgrade = 2},
|
496
|
+
['post'] = {upgrade = 2},
|
497
|
+
['preun'] = {upgrade = 0},
|
498
|
+
['postun'] = {upgrade = 0}
|
499
|
+
}
|
500
|
+
local rpm_dir = rpm.expand('%{prefix}/' .. module_name)
|
501
|
+
|
502
|
+
for name,data in pairs(DEFAULT_SCRIPTLETS) do
|
503
|
+
local content = ('%'..name.."\n"..
|
504
|
+
'# (default scriptlet for SIMP 6.x)\n'..
|
505
|
+
'# when $1 = 1, this is an install\n'..
|
506
|
+
'# when $1 = '.. data.upgrade ..', this is an upgrade\n'..
|
507
|
+
'/usr/local/sbin/simp_rpm_helper --rpm_dir='..
|
508
|
+
rpm_dir.." --rpm_section='"..name.."' --rpm_status=$1\n\n"
|
509
|
+
)
|
510
|
+
|
511
|
+
define_custom_content(content, custom_content_table, declared_scriptlets_table)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
|
516
|
+
-- insert custom content (e.g., rpm_metadata/custom/*, scriptlets)
|
517
|
+
function print_extra_content( custom_content_table )
|
518
|
+
local extra_content = table.concat(custom_content_table, "\n") .. "\n"
|
519
|
+
lua_stderr("\n========== DYNAMIC CONTENT SUMMARY ========== (begin)\n" ..
|
520
|
+
rpm.expand( extra_content ) ..
|
521
|
+
"\n========== DYNAMIC CONTENT SUMMARY ========== (end)\n")
|
522
|
+
print(extra_content)
|
523
|
+
end
|
524
|
+
|
525
|
+
|
526
|
+
load_custom_content_files(
|
527
|
+
custom_content_dir,
|
528
|
+
custom_content_table,
|
529
|
+
declared_scriptlets_table
|
530
|
+
)
|
531
|
+
declare_default_scriptlets(custom_content_table, declared_scriptlets_table)
|
532
|
+
print_extra_content(custom_content_table)
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
%files
|
537
|
+
%defattr(0640,root,root,0750)
|
538
|
+
%{prefix}/%{module_name}
|
326
539
|
|
327
540
|
%changelog
|
328
541
|
%{lua:
|
@@ -345,7 +558,7 @@ default_lookup_table = {
|
|
345
558
|
changelog = io.open(src_dir .. "/CHANGELOG","r")
|
346
559
|
if changelog then
|
347
560
|
first_line = changelog:read()
|
348
|
-
if
|
561
|
+
if first_line:match("^*%s+%a%a%a%s+%a%a%a%s+%d%d?%s+%d%d%d%d%s+.+") then
|
349
562
|
changelog:seek("set",0)
|
350
563
|
print(changelog:read("*all"))
|
351
564
|
else
|
data/lib/simp/rake/pkg.rb
CHANGED
@@ -54,6 +54,7 @@ module Simp::Rake
|
|
54
54
|
'dist/rpmbuild',
|
55
55
|
'spec/fixtures/modules'
|
56
56
|
]
|
57
|
+
@verbose = ENV.fetch('SIMP_RAKE_PKG_verbose','no') == 'yes'
|
57
58
|
|
58
59
|
# This is only meant to be used to work around the case where particular
|
59
60
|
# packages need to ignore some set of artifacts that get updated out of
|
@@ -65,7 +66,7 @@ module Simp::Rake
|
|
65
66
|
@ignore_changes_list += ENV['SIMP_INTERNAL_pkg_ignore'].split(',')
|
66
67
|
end
|
67
68
|
|
68
|
-
FileUtils.mkdir_p(@pkg_tmp_dir)
|
69
|
+
FileUtils.mkdir_p(@pkg_tmp_dir, verbose: @verbose)
|
69
70
|
|
70
71
|
local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
|
71
72
|
unless local_spec.empty?
|
@@ -79,7 +80,7 @@ module Simp::Rake
|
|
79
80
|
@spec_tempfile.flush
|
80
81
|
@spec_tempfile.close
|
81
82
|
|
82
|
-
FileUtils.chmod(0640, @spec_file)
|
83
|
+
FileUtils.chmod(0640, @spec_file, verbose: @verbose)
|
83
84
|
end
|
84
85
|
|
85
86
|
::CLEAN.include( @pkg_dir )
|
@@ -134,7 +135,7 @@ module Simp::Rake
|
|
134
135
|
end
|
135
136
|
|
136
137
|
@rpm_srcdir ||= "#{@pkg_dir}/rpmbuild/SOURCES"
|
137
|
-
FileUtils.mkdir_p(@rpm_srcdir)
|
138
|
+
FileUtils.mkdir_p(@rpm_srcdir, verbose: @verbose)
|
138
139
|
|
139
140
|
@tar_dest ||= "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
|
140
141
|
|
@@ -210,6 +211,9 @@ module Simp::Rake
|
|
210
211
|
end
|
211
212
|
|
212
213
|
def define_pkg_rpm
|
214
|
+
|
215
|
+
# :pkg:rpm
|
216
|
+
# -----------------------------
|
213
217
|
namespace :pkg do
|
214
218
|
desc <<-EOM
|
215
219
|
Build the #{@pkg_name} RPM.
|
@@ -226,21 +230,29 @@ module Simp::Rake
|
|
226
230
|
%(-D '_srcrpmdir #{@pkg_dir}'),
|
227
231
|
%(-D '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm')
|
228
232
|
]
|
229
|
-
|
233
|
+
rpm_opts << '-v' if @verbose
|
234
|
+
rpm_opts << "-D 'lua_debug 1'" if (ENV.fetch('SIMP_RAKE_PKG_LUA_verbose','no') =='yes')
|
235
|
+
rpm_opts << "-D 'pup_module_info_dir #{@base_dir}'"
|
230
236
|
Dir.chdir(@pkg_dir) do
|
231
237
|
|
232
238
|
# Copy in the materials required for the module builds
|
233
239
|
# The following are required to build successful RPMs using
|
234
240
|
# the new LUA-based RPM template
|
235
241
|
puppet_module_info_files = [
|
236
|
-
Dir.glob(%(#{@base_dir}/build/rpm_metadata
|
242
|
+
Dir.glob(%(#{@base_dir}/build/rpm_metadata/**)),
|
237
243
|
%(#{@base_dir}/CHANGELOG),
|
238
244
|
%(#{@base_dir}/metadata.json)
|
239
245
|
].flatten
|
240
246
|
|
247
|
+
if @verbose
|
248
|
+
puts "==== pkg:rpm: @base_dir: #{@base_dir}"
|
249
|
+
puts "==== pkg:rpm: rpm_opts:\n #{rpm_opts.map{|x| "\n #{x}"}.join}"
|
250
|
+
puts "==== pkg:rpm: puppet_module_info_files: #{puppet_module_info_files.map{|x| "\n #{x}"}.join}"
|
251
|
+
end
|
252
|
+
|
241
253
|
puppet_module_info_files.each do |f|
|
242
254
|
if File.exist?(f)
|
243
|
-
FileUtils.cp_r(f, @rpm_srcdir)
|
255
|
+
FileUtils.cp_r(f, @rpm_srcdir, verbose: @verbose)
|
244
256
|
end
|
245
257
|
end
|
246
258
|
|
@@ -251,26 +263,28 @@ module Simp::Rake
|
|
251
263
|
Dir.chdir(@rpm_srcdir) do
|
252
264
|
extra_deps.each do |dep|
|
253
265
|
unless File.exist?(dep)
|
254
|
-
FileUtils.cp_r("../../#{dep}", dep)
|
266
|
+
FileUtils.cp_r("../../#{dep}", dep, verbose: @verbose)
|
255
267
|
end
|
256
268
|
end
|
257
269
|
end
|
258
270
|
|
259
|
-
FileUtils.mkdir_p('logs')
|
260
|
-
FileUtils.mkdir_p('rpmbuild/BUILDROOT')
|
261
|
-
FileUtils.mkdir_p('rpmbuild/BUILD')
|
271
|
+
FileUtils.mkdir_p('logs', verbose: @verbose)
|
272
|
+
FileUtils.mkdir_p('rpmbuild/BUILDROOT', verbose: @verbose)
|
273
|
+
FileUtils.mkdir_p('rpmbuild/BUILD', verbose: @verbose)
|
262
274
|
|
263
275
|
srpms = [@full_pkg_name + '.src.rpm']
|
264
276
|
if require_rebuild?(srpms.first, @tar_dest)
|
265
277
|
# Need to build the SRPM so that we can get the build dependencies
|
266
|
-
%
|
278
|
+
cmd = %(rpmbuild #{rpm_opts.join(' ')} -bs #{@spec_file} > logs/build.srpm.out 2> logs/build.srpm.err)
|
279
|
+
puts "==== pkg:rpm SRPM BUILD: #{cmd}" if @verbose
|
280
|
+
%x(#{cmd})
|
267
281
|
|
268
|
-
srpms = File.read('logs/build.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten
|
282
|
+
srpms = File.read('logs/build.srpm.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten
|
269
283
|
|
270
284
|
if srpms.empty?
|
271
285
|
raise <<-EOM
|
272
286
|
Could not create SRPM for '#{@spec_info.basename}
|
273
|
-
Error: #{File.read('logs/build.err')}
|
287
|
+
Error: #{File.read('logs/build.srpm.err')}
|
274
288
|
EOM
|
275
289
|
end
|
276
290
|
end
|
@@ -327,7 +341,10 @@ module Simp::Rake
|
|
327
341
|
rpms = expected_rpms
|
328
342
|
else
|
329
343
|
# Try a build
|
330
|
-
%
|
344
|
+
cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
|
345
|
+
puts "==== pkg:rpm: #{cmd}" if @verbose
|
346
|
+
_result = %x(#{cmd})
|
347
|
+
puts _result if @verbose
|
331
348
|
|
332
349
|
# If the build failed, it was probably due to missing dependencies
|
333
350
|
unless $?.success?
|
@@ -359,6 +376,7 @@ module Simp::Rake
|
|
359
376
|
unless Process.uid == 0
|
360
377
|
yum_install_cmd = 'sudo ' + yum_install_cmd
|
361
378
|
end
|
379
|
+
puts "==== pkg:rpm: #{yum_install_cmd}" if @verbose
|
362
380
|
|
363
381
|
install_output = %x(#{yum_install_cmd} 2>&1)
|
364
382
|
|
@@ -373,14 +391,16 @@ module Simp::Rake
|
|
373
391
|
# Try it again!
|
374
392
|
#
|
375
393
|
# If this doesn't work, something we can't fix automatically is wrong
|
376
|
-
%
|
394
|
+
cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
|
395
|
+
puts "==== pkg:rpm: #{cmd}" if @verbose
|
396
|
+
%x(#{cmd})
|
377
397
|
|
378
|
-
rpms = File.read('logs/build.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten - srpms
|
398
|
+
rpms = File.read('logs/build.rpm.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten - srpms
|
379
399
|
|
380
400
|
if rpms.empty?
|
381
401
|
raise <<-EOM
|
382
402
|
Could not create RPM for '#{@spec_info.basename}
|
383
|
-
Error: #{File.read('logs/build.err')}
|
403
|
+
Error: #{File.read('logs/build.rpm.err')}
|
384
404
|
EOM
|
385
405
|
end
|
386
406
|
end
|
@@ -514,7 +534,7 @@ module Simp::Rake
|
|
514
534
|
# -----------------------------
|
515
535
|
desc <<-EOM
|
516
536
|
Generate an appropriate changelog for an annotated tag from a
|
517
|
-
component's CHANGELOG or RPM spec file.
|
537
|
+
component's CHANGELOG or RPM spec file.
|
518
538
|
|
519
539
|
The changelog text will be for the latest version and contain
|
520
540
|
1 or more changelog entries for that version, in reverse
|
data/lib/simp/rake/rubygem.rb
CHANGED