Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First pass at rake tasks

  • Loading branch information...
commit d9bc1c115d2f35a5c009bbb98ae1baff179c9709 1 parent 577fe06
@erikogan erikogan authored
View
1  Rakefile
@@ -36,6 +36,7 @@ require 'build/cxx_tests'
require 'build/ruby_tests'
require 'build/integration_tests'
require 'build/misc'
+require 'build/rpm'
#### Default tasks
View
94 build/rpm.rb
@@ -0,0 +1,94 @@
+# Phusion Passenger - http://www.modrails.com/
+# Copyright (C) 2010 Phusion
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+require 'phusion_passenger'
+require 'phusion_passenger/abstract_installer'
+
+namespace :package do
+ @sources_dir = nil
+ @verbosity = 0
+
+ def sources_dir
+ if !@sources_dir
+ @sources_dir = `rpm -E '%{_sourcedir}'`.strip
+ else
+ @sources_dir
+ end
+ end
+
+ def noisy_system(*args)
+ puts args.join ' ' if @verbosity
+ system(*args)
+ end
+
+ def create_tarball(verbosity = 0)
+ working_dir = "/tmp/#{`whoami`.strip}-passenger-rpm-#{Process.pid}"
+ sub_dir = "passenger-#{PhusionPassenger::VERSION_STRING}"
+ FileUtils.rm_rf(working_dir, :verbose => verbosity > 0)
+ begin
+ FileUtils.mkdir_p("#{working_dir}/#{sub_dir}", :verbose => verbosity > 0)
+ FileUtils.cp_r('.', "#{working_dir}/#{sub_dir}", :verbose => verbosity > 0)
+ noisy_system('tar', "c#{verbosity >= 2 ? 'v' : ''}", "-C", working_dir, '-f', "#{sources_dir}/#{sub_dir}.tar.gz", sub_dir)
+ ensure
+ FileUtils.rm_rf("#{working_dir}", :verbose => verbosity > 0)
+ end
+ end
+
+ def test_setup(*args)
+ abort "Mock setup failed, see above for details" unless
+ noisy_system('./rpm/release/mocksetup-first.sh', *args)
+ NginxFetch.new.fetch(sources_dir)
+ end
+
+ desc "Package the current release into a set of RPMs"
+ task 'rpm' => :rpm_verbosity do
+ test_setup
+ create_tarball(@verbosity)
+ # Add a single -v for some feedback
+ noisy_system(*(%w{./rpm/release/build.rb --single} + @build_verbosity))
+ end
+
+ desc "Build a Yum repository for the current release"
+ task 'yum' => :rpm_verbosity do
+ test_setup('--need-createrepo')
+ create_tarball(@verbosity)
+ # Add a single -v for some feedback
+ noisy_system(*(%w{./rpm/release/build.rb --stage-dir=yum-repo --extra-packages=release/mock-repo} + @build_verbosity))
+ Dir["yum-repo/{fedora,rhel}/*/{i386,x86_64}"].each do |dir|
+ noisy_system('createrepo', dir)
+ end
+ end
+
+ task 'rpm_verbosity' do
+ if ENV['verbosity']
+ if ENV['verbosity'] =~ /(true|yes|on)/i
+ @verbosity = 1
+ else
+ @verbosity = ENV['verbosity'].to_i
+ @build_verbosity = %w{-v} * (@verbosity == 0 ? 1 : @verbosity)
+ end
+ end
+ end
+end
+
+class NginxFetch < PhusionPassenger::AbstractInstaller
+
+ def fetch(dir)
+ tarball = "nginx-#{PREFERRED_NGINX_VERSION}.tar.gz"
+ return true if File.exists?("#{dir}/#{tarball}")
+ download("http://sysoev.ru/nginx/#{tarball}", "#{dir}/#{tarball}")
+ end
+end
View
8 rpm/passenger.spec
@@ -9,8 +9,12 @@
# do not remove the URL above.)
%define gemname passenger
-%define passenger_version 3.0.0
-%define passenger_release 11%{?dist}
+%if %{?passenger_version:0}%{?!passenger_version:1}
+ %define passenger_version 3.0.0
+%endif
+%if %{?passenger_release:0}%{?!passenger_release:1}
+ %define passenger_release 11%{?dist}
+%endif
%define passenger_epoch 1
%define nginx_version 0.8.53
View
2  rpm/release/build.rb
@@ -39,7 +39,7 @@
@can_build = @can_build[rpmarch.to_s == '' ? 'x86_64' : rpmarch]
@can_build.push rpmarch
-bindir=File.dirname($0)
+bindir=File.dirname(File.expand_path __FILE__)
configs = Dir["#{mock_etc_dir}/{#{CFGLIMIT.join ','}}*"].map {|f| f.gsub(%r{.*/([^.]*).cfg}, '\1')}
View
80 rpm/release/mocksetup-first.sh
@@ -0,0 +1,80 @@
+#!/bin/bash -e
+
+declare -a required_packages=(mock)
+if grep -iq fedora /etc/redhat-release ; then
+ # fedora-packager has rpmbuild-md5 for the SRPM
+ required_packages=( ${required_packages[@]} fedora-packager )
+else
+ required_packages=( ${required_packages[@]} rpm-build )
+fi
+
+if [ "$1" == '--need-createrepo' ] ; then
+ shift
+ required_packages=( ${required_packages[@]} createrepo )
+fi
+
+repo=${1:-/var/lib/mock/passenger-build-repo}
+etc=${2:-/etc/mock}
+
+if [ "$(id -u)" == "0" ]; then
+ cat <<EOF >&2
+It is a very bad idea to run this build as root.
+Use a less-privileged user. If that user is not a sudoer, you may need to run
+a few commands as root before the first run. (Those commands will be determined
+the first time through)
+EOF
+ exit 1
+fi
+
+mock_installed=`rpm -q mock | grep -v 'not installed' | wc -l`
+cfg_count=`ls -1 $etc/passenger-* 2>/dev/null | wc -l`
+in_mock_group=`groups | grep mock | wc -l`
+
+# Fedora has a utility to do this, but I don't know if RHEL does, plus it requires another package install, just do it by hand
+mkdir -p `rpm -E '%{_topdir}'`/{SOURCES,SPECS,SRPMS,RPMS}
+
+if [[ ( $cfg_count == 0 && ! -w $etc ) || ! ( -d $etc || -w $etc/.. ) || ! ( -w $repo || -w $repo/.. ) ]] ; then
+ run_setup=1
+fi
+
+declare -a yum_pkgs
+
+for pkg in "${required_packages[@]}"
+do
+ if [ `rpm -q $pkg | grep -v 'not installed' | wc -l` -eq 0 ] ; then
+ yum_pkgs=(${yum_pkgs[@]} $pkg)
+ fi
+done
+
+if [[ "$run_setup" = "1" || ! $in_mock_group == 1 || ${#yum_pkgs[@]} != 0 ]] ; then
+ echo "There is some setup required before building packages."
+ echo "We will run sudo to do the following:"
+
+ if [[ ${#yum_pkgs[@]} != 0 ]] ; then
+ echo " # yum -y install ${yum_pkgs[@]}"
+ fi
+
+ if [[ ! "$in_mock_group" == "1" ]] ; then
+ echo " # usermod -a -G mock $USER"
+ echo " (add you to the mock group, you will need to log back in for this to take effect)"
+ fi
+
+ if [[ "$run_setup" == "1" ]] ; then
+ echo " # `dirname $0`/mocksetup.sh"
+ echo " (sets up the dependencies for mock)"
+ fi
+ echo
+ echo "Hit return to continue, ^C to cancel"
+ read
+
+ if [[ ! $mock_installed == 1 || ! $createrepo_installed == 1 ]] ; then
+ sudo yum -y install $yum_pkgs
+ fi
+ if [[ ! "$in_mock_group" == "1" ]] ; then
+ sudo usermod -a -G mock $USER
+ fi
+ if [[ "$run_setup" == "1" ]] ; then
+ sudo `dirname $0`/mocksetup.sh $repo $etc
+ fi
+fi
+
Please sign in to comment.
Something went wrong with that request. Please try again.