forked from puppetlabs/puppetdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
302 lines (263 loc) · 10.2 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
require 'rake'
require 'erb'
PE_BUILD = ENV['PE_BUILD'] || ''
if PE_BUILD.downcase == 'true'
ENV['PATH'] = "/opt/puppet/bin:" + ENV['PATH']
end
PATH = ENV['PATH']
DESTDIR= ENV['DESTDIR'] || ''
def version
# This ugly bit removes the gSHA1 portion of the describe as that causes failing tests
if File.exists?('.git')
%x{git describe}.chomp.gsub('-', '.').split('.')[0..3].join('.').gsub('v', '')
else
%x{pwd}.strip!.split('.')[-1]
end
end
def cp_pr(src, dest, options={})
mandatory = {:preserve => true}
cp_r(src, dest, options.merge(mandatory))
end
def cp_p(src, dest, options={})
mandatory = {:preserve => true}
cp(src, dest, options.merge(mandatory))
end
require 'facter'
osfamily = Facter.value(:osfamily).downcase
if osfamily.downcase =~ /debian/ and PE_BUILD == ''
@plibdir = '/usr/lib/ruby/1.8'
elsif osfamily.downcase =~ /debian/ and PE_BUILD.downcase == "true"
@plibdir = '/opt/puppet/lib/ruby/1.8'
elsif osfamily.downcase =~ /redhat/ and PE_BUILD == ''
@plibdir = '/usr/lib/ruby/site_ruby/1.8'
elsif osfamily.downcase =~ /redhat/ and PE_BUILD.downcase == "true"
@plibdir = '/opt/puppet/lib/ruby/site_ruby/1.8'
end
if PE_BUILD.downcase.strip == "true"
@install_dir = "/opt/puppet/share/puppetdb"
@config_dir = "/etc/puppetlabs/puppetdb/conf.d"
@initscriptname = "/etc/init.d/pe-puppetdb"
@log_dir = "/var/log/pe-puppetdb"
@lib_dir = "/opt/puppet/share/puppetdb"
@name ="pe-puppetdb"
@pe = true
@version = version
@sbin_dir = "/opt/puppet/sbin"
else
@install_dir = "/usr/share/puppetdb"
@config_dir = "/etc/puppetdb/conf.d"
@initscriptname = "/etc/init.d/puppetdb"
@log_dir = "/var/log/puppetdb"
@lib_dir = "/usr/share/puppetdb"
@link = "/var/lib/puppetdb"
@name = "puppetdb"
@pe = false
@version = version
@sbin_dir = "/usr/sbin"
end
desc "Create a source install of PuppetDB"
task :sourceinstall do
ENV['SOURCEINSTALL'] = 1
Rake::Task[:install].invoke
end
def erb(erbfile, outfile)
if ENV['SOURCEINSTALL'] == 1
@install_dir = "#{DESTDIR}/@install_dir"
@config_dir = "#{DESTDIR}/@config_dir"
@initscriptname = "#{DESTDIR}/@initscript"
@log_dir = "#{DESTDIR}/@log_dir"
@lib_dir = "#{DESTDIR}/@lib_dir"
@link = "#{DESTDIR}/@link"
end
template = File.read(erbfile)
message = ERB.new(template, nil, "-")
output = message.result(binding)
File.open(outfile, 'w') { |f| f.write output }
puts "Generated: #{outfile}"
end
JAR_FILE_V = "puppetdb-#{@version}-standalone.jar"
JAR_FILE = "puppetdb.jar"
task :default => [ :package ]
desc "Build the uberjar"
task :uberjar => [ ] do
if `which lein`
sh "lein uberjar"
mv JAR_FILE_V, JAR_FILE
else
puts "You need lein on your system"
exit 1
end
end
desc "Create a source tar archive"
task :package => [ JAR_FILE, :template ] do
workdir = "pkg/puppetdb-#{@version}"
mkdir_p workdir
FileList[ "ext", "*.md", JAR_FILE, "spec", "Rakefile" ].each do |f|
cp_pr f, workdir
end
mv "#{workdir}/ext/files/debian", workdir
cp_pr "puppet", "#{workdir}/ext/master"
sh "cd pkg; tar --exclude=.gitignore -zcf puppetdb-#{@version}.tar.gz puppetdb-#{@version}"
rm_rf workdir
puts
puts "Wrote #{`pwd`.strip}/pkg/puppetdb-#{@version}"
end
file JAR_FILE do |t|
Rake::Task[:uberjar].invoke
end
task :allclean => [ :clobber ]
desc "Remove build artifacts (other than clojure (lein) builds)"
task :clean do
rm_rf FileList["ext/files", "pkg", "*.tar.gz"]
end
desc "Get rid of build artifacts including clojure (lein) builds"
task :clobber => [ :clean ] do
rm_rf FileList["puppetdb*jar"]
end
file "ext/files/config.ini" => [ :template, JAR_FILE ] do
end
task :template => [ :clean ] do
mkdir_p "ext/files/debian"
# files for deb and rpm
erb "ext/templates/log4j.properties.erb", "ext/files/log4j.properties"
erb "ext/templates/config.ini.erb" , "ext/files/config.ini"
erb "ext/templates/jetty.ini.erb", "ext/files/jetty.ini"
erb "ext/templates/repl.ini.erb", "ext/files/repl.ini"
erb "ext/templates/database.ini.erb", "ext/files/database.ini"
# files for deb
erb "ext/templates/init_debian.erb", "ext/files/debian/#{@name}.init"
erb "ext/templates/puppetdb_default.erb", "ext/files/debian/#{@name}.default"
erb "ext/templates/deb/control.erb", "ext/files/debian/control"
erb "ext/templates/deb/postrm.erb", "ext/files/debian/#{@name}.postrm"
erb "ext/templates/deb/base.install.erb", "ext/files/debian/#{@name}.install"
erb "ext/templates/deb/terminus.install.erb", "ext/files/debian/#{@name}-terminus.install"
erb "ext/templates/deb/rules.erb", "ext/files/debian/rules"
chmod 0755, "ext/files/debian/rules"
erb "ext/templates/deb/changelog.erb", "ext/files/debian/changelog"
erb "ext/templates/deb/base.postinst.erb", "ext/files/debian/#{@name}.postinst"
erb "ext/templates/deb/terminus.postinst.erb", "ext/files/debian/#{@name}-terminus.postinst"
erb "ext/templates/deb/preinst.erb", "ext/files/debian/#{@name}.preinst"
erb "ext/templates/deb/postinst.erb", "ext/files/debian/#{@name}.postinst"
erb "ext/templates/logrotate.erb", "ext/files/debian/#{@name}.logrotate"
erb "ext/templates/init_debian.erb", "ext/files/#{@name}.debian.init"
cp_pr FileList["ext/templates/deb/*"], "ext/files/debian"
cp_pr "ext/templates/puppetdb-ssl-setup", "ext/files"
chmod 0700, "ext/files/puppetdb-ssl-setup"
rm_rf FileList["ext/files/debian/*.erb"]
# files for rpm
erb "ext/templates/logrotate.erb", "ext/files/puppetdb.logrotate"
erb "ext/templates/init_redhat.erb", "ext/files/puppetdb.redhat.init"
erb "ext/templates/puppetdb_default.erb", "ext/files/puppetdb.default"
erb "ext/templates/puppetdb.spec.erb", "ext/files/#{@name}.spec"
end
desc "Install PuppetDB (DESTDIR and PE_BUILD optional arguments)"
task :install => [ JAR_FILE ] do
unless File.exists?("ext/files/config.ini")
Rake::Task[:template].invoke
end
require 'facter'
osfamily = Facter.value(:osfamily).downcase
mkdir_p "#{DESTDIR}/#{@install_dir}"
mkdir_p "#{DESTDIR}/#{@config_dir}"
mkdir_p "#{DESTDIR}/#{@config_dir}/.."
mkdir_p "#{DESTDIR}/#{@log_dir}"
mkdir_p "#{DESTDIR}/etc/init.d/"
mkdir_p "#{DESTDIR}/#{@lib_dir}"
mkdir_p "#{DESTDIR}/#{@sbin_dir}"
mkdir_p "#{DESTDIR}/etc/logrotate.d/"
ln_sf @config_dir, "#{DESTDIR}/#{@lib_dir}/config"
ln_sf @log_dir, "#{DESTDIR}/#{@install_dir}/log"
if PE_BUILD == false or PE_BUILD == nil or PE_BUILD == ''
mkdir_p "#{DESTDIR}/var/lib/puppetdb/state"
mkdir_p "#{DESTDIR}/var/lib/puppetdb/db"
mkdir_p "#{DESTDIR}/var/lib/puppetdb/mq"
ln_sf "#{@link}/state", "#{DESTDIR}#{@lib_dir}/state"
ln_sf "#{@link}/db", "#{DESTDIR}#{@lib_dir}/db"
ln_sf "#{@link}/mq", "#{DESTDIR}#{@lib_dir}/mq"
mkdir_p "#{DESTDIR}#/etc/puppetdb"
else
mkdir_p "#{DESTDIR}#{@lib_dir}/state"
mkdir_p "#{DESTDIR}#{@lib_dir}/db"
mkdir_p "#{DESTDIR}#{@lib_dir}/mq"
mkdir_p "#{DESTDIR}#/etc/puppetlabs/puppetdb"
end
cp_p JAR_FILE, "#{DESTDIR}/#{@install_dir}"
cp_pr "ext/files/config.ini", "#{DESTDIR}/#{@config_dir}"
cp_pr "ext/files/database.ini", "#{DESTDIR}/#{@config_dir}"
cp_pr "ext/files/jetty.ini", "#{DESTDIR}/#{@config_dir}"
cp_pr "ext/files/repl.ini", "#{DESTDIR}/#{@config_dir}"
cp_pr "ext/files/puppetdb.logrotate", "#{DESTDIR}/etc/logrotate.d/#{@name}"
cp_pr "ext/files/log4j.properties", "#{DESTDIR}/#{@config_dir}/.."
cp_pr "ext/files/puppetdb-ssl-setup", "#{DESTDIR}/#{@sbin_dir}"
# figure out which init script to install based on facter
if osfamily.downcase == "RedHat".downcase
mkdir_p "#{DESTDIR}/etc/sysconfig"
mkdir_p "#{DESTDIR}/etc/rc.d/init.d/"
cp_p "ext/files/puppetdb.default", "#{DESTDIR}/etc/sysconfig/#{@name}"
cp_p "ext/files/puppetdb.redhat.init", "#{DESTDIR}/etc/rc.d/init.d/#{@name}"
chmod 0755, "#{DESTDIR}/etc/rc.d/init.d/#{@name}"
else
mkdir_p "#{DESTDIR}/etc/default"
cp_p "ext/files/puppetdb.default", "#{DESTDIR}/etc/default/#{@name}"
cp_pr "ext/files/#{@name}.debian.init", "#{DESTDIR}/etc/init.d/#{@name}"
chmod 0755, "#{DESTDIR}/etc/init.d/#{@name}"
end
chmod 0750, "#{DESTDIR}/#{@config_dir}"
chmod 0640, "#{DESTDIR}/#{@config_dir}/../log4j.properties"
chmod 0700, "#{DESTDIR}/#{@sbin_dir}/puppetdb-ssl-setup"
end
desc "Install the terminus components onto an existing puppet setup"
task :terminus do
mkdir_p "#{DESTDIR}#{@plibdir}/puppet/indirector"
cp_pr FileList["ext/master/lib/puppet/*"], "#{DESTDIR}#{@plibdir}/puppet/"
#TODO Fix up specs when the specs ship with the puppet packages
end
desc "Build a Source RPM for puppetdb"
task :srpm => [ :package ] do
%x{which rpmbuild}
if $? != 0
puts "rpmbuild command not found...exiting"
exit 1
end
temp = `mktemp -d -t tmpXXXXXX`.strip
RPM_DEFINE="--define \"%dist .el5\" --define \"%_topdir #{temp}\" "
RPM_OLD_VERSION='--define "_source_filedigest_algorithm 1" --define "_binary_filedigest_algorithm 1" \
--define "_binary_payload w9.gzdio" --define "_source_payload w9.gzdio" \
--define "_default_patch_fuzz 2"'
args = RPM_DEFINE + ' ' + RPM_OLD_VERSION
mkdir_p temp
mkdir_p 'pkg/rpm'
mkdir_p "#{temp}/SOURCES"
mkdir_p "#{temp}/SPECS"
cp_p "pkg/puppetdb-#{@version}.tar.gz", "#{temp}/SOURCES"
cp_p "ext/files/#{@name}.spec", "#{temp}/SPECS"
sh "rpmbuild #{args} -bs --nodeps #{temp}/SPECS/#{@name}.spec"
output = `ls #{temp}/SRPMS/*rpm`
mv FileList["#{temp}/SRPMS/*rpm"], "pkg/rpm"
rm_rf temp
puts
puts "Wrote #{`pwd`.strip}/pkg/rpm/#{output.split('/')[-1]}"
end
desc "Build deb package"
task :deb => [ :package ] do
temp = `mktemp -d -t tmpXXXXXX`.strip
mkdir_p temp
cp_p "pkg/puppetdb-#{@version}.tar.gz", "#{temp}"
sh "cd #{temp}; tar -z -x -f #{temp}/puppetdb-#{version}.tar.gz"
mv "#{temp}/puppetdb-#{@version}.tar.gz", "#{temp}/#{@name}_#{@version}.orig.tar.gz"
sh "cd #{temp}/puppetdb-#{@version}; debuild --no-lintian -uc -us"
mkdir_p "pkg/deb"
rm_rf "#{temp}/puppetdb-#{@version}"
mv FileList["#{temp}/*"], "pkg/deb"
rm_rf temp
puts
puts "Wrote debian package output to #{`pwd`.strip}/pkg/deb"
end
namespace :package do
desc "Create source tarball"
task :tar => [ :package ]
desc "Create source rpm for rebuild in a tool such as mock"
task :srpm => [ :srpm ]
desc "Create debian package"
task :deb => [ :deb ]
end