PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/puppetdb-git/Rakefile

https://bitbucket.org/kaendfinger/aur-mirror
Rakefile | 408 lines | 343 code | 49 blank | 16 comment | 28 complexity | 918f91504aab34d174dbf0e3cdd0d708 MD5 | raw file
Possible License(s): LGPL-2.0, Unlicense, AGPL-1.0, BitTorrent-1.0, EPL-1.0, GPL-3.0, BSD-3-Clause, GPL-2.0, MIT, CC-BY-SA-3.0, BSD-2-Clause, MPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, JSON, AGPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0, LGPL-2.1, ISC, CC-BY-3.0, WTFPL, 0BSD, CC0-1.0, LGPL-3.0, Cube, Apache-2.0
  1. require 'rake'
  2. require 'erb'
  3. require 'facter'
  4. if ENV['PE_BUILD'] and ENV['PE_BUILD'].downcase == 'true'
  5. @pe = TRUE
  6. ENV['PATH'] = "/opt/puppet/bin:" + ENV['PATH']
  7. else
  8. @pe = FALSE
  9. end
  10. # We only need the ruby major, minor versions
  11. @ruby_version = (ENV['RUBY_VER'] || Facter.value(:rubyversion))[0..2]
  12. unless @ruby_version == '1.8' or @ruby_version == '1.9'
  13. STDERR.puts "RUBY_VER needs to be 1.8 or 1.9"
  14. exit 1
  15. end
  16. PATH = ENV['PATH']
  17. DESTDIR= ENV['DESTDIR'] || ''
  18. def get_version
  19. if File.exists?('version')
  20. File.read('version').chomp
  21. elsif File.exists?('.git')
  22. %x{git describe}.chomp.gsub('-', '.').split('.')[0..3].join('.').gsub('v', '')
  23. else
  24. File.basename(pwd).split('-').last
  25. end
  26. end
  27. def get_debversion
  28. packager = @pe ? 'puppet' : 'puppetlabs'
  29. version = @version.match(/\d\.\d\.\d/)[0]
  30. if @version.include?('rc')
  31. return version + '-0.1' + @version.match(/rc\d+/)[0] + packager + get_debrelease
  32. else
  33. return version + "-1#{packager}" + get_debrelease
  34. end
  35. end
  36. def get_origversion
  37. @debversion.split('-')[0]
  38. end
  39. def get_rpmversion
  40. rpmversion = @version.match(/^([0-9\.]+)/)[1].chomp('.')
  41. end
  42. def get_debrelease
  43. ENV['RELEASE'] || "1"
  44. end
  45. def get_rpmrelease
  46. ENV['RELEASE'] ||
  47. if @version.include?("rc")
  48. "0.1" + @version.gsub('-', '_').match(/rc[0-9]+.*/)[0]
  49. else
  50. "1"
  51. end
  52. end
  53. def cp_pr(src, dest, options={})
  54. mandatory = {:preserve => true}
  55. cp_r(src, dest, options.merge(mandatory))
  56. end
  57. def cp_p(src, dest, options={})
  58. mandatory = {:preserve => true}
  59. cp(src, dest, options.merge(mandatory))
  60. end
  61. def ln_sfT(src, dest)
  62. `ln -sfT "#{src}" "#{dest}"`
  63. end
  64. @osfamily = (Facter.value(:osfamily) || "").downcase
  65. case @osfamily
  66. when /debian/
  67. @plibdir = @pe ? '/opt/puppet/lib/ruby/1.8' : '/usr/lib/ruby/vendor_ruby'
  68. when /redhat/
  69. @plibdir = @pe ? '/opt/puppet/lib/ruby/site_ruby/1.8' : ( @ruby_version == '1.8' ? '/usr/lib/ruby/site_ruby/1.8' : '/usr/share/ruby/vendor_ruby' )
  70. when /suse/
  71. @plibdir = @pe ? '/opt/puppet/lib/ruby/site_ruby/1.8' : nil
  72. when /linux/
  73. @plibdir = @pe ? '/opt/puppet/lib/ruby/site_ruby/1.8' : '/usr/lib/ruby/site_ruby/1.9.1/'
  74. end
  75. if @pe
  76. @install_dir = "/opt/puppet/share/puppetdb"
  77. @etc_dir = "/etc/puppetlabs/puppetdb"
  78. @config_dir = "/etc/puppetlabs/puppetdb/conf.d"
  79. @initscriptname = "/etc/init.d/pe-puppetdb"
  80. @log_dir = "/var/log/pe-puppetdb"
  81. @lib_dir = "/opt/puppet/share/puppetdb"
  82. @name ="pe-puppetdb"
  83. @sbin_dir = "/opt/puppet/sbin"
  84. @cows = 'lucid', 'squeeze', 'precise', 'wheezy'
  85. @pe_version = ENV['PE_VER'] || '2.7'
  86. else
  87. @install_dir = "/usr/share/puppetdb"
  88. @etc_dir = "/etc/puppetdb"
  89. @config_dir = "/etc/puppetdb/conf.d"
  90. @initscriptname = "/etc/init.d/puppetdb"
  91. @log_dir = "/var/log/puppetdb"
  92. @lib_dir = "/var/lib/puppetdb"
  93. @link = "/usr/share/puppetdb"
  94. @name = "puppetdb"
  95. @sbin_dir = "/usr/sbin"
  96. end
  97. @heap_dump_path = "#{@log_dir}/puppetdb-oom.hprof"
  98. @default_java_args = "-Xmx192m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=#{@heap_dump_path} "
  99. @version ||= get_version
  100. @debversion ||= get_debversion
  101. @origversion ||= get_origversion
  102. @rpmversion ||= get_rpmversion
  103. @rpmrelease ||= get_rpmrelease
  104. def erb(erbfile, outfile)
  105. template = File.read(erbfile)
  106. message = ERB.new(template, nil, "-")
  107. output = message.result(binding)
  108. File.open(outfile, 'w') { |f| f.write output }
  109. puts "Generated: #{outfile}"
  110. end
  111. JAR_FILE_V = "puppetdb-#{@version}-standalone.jar"
  112. JAR_FILE = "puppetdb.jar"
  113. task :default => [ :package ]
  114. desc "Build the uberjar"
  115. task :uberjar => [ ] do
  116. if `which lein`
  117. sh "lein uberjar"
  118. mv "target/#{JAR_FILE_V}", JAR_FILE
  119. else
  120. puts "You need lein on your system"
  121. exit 1
  122. end
  123. end
  124. desc "Create a source tar archive"
  125. task :package => [ :clobber, JAR_FILE, :template ] do
  126. temp = `mktemp -d -t tmpXXXXXX`.strip
  127. workdir = File.join(temp, "puppetdb-#{@version}")
  128. mkdir_p workdir
  129. FileList[ "ext", "*.md", JAR_FILE, "documentation", "Rakefile" ].each do |f|
  130. cp_pr f, workdir
  131. end
  132. # Lay down version file for later reading
  133. File.open(File.join(workdir,'version'), File::CREAT|File::TRUNC|File::RDWR, 0644) do |f|
  134. f.puts @version
  135. end
  136. mv "#{workdir}/ext/files/debian", workdir
  137. cp_pr "puppet", "#{workdir}/ext/master"
  138. mkdir_p "pkg"
  139. pkg_dir = File.expand_path(File.join(".", "pkg"))
  140. sh "cd #{temp}; tar --exclude=.gitignore -zcf #{pkg_dir}/puppetdb-#{@version}.tar.gz puppetdb-#{@version}"
  141. rm_rf temp
  142. puts
  143. puts "Wrote #{`pwd`.strip}/pkg/puppetdb-#{@version}"
  144. end
  145. file JAR_FILE do |t|
  146. Rake::Task[:uberjar].invoke
  147. end
  148. task :allclean => [ :clobber ]
  149. desc "Remove build artifacts (other than clojure (lein) builds)"
  150. task :clean do
  151. rm_rf FileList["ext/files", "pkg", "*.tar.gz"]
  152. end
  153. desc "Get rid of build artifacts including clojure (lein) builds"
  154. task :clobber => [ :clean ] do
  155. rm_rf FileList["puppetdb*jar"]
  156. end
  157. task :version do
  158. puts @version
  159. end
  160. file "ext/files/config.ini" => [ :template, JAR_FILE ] do
  161. end
  162. task :template => [ :clean ] do
  163. mkdir_p "ext/files/debian"
  164. # files for deb and rpm
  165. erb "ext/templates/log4j.properties.erb", "ext/files/log4j.properties"
  166. erb "ext/templates/config.ini.erb" , "ext/files/config.ini"
  167. erb "ext/templates/jetty.ini.erb", "ext/files/jetty.ini"
  168. erb "ext/templates/repl.ini.erb", "ext/files/repl.ini"
  169. erb "ext/templates/database.ini.erb", "ext/files/database.ini"
  170. erb "ext/templates/puppetdb-foreground.erb", "ext/files/puppetdb-foreground"
  171. chmod 0700, "ext/files/puppetdb-foreground"
  172. # files for deb
  173. erb "ext/templates/init_debian.erb", "ext/files/debian/#{@name}.init"
  174. erb "ext/templates/puppetdb_default.erb", "ext/files/debian/#{@name}.default"
  175. erb "ext/templates/deb/control.erb", "ext/files/debian/control"
  176. erb "ext/templates/deb/prerm.erb", "ext/files/debian/#{@name}.prerm"
  177. erb "ext/templates/deb/postrm.erb", "ext/files/debian/#{@name}.postrm"
  178. erb "ext/templates/deb/base.install.erb", "ext/files/debian/#{@name}.install"
  179. erb "ext/templates/deb/terminus.install.erb", "ext/files/debian/#{@name}-terminus.install"
  180. erb "ext/templates/deb/rules.erb", "ext/files/debian/rules"
  181. chmod 0755, "ext/files/debian/rules"
  182. erb "ext/templates/deb/changelog.erb", "ext/files/debian/changelog"
  183. erb "ext/templates/deb/terminus.postinst.erb", "ext/files/debian/#{@name}-terminus.postinst"
  184. erb "ext/templates/deb/preinst.erb", "ext/files/debian/#{@name}.preinst"
  185. erb "ext/templates/deb/postinst.erb", "ext/files/debian/#{@name}.postinst"
  186. erb "ext/templates/logrotate.erb", "ext/files/debian/#{@name}.logrotate"
  187. erb "ext/templates/init_debian.erb", "ext/files/#{@name}.debian.init"
  188. cp_pr FileList["ext/templates/deb/*"], "ext/files/debian"
  189. cp_pr "ext/templates/puppetdb-ssl-setup", "ext/files"
  190. chmod 0700, "ext/files/puppetdb-ssl-setup"
  191. rm_rf FileList["ext/files/debian/*.erb"]
  192. # files for rpm
  193. erb "ext/templates/logrotate.erb", "ext/files/puppetdb.logrotate"
  194. erb "ext/templates/init_redhat.erb", "ext/files/puppetdb.redhat.init"
  195. erb "ext/templates/puppetdb_default.erb", "ext/files/puppetdb.default"
  196. erb "ext/templates/puppetdb.spec.erb", "ext/files/#{@name}.spec"
  197. # developer utility files for redhat
  198. mkdir_p "ext/files/dev/redhat"
  199. erb "ext/templates/dev/redhat/redhat_dev_preinst.erb", "ext/files/dev/redhat/redhat_dev_preinst"
  200. erb "ext/templates/dev/redhat/redhat_dev_postinst.erb", "ext/files/dev/redhat/redhat_dev_postinst"
  201. end
  202. desc "Install PuppetDB (DESTDIR and PE_BUILD optional arguments)"
  203. task :install => [ JAR_FILE ] do
  204. unless File.exists?("ext/files/config.ini")
  205. Rake::Task[:template].invoke
  206. end
  207. require 'facter'
  208. raise "Oh damn. You need a newer facter or better facts. Facter version: #{Facter.version}" if Facter.value(:osfamily).nil?
  209. @osfamily = Facter.value(:osfamily).downcase
  210. mkdir_p "#{DESTDIR}/#{@install_dir}"
  211. mkdir_p "#{DESTDIR}/#{@config_dir}"
  212. mkdir_p "#{DESTDIR}/#{@config_dir}/.."
  213. mkdir_p "#{DESTDIR}/#{@log_dir}"
  214. mkdir_p "#{DESTDIR}/etc/init.d/"
  215. mkdir_p "#{DESTDIR}/#{@lib_dir}"
  216. mkdir_p "#{DESTDIR}/#{@sbin_dir}"
  217. mkdir_p "#{DESTDIR}/etc/logrotate.d/"
  218. ln_sfT @config_dir, "#{DESTDIR}/#{@lib_dir}/config"
  219. ln_sfT @log_dir, "#{DESTDIR}/#{@install_dir}/log"
  220. unless @pe
  221. mkdir_p "#{DESTDIR}/var/lib/puppetdb/state"
  222. mkdir_p "#{DESTDIR}/var/lib/puppetdb/db"
  223. mkdir_p "#{DESTDIR}/var/lib/puppetdb/mq"
  224. ln_sfT "#{@lib_dir}/state", "#{DESTDIR}#{@link}/state"
  225. ln_sfT "#{@lib_dir}/db", "#{DESTDIR}#{@link}/db"
  226. ln_sfT "#{@lib_dir}/mq", "#{DESTDIR}#{@link}/mq"
  227. mkdir_p "#{DESTDIR}#/etc/puppetdb"
  228. else
  229. mkdir_p "#{DESTDIR}#{@lib_dir}/state"
  230. mkdir_p "#{DESTDIR}#{@lib_dir}/db"
  231. mkdir_p "#{DESTDIR}#{@lib_dir}/mq"
  232. mkdir_p "#{DESTDIR}#/etc/puppetlabs/puppetdb"
  233. end
  234. cp_p JAR_FILE, "#{DESTDIR}/#{@install_dir}"
  235. cp_pr "ext/files/config.ini", "#{DESTDIR}/#{@config_dir}"
  236. cp_pr "ext/files/database.ini", "#{DESTDIR}/#{@config_dir}"
  237. cp_pr "ext/files/jetty.ini", "#{DESTDIR}/#{@config_dir}"
  238. cp_pr "ext/files/repl.ini", "#{DESTDIR}/#{@config_dir}"
  239. cp_pr "ext/files/puppetdb.logrotate", "#{DESTDIR}/etc/logrotate.d/#{@name}"
  240. cp_pr "ext/files/log4j.properties", "#{DESTDIR}/#{@config_dir}/.."
  241. cp_pr "ext/files/puppetdb-ssl-setup", "#{DESTDIR}/#{@sbin_dir}"
  242. cp_pr "ext/files/puppetdb-foreground", "#{DESTDIR}/#{@sbin_dir}"
  243. # figure out which init script to install based on facter
  244. if @osfamily == "redhat" || @osfamily == "suse"
  245. mkdir_p "#{DESTDIR}/etc/sysconfig"
  246. mkdir_p "#{DESTDIR}/etc/rc.d/init.d/"
  247. cp_p "ext/files/puppetdb.default", "#{DESTDIR}/etc/sysconfig/#{@name}"
  248. cp_p "ext/files/puppetdb.redhat.init", "#{DESTDIR}/etc/rc.d/init.d/#{@name}"
  249. chmod 0755, "#{DESTDIR}/etc/rc.d/init.d/#{@name}"
  250. elsif @osfamily == "debian"
  251. mkdir_p "#{DESTDIR}/etc/default"
  252. cp_p "ext/files/puppetdb.default", "#{DESTDIR}/etc/default/#{@name}"
  253. cp_pr "ext/files/#{@name}.debian.init", "#{DESTDIR}/etc/init.d/#{@name}"
  254. chmod 0755, "#{DESTDIR}/etc/init.d/#{@name}"
  255. elsif @osfamily == "linux"
  256. mkdir_p "#{DESTDIR}/etc/default"
  257. cp_p "ext/files/puppetdb.default", "#{DESTDIR}/etc/default/#{@name}"
  258. else
  259. raise "Unknown or unsupported osfamily: #{@osfamily}"
  260. end
  261. chmod 0750, "#{DESTDIR}/#{@config_dir}"
  262. chmod 0640, "#{DESTDIR}/#{@config_dir}/../log4j.properties"
  263. chmod 0700, "#{DESTDIR}/#{@sbin_dir}/puppetdb-ssl-setup"
  264. chmod 0700, "#{DESTDIR}/#{@sbin_dir}/puppetdb-foreground"
  265. end
  266. desc "INTERNAL USE ONLY: Install the terminus components from the puppetdb package tarball onto an existing puppet setup"
  267. task :terminus do
  268. mkdir_p "#{DESTDIR}#{@plibdir}/puppet/indirector"
  269. cp_pr FileList["ext/master/lib/puppet/*"], "#{DESTDIR}#{@plibdir}/puppet/"
  270. #TODO Fix up specs when the specs ship with the puppet packages
  271. end
  272. desc "Install the terminus components from puppetdb source tree onto an existing puppet setup"
  273. task :sourceterminus do
  274. mkdir_p "#{DESTDIR}#{@plibdir}/puppet/indirector"
  275. cp_pr FileList["puppet/lib/puppet/*"], "#{DESTDIR}#{@plibdir}/puppet/"
  276. end
  277. desc "Build a Source RPM for puppetdb"
  278. task :srpm => [ :package ] do
  279. %x{which rpmbuild}
  280. if $? != 0
  281. puts "rpmbuild command not found...exiting"
  282. exit 1
  283. end
  284. temp = `mktemp -d -t tmpXXXXXX`.strip
  285. RPM_DEFINE="--define \"%dist .el5\" --define \"%_topdir #{temp}\" "
  286. RPM_OLD_VERSION='--define "_source_filedigest_algorithm 1" --define "_binary_filedigest_algorithm 1" \
  287. --define "_binary_payload w9.gzdio" --define "_source_payload w9.gzdio" \
  288. --define "_default_patch_fuzz 2"'
  289. args = RPM_DEFINE + ' ' + RPM_OLD_VERSION
  290. mkdir_p temp
  291. mkdir_p 'pkg/rpm'
  292. mkdir_p "#{temp}/SOURCES"
  293. mkdir_p "#{temp}/SPECS"
  294. mkdir_p "#{temp}/SRPMS"
  295. cp_p "pkg/puppetdb-#{@version}.tar.gz", "#{temp}/SOURCES"
  296. cp_p "ext/files/#{@name}.spec", "#{temp}/SPECS"
  297. sh "rpmbuild #{args} -bs --nodeps #{temp}/SPECS/#{@name}.spec"
  298. output = `ls #{temp}/SRPMS/*rpm`
  299. mv FileList["#{temp}/SRPMS/*rpm"], "pkg/rpm"
  300. rm_rf temp
  301. puts
  302. puts "Wrote #{`pwd`.strip}/pkg/rpm/#{output.split('/')[-1]}"
  303. end
  304. desc "Build deb package"
  305. task :deb => [ :package ] do
  306. temp = `mktemp -d -t tmpXXXXXX`.strip
  307. mkdir_p temp
  308. cp_p "pkg/puppetdb-#{@version}.tar.gz", "#{temp}"
  309. sh "cd #{temp}; tar -z -x -f #{temp}/puppetdb-#{@version}.tar.gz"
  310. mv "#{temp}/puppetdb-#{@version}", "#{temp}/puppetdb-#{@debversion}"
  311. mv "#{temp}/puppetdb-#{@version}.tar.gz", "#{temp}/#{@name}_#{@origversion}.orig.tar.gz"
  312. cd "#{temp}/puppetdb-#{@debversion}" do
  313. if @pe
  314. @cows.each do |cow|
  315. mkdir "#{temp}/#{cow}"
  316. arch = ENV['ARCH'] || 'i386'
  317. # Because these are general purpose cows, we have to update them with PE repos
  318. # to ensure this build succeeds at dependency resolution
  319. sh "export DIST=#{cow} ARCH=#{arch} PE_VER=#{@pe_version} ; \
  320. sudo -E cowbuilder --update \
  321. --override-config \
  322. --basepath=/var/cache/pbuilder/base-#{cow}-#{arch}.cow \
  323. --dist #{cow} \
  324. --architecture #{arch}"
  325. sh "pdebuild --buildresult #{temp}/#{cow} \
  326. --pbuilder cowbuilder -- \
  327. --basepath /var/cache/pbuilder/base-#{cow}-#{arch}.cow/"
  328. end
  329. else
  330. sh 'debuild --no-lintian -uc -us'
  331. end
  332. end
  333. mkdir_p 'pkg/deb'
  334. rm_rf "#{temp}/puppetdb-#{@debversion}"
  335. mv FileList["#{temp}/*"], "pkg/deb"
  336. rm_rf temp
  337. puts
  338. puts "Wrote debian package output to #{`pwd`.strip}/pkg/deb"
  339. end
  340. namespace :package do
  341. desc "Create source tarball"
  342. task :tar => [ :package ]
  343. desc "Create source rpm for rebuild in a tool such as mock"
  344. task :srpm => [ :srpm ]
  345. desc "Create debian package"
  346. task :deb => [ :deb ]
  347. end
  348. namespace :test do
  349. desc "Build packages for testing"
  350. task :package do
  351. # TODO: I'm not proud of this. The contents of the shell script(s) that
  352. # we call here need to be reconciled with Moses' standardized packaging
  353. # stuff, and a lot of the contents should probably be ported over to
  354. # Ruby instead of just shipping the nasty scripts. However, this first step
  355. # at least gives us 1) VCS for this stuff, and 2) the ability to run
  356. # the two packaging builds in parallel.
  357. sh "sh ./ext/test/build_packages.sh"
  358. end
  359. end