From a58f3e04bf9328053a532e7498915da127930e7f Mon Sep 17 00:00:00 2001 From: Michael Stahnke Date: Thu, 14 Jul 2011 14:24:03 -0700 Subject: [PATCH 1/2] (#6840) Remove need for VERSION file in puppet-dashboard Instead of always relying on the VERSION file being present, we now first test to see if it is, then fall back to using the output of git-describe to determine which version of the Dashboard we are running. Also, instead of just linking to the puppet-dashboard project on GitHub, we now link to the CHANGELOG file for the version we are running. Signed-off-by: Michael Stahnke Signed-off-by: Jacob Helwig --- app/views/shared/_global_nav.html.haml | 2 +- config/initializers/app_version_init.rb | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/shared/_global_nav.html.haml b/app/views/shared/_global_nav.html.haml index 35834fbc0..2ceadb6e4 100644 --- a/app/views/shared/_global_nav.html.haml +++ b/app/views/shared/_global_nav.html.haml @@ -6,7 +6,7 @@ - else %a{:href => root_path, :id => "logo", :style => "text-indent: -9000px;"} Puppet Dashboard %li{:class => active_if(request.url == release_notes_url)} - = link_to "v#{APP_VERSION}", 'https://github.com/puppetlabs/puppet-dashboard' + = link_to APP_VERSION, "https://github.com/puppetlabs/puppet-dashboard/blob/#{APP_VERSION.sub(/.*?g([0-9a-f]*)/, "\\1")}/CHANGELOG" %li » %li{:class => active_if(request.url == root_url)} = link_to "Home", root_path diff --git a/config/initializers/app_version_init.rb b/config/initializers/app_version_init.rb index 6664916df..df49f0e46 100644 --- a/config/initializers/app_version_init.rb +++ b/config/initializers/app_version_init.rb @@ -1,3 +1,19 @@ # Get the Dashboard version number. +# +# Any officially released package or tarball of dashboard +# will have a VERSION file that is generated at tarball +# build time. +# +# This allows for the APP_VERSION to be determined by git, so +# developers can run out of master after a git checkout. +def get_app_version + if File.exists?(Rails.root.join('VERSION')) + return File.read(Rails.root.join('VERSION')).strip + elsif File.directory?(Rails.root.join('.git')) + return `cd #{Rails.root}; git describe`.strip! rescue 'unknown' + end -APP_VERSION = File.read(Rails.root.join('VERSION')).strip.sub(/^v/, '') + 'unknown' +end + +APP_VERSION = get_app_version From 82eeea75b57d4ddc74f0e506a336d5ca0d11d6b0 Mon Sep 17 00:00:00 2001 From: Michael Stahnke Date: Thu, 14 Jul 2011 14:35:25 -0700 Subject: [PATCH 2/2] (#7567) Refactor dashboard packaging to allow for nightly builds We now allow for builds out of master that utilizes git-describe for versioning. The generation of the tarball or package will create a VERSION file with the proper contents. The package/tarball will also use erb to substitute versions, dates and other metadata into the Red Hat spec or Debian changelog. The Debian package also changed to model more the builds from PE. This means a newer rules configuration and the addition of the rmshebang script to comply with Debian packaging guidelines. The package:deb, package:rpm, and package:srpm rake tasks now use the tarball generated from the package:tar task, which means that the spec, changelog, and other packaging inputs are generated from their erb templates. Signed-off-by: Michael Stahnke --- .gitignore | 2 + VERSION | 1 - ext/packaging/debian/cl.erb | 6 + ext/packaging/debian/install | 1 - ext/packaging/debian/rmshebang.sh | 17 ++ ext/packaging/debian/rules | 72 +++-- ...shboard.spec => puppet-dashboard.spec.erb} | 23 +- lib/tasks/package.rake | 260 +++++++++--------- 8 files changed, 218 insertions(+), 164 deletions(-) delete mode 100644 VERSION create mode 100644 ext/packaging/debian/cl.erb create mode 100644 ext/packaging/debian/rmshebang.sh rename ext/packaging/redhat/{puppet-dashboard.spec => puppet-dashboard.spec.erb} (92%) diff --git a/.gitignore b/.gitignore index 09426dbe0..bec6be067 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ db/schema.rb db/migrate/*_plugin_*.rb config/installed_plugins *.rpm +pkg/* +VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 1573078f4..000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -v1.1.9 diff --git a/ext/packaging/debian/cl.erb b/ext/packaging/debian/cl.erb new file mode 100644 index 000000000..eec523ec9 --- /dev/null +++ b/ext/packaging/debian/cl.erb @@ -0,0 +1,6 @@ +puppet-dashboard (<%= version %>-1) intrepid jaunty karmic lucid meerkat narwhal natty lenny squeeze; urgency=low + + * build at version <%= version %> + + -- Michael Stahnke <%= dt %> + diff --git a/ext/packaging/debian/install b/ext/packaging/debian/install index a07ee28c8..b986703e3 100644 --- a/ext/packaging/debian/install +++ b/ext/packaging/debian/install @@ -5,7 +5,6 @@ db usr/share/puppet-dashboard ext usr/share/puppet-dashboard lib usr/share/puppet-dashboard public usr/share/puppet-dashboard -VERSION usr/share/puppet-dashboard CHANGELOG usr/share/puppet-dashboard COPYING usr/share/puppet-dashboard LICENSE usr/share/puppet-dashboard diff --git a/ext/packaging/debian/rmshebang.sh b/ext/packaging/debian/rmshebang.sh new file mode 100644 index 000000000..ec6238805 --- /dev/null +++ b/ext/packaging/debian/rmshebang.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +for target_dir in $@ +do + for f in `find "$target_dir" -type f 2>/dev/null` + do + sed -e '1,1{ + /^#!/d + }' < $f > $f.tmp + if ! cmp $f $f.tmp >/dev/null + then + mv -f $f.tmp $f + else + rm -f $f.tmp + fi + done +done diff --git a/ext/packaging/debian/rules b/ext/packaging/debian/rules index 173959d7c..82534f078 100755 --- a/ext/packaging/debian/rules +++ b/ext/packaging/debian/rules @@ -1,32 +1,48 @@ #!/usr/bin/make -f -# -*- makefile -*- -# Uncomment these fllowing lines to display lots of debugging information during the build process: -export DH_VERBOSE=1 -export DH_OPTIONS=-v +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/rules/buildcore.mk -%: - dh $@ +ruby_ver = 1.8 -override_dh_install: - install -d debian/puppet-dashboard/etc/puppet-dashboard - install -d debian/puppet-dashboard/usr/share/puppet-dashboard - install -d debian/puppet-dashboard/usr/share/doc/puppet-dashboard/examples - cp -r app bin config db ext lib public script spec vendor VERSION CHANGELOG COPYING LICENSE README.markdown README_PACKAGES.markdown RELEASE_NOTES.md Rakefile debian/puppet-dashboard/usr/share/puppet-dashboard/ - install config/database.yml.example debian/puppet-dashboard/etc/puppet-dashboard/database.yml - install config/database.yml.example debian/puppet-dashboard/usr/share/doc/puppet-dashboard/examples/database.yml.example - # Clean up the "extra" license files - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/config/database.yml.example - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/doc/README_FOR_APP - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/plugins/*/*LICENSE - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/plugins/*/License.txt - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/plugins/*/COPYING - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/gems/*/COPYING - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/gems/*/*LICENSE - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/gems/*/License.txt - rm -f debian/puppet-dashboard/usr/share/puppet-dashboard/vendor/rails/*/*LICENSE - # ...and other various files - rm -f debian/puppet-dashboard/.gems - rm -f debian/puppet-dashboard/.autotest - find debian/puppet-dashboard -name '.gitignore' -type f | xargs rm -f - find debian/puppet-dashboard -name '.git' -type d | xargs rm -rf +binary-install/puppet-dashboard:: + mkdir -p $(CURDIR)/debian/$(cdbs_curpkg)/etc/puppet-dashboard + mkdir -p $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard + mkdir -p $(CURDIR)/debian/$(cdbs_curpkg)/var/$(cdbs_curpkg)/tmp + mkdir -p $(CURDIR)/debian/$(cdbs_curpkg)/var/log/puppet-dashboard + cp -r app \ + bin \ + config \ + db \ + ext \ + lib \ + Rakefile \ + script \ + spec \ + vendor \ + RELEASE_NOTES.md \ + $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard + cp $(CURDIR)/config/database.yml.example $(CURDIR)/debian/$(cdbs_curpkg)/etc/puppet-dashboard/database.yml + cp -r $(CURDIR)/public $(CURDIR)/debian/$(cdbs_curpkg)/var/$(cdbs_curpkg) + chmod -R a+rx $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/script + rm -rf $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/ext/packaging + # Clean up the "extra" files + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/config/database.yml.example + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/plugins/*/*LICENSE + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/plugins/*/License.txt + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/gems/*/COPYING + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/gems/*/*LICENSE + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/gems/*/License.txt + rm -f $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor/rails/*/*LICENSE + find $(CURDIR)/debian/$(cdbs_curpkg) -name .gitignore -exec rm {} \; + find $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor -name LICENSE -exec rm {} \; + find $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor -name MIT-LICENSE -exec rm {} \; + find $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor -type f -exec chmod a-x {} \; + find $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/app -type f -exec chmod a-x {} \; + find $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/spec -type f -exec chmod a-x {} \; + # Fixup shebang lines + bash $(CURDIR)/debian/rmshebang.sh \ + $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/lib \ + $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/app \ + $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/spec \ + $(CURDIR)/debian/$(cdbs_curpkg)/usr/share/puppet-dashboard/vendor diff --git a/ext/packaging/redhat/puppet-dashboard.spec b/ext/packaging/redhat/puppet-dashboard.spec.erb similarity index 92% rename from ext/packaging/redhat/puppet-dashboard.spec rename to ext/packaging/redhat/puppet-dashboard.spec.erb index cf68f5c7a..a2e9bf4e8 100644 --- a/ext/packaging/redhat/puppet-dashboard.spec +++ b/ext/packaging/redhat/puppet-dashboard.spec.erb @@ -1,15 +1,18 @@ %global confdir ext/packaging/redhat %global initrddir /etc/rc.d/init.d +# VERSION is subbed out during rake srpm process +%global realversion <%= version %> +%define rpmversion %(echo %{realversion} | sed -e 's/-/_/g') Name: puppet-dashboard -Version: 1.1.9 -Release: 2%{?dist} +Version: %{rpmversion} +Release: <%= release -%>%{?dist} Summary: Systems Management web application Group: Applications/System # Remember to verify this License: GPLv2 URL: http://www.puppetlabs.com -Source0: http://yum.puppetlabs.com/sources/%{name}-%{version}.tar.gz +Source0: http://yum.puppetlabs.com/sources/%{name}-%{realversion}.tar.gz BuildArch: noarch Requires: ruby(abi) = 1.8, rubygems, ruby-mysql Requires: ruby > 1.8.7, rubygem(rake) @@ -33,7 +36,7 @@ getent passwd puppet-dashboard > /dev/null || \ exit 0 %prep -%setup -q +%setup -q -n %{name}-%{realversion} %build @@ -69,12 +72,12 @@ rm timestamp # Put logs in /var/log and symlink in /usr/share (FHS work) #mkdir -p $RPM_BUILD_ROOT/var/log/%{name} -#if $(stat $RPM_BUILD_ROOT/%{_datadir}/%{name}/log/*) ; then +#if $(stat $RPM_BUILD_ROOT/%{_datadir}/%{name}/log/*) ; then # rsync -avx $RPM_BUILD_ROOT/%{_datadir}/%{name}/log/* $RPM_BUILD_ROOT/var/log/%{name} -#fi +#fi #rm -rf $RPM_BUILD_ROOT/%{_datadir}/%{name}/log #ls -l $RPM_BUILD_ROOT/%{_datadir}/%{name} -#cd $RPM_BUILD_ROOT/var/log +#cd $RPM_BUILD_ROOT/var/log #ln -sf %{name} ../..%{_datadir}/%{name}/log @@ -132,9 +135,12 @@ fi #%attr(-,puppet-dashboard,puppet-dashboard) %dir /var/log/%{name} %changelog +* <%= spec_date %> Michael Stahnke - <%= rpmversion %>-<%= release %> +- Build for <%= version %> + * Mon Jul 04 2011 Michael Stahnke - 1.1.9-2 - Updating spec to fix some rpmlint issues -- Began work on FHS issues, but haven't completed (commented out) +- Began work on FHS issues, but have not completed (commented out) - Adding a spool directory * Thu Jun 30 2011 Michael Stahnke - 1.1.9-1 @@ -184,4 +190,3 @@ fi * Thu Mar 26 2010 James Turnbull - 1.0.0-1 - Initial release. - diff --git a/lib/tasks/package.rake b/lib/tasks/package.rake index df129ab9a..ee3631feb 100644 --- a/lib/tasks/package.rake +++ b/lib/tasks/package.rake @@ -1,19 +1,98 @@ +require 'erb' + +def get_version + `git describe`.strip +end + +def get_temp + `mktemp -d`.strip +end + +def get_name + 'puppet-dashboard' +end + +def add_version_file(path) + sh "echo #{get_version} > #{path}/VERSION" +end + +def update_redhat_spec_file(base) + name = get_name + spec_date = Time.now.strftime("%a %b %d %Y") + release = ENV['RELEASE'] ||= "1" + version = get_version + rpmversion = version.gsub('-', '_') + specfile = File.join(base, 'ext', 'packaging', 'redhat', "#{name}.spec") + erbfile = File.join(base, 'ext', 'packaging', 'redhat', "#{name}.spec.erb") + template = IO.read(erbfile) + message = ERB.new(template, 0, "-") + output = message.result(binding) + holder = `mktemp`.strip! + File.open(holder, 'w') {|f| f.write(output) } + mv holder , specfile + rm_f erbfile +end + +def update_debian_changelog(base) + name = get_name + dt = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z") + version = get_version + version.gsub!('v', '') + deb_changelog = File.join(base, 'ext', 'packaging', 'debian', 'changelog') + erbfile = File.join(base, 'ext', 'packaging', 'debian', 'cl.erb') + template = IO.read(erbfile) + message = ERB.new(template, 0, "-") + output = message.result(binding) + holder = `mktemp`.strip! + sh "echo -n \"#{output}\" | cat - #{deb_changelog} > #{holder}" + mv holder, deb_changelog + rm_f erbfile +end + +def prep_rpm_builds + name=get_name + version=get_version + temp=`mktemp -d`.strip! + raise "No /usr/bin/rpmbuild found!" unless File.exists? '/usr/bin/rpmbuild' + dirs = [ 'BUILD', 'SPECS', 'SOURCES', 'RPMS', 'SRPMS' ] + dirs.each do |d| + FileUtils.mkdir_p "#{temp}//#{d}" + end + rpm_defines = " --define \"_specdir #{temp}/SPECS\" --define \"_rpmdir #{temp}/RPMS\" --define \"_sourcedir #{temp}/SOURCES\" --define \" _srcrpmdir #{temp}/SRPMS\" --define \"_builddir #{temp}/BUILD\"" + sh "tar zxvf pkg/tar/#{name}-#{version}.tar.gz --no-anchored ext/packaging/redhat/#{name}.spec" + mv "#{name}-#{version}/ext/packaging/redhat/#{name}.spec", "#{temp}/SPECS" + rm_rf "#{name}-#{version}" + sh "cp pkg/tar/*.tar.gz #{temp}/SOURCES" + return [ temp, rpm_defines ] +end + namespace :package do desc "Create .deb from this git repository, set KEY_ID=your_key to use a specific key or UNSIGNED=1 to leave unsigned." - task :deb => :build_environment do - build_dir = create_workspace('deb') - - cd build_dir do - cp_r File.join('ext', 'packaging', 'debian'), '.' - cmd = 'dpkg-buildpackage -a' - cmd << ' -us -uc' if ENV['UNSIGNED'] == '1' - cmd << " -k#{ENV['KEY_ID']}" if ENV['KEY_ID'] - - begin - sh cmd - puts "** Created package: "+ latest_file(File.expand_path(File.join(RAILS_ROOT, 'tmp', 'packages', 'deb', '*.deb'))) - rescue - puts <<-HERE + task :deb => :tar do + name = get_name + version = get_version + dt = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z") + temp=`mktemp -d`.strip! + base="#{temp}/#{name}-#{version}" + sh "cp pkg/tar/#{name}-#{version}.tar.gz #{temp}" + cd temp do + sh "tar zxf *.tar.gz" + cd "#{name}-#{version}" do + mv File.join('ext', 'packaging', 'debian'), '.' + cmd = 'dpkg-buildpackage -a' + cmd << ' -us -uc' if ENV['UNSIGNED'] == '1' + cmd << " -k#{ENV['KEY_ID']}" if ENV['KEY_ID'] + begin + sh cmd + dest_dir = File.join(RAILS_ROOT, 'pkg', 'deb') + mkdir_p dest_dir + cp latest_file(File.join(temp, '*.deb')), dest_dir + cp latest_file(File.join(temp, '*.dsc')), dest_dir + cp latest_file(File.join(temp, '*.changes')), dest_dir + puts + puts "** Created package: "+ latest_file(File.expand_path(File.join(RAILS_ROOT, 'pkg', 'deb', '*.deb'))) + rescue + puts <<-HERE !! Building the .deb failed! !! Perhaps you want to run: @@ -24,113 +103,60 @@ namespace :package do rake package:deb KEY_ID=4BD6EC30 rake package:deb KEY_ID=me@example.com - HERE + HERE + end end end + rm_rf temp end desc "Create srpm from this git repository (unsigned)" - task :srpm => :tar do - name='puppet-dashboard' - temp=`mktemp -d`.strip! - pwd=`pwd`.strip! - spec_file="ext/packaging/redhat/#{name}.spec" - rpm_defines = " --define \"_specdir #{temp}/SPECS\" --define \"_rpmdir #{temp}/RPMS\" --define \"_sourcedir #{temp}/SOURCES\" --define \" _srcrpmdir #{temp}/SRPMS\" --define \"_builddir #{temp}/BUILD\"" - sh " [ -f /usr/bin/rpmbuild ] " - dirs = [ 'BUILD', 'SPECS', 'SOURCES', 'RPMS', 'SRPMS' ] - dirs.each do |d| - FileUtils.mkdir_p "#{temp}//#{d}" - end - sh "mv tmp/packages/tar/*.tar.gz #{temp}/SOURCES" - sh "cp #{spec_file} #{temp}/SPECS" + task :srpm => :tar do + name = get_name + version = get_version + temp, rpm_defines = prep_rpm_builds sh "rpmbuild #{rpm_defines} -bs --nodeps #{temp}/SPECS/*.spec" - sh "mv -f #{temp}/SRPMS/* ." - sh "rm -rf #{temp}/BUILD #{temp}/SRPMS #{temp}/RPMS #{temp}/SPECS #{temp}/SOURCES" - sh "rm -rf #{temp}" + mkdir_p "#{RAILS_ROOT}/pkg/srpm" + sh "mv -f #{temp}/SRPMS/* pkg/srpm" + rm_rf temp + puts + puts "** Created package: "+ latest_file(File.expand_path(File.join(RAILS_ROOT, 'pkg', 'srpm', '*.rpm'))) end - desc "Create .rpm from this git repository, set UNSIGNED=1 to leave unsigned." - task :rpm => :build_environment do - unless File.exists?(File.expand_path('~/.rpmmacros')) - puts <<-HERE -!! You must setup a ~/.rpmmacros file. -!! You can do this by running: - - rake package:rpm:create_rpmmacros - - HERE - end - - version = File.open('VERSION', 'r').read.sub(/^v/, '').chomp - sh "git archive --format=tar --prefix=puppet-dashboard-#{version}/ HEAD | gzip > #{rpm_macro_value('_sourcedir')}/puppet-dashboard-#{version}.tar.gz" - cd File.expand_path(rpm_macro_value('_specdir')) do - cp File.join(RAILS_ROOT, 'ext', 'packaging', 'redhat', 'puppet-dashboard.spec'), 'puppet-dashboard.spec' - - cmd = 'rpmbuild -ba' - cmd << ' --sign' unless ENV['UNSIGNED'] == '1' - cmd << ' puppet-dashboard.spec' - - begin - sh cmd - puts "** Created package: "+ latest_file(File.expand_path(File.join(rpm_macro_value('_rpmdir'), 'noarch', 'puppet-dashboard*.rpm'))) - rescue - puts <<-HERE -!! Building the '.rpm's failed! -!! Perhaps you want to run: - - rake package:rpm UNSIGNED=1 - HERE - end - end + desc "Create .rpm from this git repository (unsigned)" + task :rpm => :srpm do + name = get_name + version = get_version + temp, rpm_defines = prep_rpm_builds + sh "rpmbuild #{rpm_defines} -ba #{temp}/SPECS/*.spec" + mkdir_p "#{RAILS_ROOT}/pkg/srpm" + mkdir_p "#{RAILS_ROOT}/pkg/rpm" + sh "mv -f #{temp}/SRPMS/* pkg/srpm" + sh "mv -f #{temp}/RPMS/*/*rpm pkg/rpm" + rm_rf temp + puts + puts "** Created package: "+ latest_file(File.expand_path(File.join(RAILS_ROOT, 'pkg', 'rpm', '*.rpm'))) end - namespace :rpm do - desc "Create ~/.rpmmacros and related directories" - task :create_rpmmacros do - rpmmacro_file = File.expand_path("~/.rpmmacros") - unless File.exists?(rpmmacro_file) - rpmmacro = " -%_topdir %(echo $HOME)/rpmbuild -%_builddir %{_topdir}/BUILD -%_rpmdir %{_topdir}/RPMS -%_sourcedir %{_topdir}/SOURCES -%_specdir %{_topdir}/SPECS -%_srcrpmdir %{_topdir}/SRPMS -%_buildrootdir %{_topdir}/BUILDROOT - -%buildroot %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch} -$RPM_BUILD_ROOT %{buildroot} -" - File.open(rpmmacro_file, "w") {|f| f.write(rpmmacro)} - end - - %w{_builddir _rpmdir _sourcedir _specdir _srcrpmdir _buildrootdir}.each do |dir| - sh %Q|mkdir -p #{rpm_macro_value(dir)}| - end - end - end desc "Create a release .tar.gz" - task :tar do - version = File.open('VERSION', 'r').read.sub(/^v/, '').chomp - work = File.expand_path(File.join(RAILS_ROOT, 'tmp', 'packages', 'tar')) - release_prefix = "puppet-dashboard-#{version}" - release_file = File.join work, "#{release_prefix}.tar.gz" - - mkdir_p work - if File.exists?(release_file) - puts <<-HERE -!! Release tar.gz file already exists: #{release_prefix}.tar.gz -!! Please move or remove this file before proceeding. - HERE - raise - end - - sh %Q{git archive --format=tar --prefix=#{release_prefix}/ HEAD | gzip > "#{release_file}"} - - puts <<-HERE -Saved release to: #{release_file} - HERE + task :tar => :build_environment do + name = get_name + rm_rf 'pkg/tar' + temp=`mktemp -d`.strip! + version = `git describe`.strip! + base = "#{temp}/#{name}-#{version}/" + mkdir_p base + sh "git checkout-index -af --prefix=#{base}" + add_version_file(base) + update_redhat_spec_file(base) + update_debian_changelog(base) + mkdir_p "pkg/tar" + sh "tar -C #{temp} -p -c -z -f #{temp}/#{name}-#{version}.tar.gz #{name}-#{version}" + mv "#{temp}/#{name}-#{version}.tar.gz", "#{RAILS_ROOT}/pkg/tar" + rm_rf temp + puts + puts "Tarball is #{RAILS_ROOT}/pkg/tar/#{name}-#{version}.tar.gz" end task :build_environment do @@ -150,26 +176,10 @@ Saved release to: #{release_file} end end - def create_workspace(package_type) - work = File.expand_path(File.join(RAILS_ROOT, 'tmp', 'packages', package_type)) - build = File.join(work, 'build') - - rm_rf work - mkdir_p work - - sh "git checkout-index -a -f --prefix=#{build}/" - - return build - end - # Return the file with the latest mtime matching the String filename glob (e.g. "foo/*.bar"). def latest_file(glob) require 'find' return FileList[glob].map{|path| [path, File.mtime(path)]}.sort_by(&:last).map(&:first).last end - # Resolve an RPM macro. - def rpm_macro_value(macro) - `rpmbuild -E '%#{macro}' #{File.join(RAILS_ROOT, 'ext', 'packaging', 'redhat', 'puppet-dashboard.spec')} 2> /dev/null`.chomp - end end