Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial import

  • Loading branch information...
commit 425e8596e6d20fee06cc2f5d117a67f94384111f 1 parent 023e01c
Marek Goldmann goldmann authored
6 .gitignore
View
@@ -0,0 +1,6 @@
+build
+*.swp
+sources-cache
+specs
+log
+.idea
6 .gitmodules
View
@@ -0,0 +1,6 @@
+[submodule "lib/net-ssh"]
+ path = lib/net-ssh
+ url = git://github.com/jamis/net-ssh.git
+[submodule "lib/net-sftp"]
+ path = lib/net-sftp
+ url = git://github.com/jamis/net-sftp.git
165 LICENSE
View
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
1  README
View
@@ -0,0 +1 @@
+Cantiere helper tasks to build RPM from .spec files
11 Rakefile
View
@@ -0,0 +1,11 @@
+$: << 'lib'
+
+additional_libs = [ "net-ssh", "net-sftp" ]
+
+additional_libs.each do |lib|
+ $LOAD_PATH.unshift( "#{File.dirname( __FILE__ )}/lib/#{lib}/lib" )
+end
+
+require 'cantiere/helpers/rake-helper'
+
+Cantiere::RakeHelper.new
12 extras/sign-rpms
View
@@ -0,0 +1,12 @@
+#!/usr/bin/expect -f
+
+set password [lindex $argv 0]
+
+foreach package [lrange $argv 1 end] {
+ spawn -noecho rpm --resign $package
+ expect -exact "Enter pass phrase: "
+ send "$password\r"
+ #expect -re "$package"
+}
+
+expect eof
55 lib/cantiere/cantiere.rb
View
@@ -0,0 +1,55 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+require 'cantiere/defaults'
+require 'cantiere/rpm'
+require 'cantiere/config'
+require 'cantiere/topdir'
+require 'cantiere/rpm-utils'
+require 'cantiere/gpg-sign'
+require 'cantiere/validator/config-validator'
+
+$stderr.reopen("/dev/null")
+
+module Cantiere
+ class Cantiere
+ def initialize( project_config = Hash.new )
+ @log = LOG
+
+ @config = Config.new( project_config )
+
+ ConfigValidator.new( @config ).validate
+
+ @log.debug "Current architecture: #{@config.arch}"
+ @log.debug "Building architecture: #{@config.build_arch}"
+
+ Topdir.new( @config )
+ RPMUtils.new( @config )
+ GPGSign.new( @config )
+
+ [ "specs/*.spec" ].each do |spec_file_dir|
+ Dir[ spec_file_dir ].each do |spec_file|
+ RPM.new( @config, spec_file )
+ end
+ end
+ end
+ end
+end
101 lib/cantiere/config.rb
View
@@ -0,0 +1,101 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/defaults'
+require 'ostruct'
+
+module Cantiere
+ class Config
+ RELEASE_FILE = '/etc/redhat-release'
+
+ def initialize( project_config = Hash.new )
+
+ @name = project_config[:name] || DEFAULT_PROJECT_CONFIG[:name]
+
+ @version = OpenStruct.new
+ @version.version = project_config[:version] || DEFAULT_PROJECT_CONFIG[:version]
+ @version.release = project_config[:release] || DEFAULT_PROJECT_CONFIG[:release]
+
+ @dir = OpenStruct.new
+ @dir.root = `pwd`.strip
+ @dir.build = project_config[:dir_build] || DEFAULT_PROJECT_CONFIG[:dir_build]
+ @dir.top = project_config[:dir_top] || "#{@dir.build}/topdir"
+ @dir.src_cache = project_config[:dir_sources_cache] || DEFAULT_PROJECT_CONFIG[:dir_sources_cache]
+ @dir.rpms_cache = project_config[:dir_rpms_cache] || DEFAULT_PROJECT_CONFIG[:dir_rpms_cache]
+ @dir.specs = project_config[:dir_specs] || DEFAULT_PROJECT_CONFIG[:dir_specs]
+ @dir.appliances = project_config[:dir_appliances] || DEFAULT_PROJECT_CONFIG[:dir_appliances]
+ @dir.src = project_config[:dir_src] || DEFAULT_PROJECT_CONFIG[:dir_src]
+ @dir.kickstarts = project_config[:dir_kickstarts] || DEFAULT_PROJECT_CONFIG[:dir_kickstarts]
+
+ # TODO better way to get this directory
+ @dir.base = "#{File.dirname( __FILE__ )}/../.."
+ @dir.tmp = "#{@dir.build}/tmp"
+
+ @arch = (-1.size) == 8 ? "x86_64" : "i386"
+ @os = OpenStruct.new
+
+ if File.exists?( RELEASE_FILE )
+ release_match = File.read( RELEASE_FILE ).match(/^(.*) release ([\d\.]+) \((.*)\)$/)
+ @os.full_name = release_match[1]
+
+ case @os.full_name
+ when /^Red Hat Enterprise Linux(.*)/ then
+ @os.name = "rhel"
+ @os.package_suffix = 'el'
+ when /^Fedora$/ then
+ @os.name = "fedora"
+ @os.package_suffix = 'f'
+ end
+
+ @os.version = release_match[2]
+ @os.main_version = @os.version.match( /^([\d]+)[\.]?(.*)?$/ )[1]
+ @os.package_suffix = @os.package_suffix + @os.main_version
+ @os.code_name = release_match[3]
+ else
+ raise "OS'es other than Fedora or Red Hat are currently unsupported"
+ end
+
+ @build_arch = ENV['CANTIERE_ARCH'].nil? ? @arch : ENV['CANTIERE_ARCH']
+ @os_name = @os.name #ENV['CANTIERE_OS_NAME'].nil? ? APPLIANCE_DEFAULTS['os_name'] : ENV['CANTIERE_OS_NAME']
+ @os_version = @os.version #ENV['CANTIERE_OS_VERSION'].nil? ? APPLIANCE_DEFAULTS['os_version'] : ENV['CANTIERE_OS_VERSION']
+ end
+
+ attr_reader :name
+ attr_reader :version
+ attr_reader :build_arch
+ attr_reader :arch
+ attr_reader :os_name
+ attr_reader :os_version
+ attr_reader :os
+ attr_reader :dir
+
+ def os_path
+ "#{@os.name}/#{@os.version}"
+ end
+
+ def build_path
+ "#{@arch}/#{os_path}"
+ end
+
+ def version_with_release
+ @version.version + ((@version.release.nil? or @version.release.empty?) ? "" : "-" + @version.release)
+ end
+ end
+end
66 lib/cantiere/defaults.rb
View
@@ -0,0 +1,66 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/log'
+require 'cantiere/helpers/exec-helper'
+
+module Cantiere
+ LOG = Log.new
+ EXEC_HELPER = ExecHelper.new
+
+ # here are global variables
+ SUPPORTED_ARCHES = [ "i386", "x86_64" ]
+ SUPPORTED_OSES = {
+ "fedora" => [ "11", "rawhide" ]
+ }
+
+ STABLE_RELEASES = {
+ "fedora" => "11",
+ "rhel" => "5"
+ }
+
+ APPLIANCE_DEFAULTS = {
+ "os_name" => "fedora",
+ "os_version" => STABLE_RELEASES['fedora'],
+ "disk_size" => 2,
+ "mem_size" => 1024,
+ "network_name" => "NAT",
+ "vcpu" => 1,
+ "arch" => (-1.size) == 8 ? "x86_64" : "i386"
+ }
+
+ DEFAULT_PROJECT_CONFIG = {
+ :name => 'Cantiere',
+ :version => '1.0.0.Beta1',
+ :release => 'SNAPSHOT',
+ :dir_build => 'build',
+ #:topdir => "#{self.} build/topdir",
+ :dir_sources_cache => 'sources-cache',
+ :dir_rpms_cache => 'rpms-cache',
+ :dir_specs => 'specs',
+ :dir_appliances => 'appliances',
+ :dir_src => 'src',
+ :dir_kickstarts => 'kickstarts'
+ }
+
+ DEFAULT_HELP_TEXT = {
+ :general => "See http://oddthesis.org/ for more info."
+ }
+end
70 lib/cantiere/gpg-sign.rb
View
@@ -0,0 +1,70 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+
+module Cantiere
+ class GPGSign < Rake::TaskLib
+
+ def initialize( config )
+ @config = config
+
+ @log = LOG
+ @exec_helper = EXEC_HELPER
+
+ define_tasks
+ end
+
+ def define_tasks
+ task 'rpm:sign:all:srpms' => [ 'rpm:all' ] do
+ sign_srpms
+ end
+
+ task 'rpm:sign:all:rpms' => [ 'rpm:all' ] do
+ sing_rpms
+ end
+
+ desc "Sign all packages."
+ task 'rpm:sign:all' => [ 'rpm:sign:all:rpms', 'rpm:sign:all:srpms' ]
+ end
+
+ def sign_srpms
+ validate_and_sign( "#{@config.dir.base}/extras/sign-rpms #{@config.data['gpg_password']} #{@config.dir.top}/#{APPLIANCE_DEFAULTS['os_name']}/#{APPLIANCE_DEFAULTS['os_version']}/SRPMS/*.src.rpm > /dev/null 2>&1", "SRPMs" )
+ end
+
+ def sing_rpms
+ validate_and_sign( "#{@config.dir.base}/extras/sign-rpms #{@config.data['gpg_password']} #{@config.dir.top}/#{@config.os_path}/RPMS/*/*.rpm > /dev/null 2>&1", "RPMs" )
+ end
+
+ def validate_and_sign( command, type )
+ @log.info "Signing #{type}..."
+
+ begin
+ @config.helper.validate_gpg_password
+ @exec_helper.execute( command )
+ rescue => e
+ @log.fatal "An error occured, some #{type} may be not signed. Possible errors: key exists?, wrong passphrase, expect package installed?, %_gpg_name in ~/.rpmmacros set?"
+ raise e
+ end
+
+ @log.info "All #{type} were successfully signed!"
+ end
+ end
+end
36 lib/cantiere/helpers/config-helper.rb
View
@@ -0,0 +1,36 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/validator/errors'
+
+module Cantiere
+ class ConfigHelper
+
+ def initialize( config )
+ @config = config
+ end
+
+ # TODO this is not good, remove this
+ def validate_gpg_password
+ raise ValidationError, "You have no GPG password specified in JBoss Cloud config file." if @config.data['gpg_password'].nil?
+ end
+
+ end
+end
44 lib/cantiere/helpers/exec-helper.rb
View
@@ -0,0 +1,44 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+module Cantiere
+ class ExecHelper
+ def initialize
+ @log = LOG
+ end
+
+ def execute( command, file = nil )
+ @log.debug "Executing command: '#{command}'"
+
+ out = `#{command} 2>&1`
+
+ formatted_output = "Command return:\r\n+++++\r\n#{out}+++++"
+
+ if $?.to_i != 0
+ @log.error formatted_output
+ raise "An error occured executing commad: '#{command}'"
+ else
+ @log.debug formatted_output unless out.strip.length == 0
+ @log.debug "Command '#{command}' executed successfuly"
+ return out
+ end
+ end
+ end
+end
58 lib/cantiere/helpers/rake-helper.rb
View
@@ -0,0 +1,58 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/cantiere'
+
+module Rake
+ class Task
+ alias_method :execute_original, :execute
+
+ def execute( args=nil )
+ begin
+ execute_original( args )
+ rescue => e
+ Cantiere::LOG.fatal e
+ Cantiere::LOG.fatal e.message
+ abort
+ end
+ end
+ end
+end
+
+module Cantiere
+ class RakeHelper
+ def initialize
+ begin
+ LOG.debug "Running new Rake session..."
+
+ Cantiere.new
+ rescue ValidationError => e
+ LOG.fatal "ValidationError: #{e.message}."
+ abort
+ rescue => e
+ LOG.fatal e
+ LOG.fatal "Aborting: #{e.message}. See previous errors for more information."
+ abort
+ end
+ end
+ end
+end
+
+
139 lib/cantiere/helpers/ssh-helper.rb
View
@@ -0,0 +1,139 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'net/ssh'
+require 'net/sftp'
+require 'progressbar/progressbar'
+
+module Cantiere
+ class SSHHelper
+ def initialize( options )
+ @options = options
+
+ @exec_helper = EXEC_HELPER
+ @log = LOG
+ end
+
+ def connect
+ @log.info "Connecting to #{@options['host']}..."
+ @ssh = Net::SSH.start( @options['host'], @options['username'], { :password => @options['password'] } )
+ end
+
+ def connected?
+ return true if !@ssh.nil? and !@ssh.closed?
+ false
+ end
+
+ def disconnect
+ @log.info "Disconnecting from #{@options['host']}..."
+ @ssh.close if connected?
+ @ssh = nil
+ end
+
+ def upload_files( path, files = {} )
+
+ return if files.size == 0
+
+ raise "You're not connected to server" unless connected?
+
+ global_size = 0
+
+ files.each_value do |file|
+ global_size += File.size( file )
+ end
+
+ global_size_kb = global_size / 1024
+ global_size_mb = global_size_kb / 1024
+
+ @log.info "#{files.size} files to upload (#{global_size_mb > 0 ? global_size_mb.to_s + "MB" : global_size_kb > 0 ? global_size_kb.to_s + "kB" : global_size.to_s})"
+
+ @ssh.sftp.connect do |sftp|
+
+ begin
+ sftp.stat!( path )
+ rescue Net::SFTP::StatusException => e
+ raise unless e.code == 2
+ if @options['sftp_create_path']
+ @ssh.exec!( "mkdir -p #{path}" )
+ else
+ raise
+ end
+ end
+
+ nb = 0
+
+ files.each do |key, local|
+ name = File.basename( local )
+ remote = "#{path}/#{key}"
+ size_b = File.size( local )
+ size_kb = size_b / 1024
+ nb_of = "#{nb += 1}/#{files.size}"
+
+ begin
+ sftp.stat!( remote )
+
+ unless @options['sftp_overwrite']
+
+ local_md5_sum = `md5sum #{local} | awk '{ print $1 }'`.strip
+ remote_md5_sum = @ssh.exec!( "md5sum #{remote} | awk '{ print $1 }'" ).strip
+
+ if (local_md5_sum.eql?( remote_md5_sum ))
+ @log.info "#{nb_of} #{name}: files are identical (md5sum: #{local_md5_sum}), skipping..."
+ next
+ end
+ end
+
+ rescue Net::SFTP::StatusException => e
+ raise unless e.code == 2
+ end
+
+ @ssh.exec!( "mkdir -p #{File.dirname( remote ) }" )
+
+ pbar = ProgressBar.new( "#{nb_of} #{name}", size_b )
+ pbar.file_transfer_mode
+
+ sftp.upload!( local, remote ) do |event, uploader, *args|
+ case event
+ when :open then
+ when :put then
+ pbar.set( args[1] )
+ when :close then
+ when :mkdir then
+ when :finish then
+ pbar.finish
+ end
+ end
+
+ sftp.setstat(remote, :permissions => @options['sftp_default_permissions'])
+
+ end
+ end
+ end
+
+ def createrepo( path, directories = [] )
+ raise "You're not connected to server" unless connected?
+
+ directories.each do |directory|
+ @log.info "Refreshing repository information in #{directory}..."
+ @ssh.exec!( "createrepo #{path}/#{directory}" )
+ end
+ end
+ end
+end
77 lib/cantiere/log.rb
View
@@ -0,0 +1,77 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'logger'
+
+module Cantiere
+ class Log
+ def initialize
+ treshold = ENV['CANTIERE_LOG_THRESHOLD']
+
+ unless treshold.nil?
+ case treshold
+ when "fatal"
+ treshold = Logger::FATAL
+ when "debug"
+ treshold = Logger::DEBUG
+ when "error"
+ treshold = Logger::ERROR
+ when "warn"
+ treshold = Logger::WARN
+ when "info"
+ treshold = Logger::INFO
+ end
+ end
+
+ @stdout_log = Logger.new(STDOUT)
+ @stdout_log.level = treshold || Logger::INFO
+
+ FileUtils.mkdir_p( 'log' )
+
+ @file_log = Logger.new('log/cantiere.log') # , 10, 1024000
+ @file_log.level = Logger::DEBUG
+ end
+
+ def debug( msg )
+ @stdout_log.debug( msg )
+ @file_log.debug( msg )
+ end
+
+ def info( msg )
+ @stdout_log.info( msg )
+ @file_log.info( msg )
+ end
+
+ def warn( msg )
+ @stdout_log.warn( msg )
+ @file_log.warn( msg )
+ end
+
+ def error( msg )
+ @stdout_log.error( msg )
+ @file_log.error( msg )
+ end
+
+ def fatal( msg )
+ @stdout_log.fatal( msg )
+ @file_log.fatal( msg )
+ end
+ end
+end
59 lib/cantiere/repodata.rb
View
@@ -0,0 +1,59 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+
+module Cantiere
+ class Repodata < Rake::TaskLib
+
+ def initialize( config )
+ @config = config
+ @log = LOG
+
+ @arches = SUPPORTED_ARCHES + [ "noarch" ]
+ @oses = SUPPORTED_OSES
+
+ @exec_helper = EXEC_HELPER
+
+ define_tasks
+ end
+
+ def define_tasks
+ desc "Force a rebuild of the repository data"
+ task "rpm:repodata:force" => [ 'rpm:topdir' ] do
+ createrepo
+ end
+ end
+
+ def createrepo
+ @log.debug "Refreshing repodata..."
+
+ for os in @oses.keys
+ for version in @oses[os]
+ for arch in @arches
+ @exec_helper.execute( "createrepo --update #{@config.dir.top}/#{os}/#{version}/RPMS/#{arch}" )
+ end
+ end
+ end
+
+ @log.debug "Refreshing repodata finished."
+ end
+ end
+end
58 lib/cantiere/rpm-gpg-sign.rb
View
@@ -0,0 +1,58 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+
+module Cantiere
+ class RPMGPGSign < Rake::TaskLib
+
+ def initialize( config, spec_file, rpm_file )
+ @config = config
+ @spec_file = spec_file
+
+ @rpm_file = rpm_file
+
+ @rpm_file_basename = File.basename( @rpm_file )
+ @simple_name = File.basename( @spec_file, ".spec" )
+
+ @log = LOG
+ @exec_helper = EXEC_HELPER
+
+ define_tasks
+ end
+
+ def define_tasks
+ task "rpm:#{@simple_name}:sign" => [ "rpm:#{@simple_name}" ] do
+ sign_rpm
+ end
+ end
+
+ def sign_rpm
+ @log.info "Signing package '#{@rpm_file_basename}'..."
+
+ @config.helper.validate_gpg_password
+ out = @exec_helper.execute( "#{@config.dir.base}/extras/sign-rpms #{@config.data['gpg_password']} #{@rpm_file}" )
+
+ raise "An error occured. Possible errors: key exists?, wrong passphrase, expect package installed?, %_gpg_name in ~/.rpmmacros set?" if out =~ /Pass phrase check failed/
+
+ @log.info "Package '#{@rpm_file_basename}' successfully signed!"
+ end
+ end
+end
85 lib/cantiere/rpm-utils.rb
View
@@ -0,0 +1,85 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+require 'net/ssh'
+require 'net/sftp'
+require 'cantiere/validator/errors'
+require 'cantiere/ssh/ssh-config'
+require 'cantiere/helpers/ssh-helper'
+
+module Cantiere
+ class RPMUtils < Rake::TaskLib
+
+ def initialize( config )
+ @config = config
+
+ @arches = SUPPORTED_ARCHES + [ "noarch" ]
+ @oses = SUPPORTED_OSES
+
+ define_tasks
+ end
+
+ def define_tasks
+ desc "Upload all packages."
+ task 'rpm:upload:all' => [ 'rpm:all' ] do
+ upload_packages
+ end
+ end
+
+ def validate_rpm_upload_config( ssh_config )
+ raise ValidationError, "Remote packages path (remote_rpm_path) not specified in ssh section in configuration file '#{@config.config_file}'. #{DEFAULT_HELP_TEXT[:general]}" if ssh_config.cfg['remote_rpm_path'].nil?
+ end
+
+ def upload_packages
+ ssh_config = SSHConfig.new( @config )
+
+ validate_rpm_upload_config( ssh_config )
+
+ dirs = []
+ packages = {}
+
+ for os in @oses.keys
+ for version in @oses[os]
+ for arch in @arches
+ dirs.push( "#{os}/#{version}/RPMS/#{arch}" )
+ Dir[ "#{@config.dir.top}/#{os}/#{version}/RPMS/#{arch}/*.rpm" ].each do |file|
+ local_prefix_length = "#{@config.dir.top}/".length
+ packages[file[ local_prefix_length, file.length ]] = file
+ end
+ end
+ dirs.push( "#{os}/#{version}/SRPMS" )
+ Dir[ "#{@config.dir.top}/#{os}/#{version}/SRPMS/*.rpm" ].each do |file|
+ local_prefix_length = "#{@config.dir.top}/".length
+ packages[file[ local_prefix_length, file.length ]] = file
+ end
+ end
+ end
+
+ ssh_helper = SSHHelper.new( ssh_config.options )
+
+ ssh_helper.connect
+ ssh_helper.upload_files( ssh_config.cfg['remote_rpm_path'], packages )
+ ssh_helper.createrepo( ssh_config.cfg['remote_rpm_path'], dirs )
+ ssh_helper.disconnect
+ end
+
+ end
+end
181 lib/cantiere/rpm.rb
View
@@ -0,0 +1,181 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/rpm-gpg-sign'
+
+module Cantiere
+ class RPM < Rake::TaskLib
+
+ def self.provides
+ @provides ||= {}
+ end
+
+ def self.provides_rpm_path
+ @provides_rpm_path ||= {}
+ end
+
+ def initialize( config, spec_file, options = {} )
+ @config = config
+ @spec_file = spec_file
+
+ @log = options[:log] || LOG
+ @exec_helper = options[:exec_helper] || EXEC_HELPER
+
+ @simple_name = File.basename( @spec_file, ".spec" )
+
+ @rpm_release = nil
+ @rpm_version = nil
+ @rpm_is_noarch = nil
+
+ Dir.chdir( File.dirname( @spec_file ) ) do
+ @rpm_release = `rpm --specfile #{@simple_name}.spec -q --qf '%{Release}\\n' 2> /dev/null`.split("\n").first
+ @rpm_version = `rpm --specfile #{@simple_name}.spec -q --qf '%{Version}\\n' 2> /dev/null`.split("\n").first
+ @rpm_is_noarch = `rpm --specfile #{@simple_name}.spec -q --qf '%{arch}\\n' 2> /dev/null`.split("\n").first == "noarch"
+ end
+
+ @rpm_arch = @rpm_is_noarch ? "noarch" : @config.build_arch
+
+ @rpm_file = "#{@config.dir.top}/#{@config.os_path}/RPMS/#{@rpm_arch}/#{@simple_name}-#{@rpm_version}-#{@rpm_release}.#{@rpm_arch}.rpm"
+ @rpm_file_basename = File.basename( @rpm_file )
+
+ RPM.provides[@simple_name] = "#{@simple_name}-#{@rpm_version}-#{@rpm_release}"
+ RPM.provides_rpm_path[@simple_name] = @rpm_file
+
+ RPMGPGSign.new( @config, @spec_file, @rpm_file )
+
+ define_tasks
+ end
+
+ def define_tasks
+ desc "Build #{@simple_name} RPM."
+ task "rpm:#{@simple_name}" => [ @rpm_file ]
+
+ file @rpm_file => [ 'rpm:topdir', @spec_file ] do
+ @log.info "Building package '#{@rpm_file_basename}'..."
+ build_source_dependencies( @rpm_file, @rpm_version, @rpm_release )
+ puts "a"
+ build_rpm
+ @log.info "Package '#{@rpm_file_basename}' was built successfully."
+ end
+
+ task 'rpm:all' => [ "rpm:#{@simple_name}" ]
+ end
+
+ def build_rpm
+ Dir.chdir( File.dirname( @spec_file ) ) do
+ @exec_helper.execute( "rpmbuild --define '_topdir #{@config.dir.root}/#{@config.dir.top}/#{@config.os_path}' --target #{@rpm_arch} -ba #{@simple_name}.spec" )
+ end
+
+ Rake::Task[ 'rpm:repodata:force' ].reenable
+ end
+
+ def handle_requirement(rpm_file, requirement)
+ if RPM.provides.keys.include?( requirement )
+ file rpm_file => [ RPM.provides_rpm_path[ requirement ] ]
+ end
+ end
+
+ def substitute_defined_data(str, version=nil, release=nil)
+ substitutes = {}
+
+ File.open( @spec_file).each_line do |line|
+ match = line.match(/^%define (.*) (.*)$/)
+ substitutes[match[1].strip] = match[2].strip if match
+ end
+
+ s = str.dup
+
+ for key in substitutes.keys
+ s.gsub!( /%\{#{key}\}/, substitutes[key] )
+ end
+
+ name = File.basename( @spec_file, ".*" )
+
+ s.gsub!( /%\{version\}/, version ) if version
+ s.gsub!( /%\{release\}/, release ) if release
+ s.gsub!( /%\{name\}/, name )
+ s
+ end
+
+ def handle_source(rpm_file, source, version, release)
+ source = substitute_defined_data( source, version, release )
+
+ @log.debug "Handling source '#{source}'..."
+
+ if ( source =~ %r{http://} )
+ handle_remote_source( rpm_file, source )
+ else
+ handle_local_source( rpm_file, source )
+ end
+
+ @log.debug "Source '#{source}' handled."
+ end
+
+ def handle_local_source(rpm_file, source)
+ source_basename = File.basename( source )
+ source_file = "#{@config.dir.top}/#{@config.os_path}/SOURCES/#{source_basename}"
+
+ file rpm_file => [ source_file ]
+
+ FileUtils.cp( "#{@config.dir.src}/#{source}", "#{source_file}" ) if File.exists?( "#{@config.dir.src}/#{source}" )
+ FileUtils.cp( "#{@config.dir.base}/src/#{source}", "#{source_file}" ) if File.exists?( "#{@config.dir.base}/src/#{source}" )
+
+ raise "Source '#{source}' not handled!" unless File.exists?( source_file )
+ end
+
+ def handle_remote_source(rpm_file, source)
+ source_basename = File.basename( source )
+
+ source_file = "#{@config.dir.top}/#{@config.os_path}/SOURCES/#{source_basename}"
+ source_cache_file = "#{@config.dir.src_cache}/#{source_basename}"
+
+ file rpm_file => [ source_file ]
+
+ if ( ! File.exist?( source_cache_file ) )
+ FileUtils.mkdir_p( @config.dir.src_cache )
+ @exec_helper.execute( "wget #{source} -O #{source_cache_file}" )
+ end
+
+ FileUtils.cp( source_cache_file, source_file )
+
+ raise "Source '#{source}' not handled!" unless File.exists?( source_file )
+ end
+
+ def build_source_dependencies( rpm_file, version=nil, release=nil)
+ File.open( @spec_file).each_line do |line|
+ line.gsub!( /#.*$/, '' )
+ puts line
+ if ( line =~ /Requires:(.*)/ )
+ requirement = $1.strip
+ handle_requirement( rpm_file, requirement )
+ elsif ( line =~ /Source[0-9]*:(.*)/ )
+ source = $1.strip
+ handle_source( rpm_file, source, version, release )
+ elsif ( line =~ /Patch[0-9]*:(.*)/ )
+ patch = $1.strip
+ handle_source( rpm_file, patch, version, release )
+ end
+ end
+ end
+ end
+end
+
+desc "Build all RPMs"
+task 'rpm:all'
56 lib/cantiere/ssh/ssh-config.rb
View
@@ -0,0 +1,56 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/validator/errors'
+require 'yaml'
+
+module Cantiere
+ class SSHConfig
+ def initialize( config )
+ @config = config
+ @options = {}
+
+ # defaults
+ @options['sftp_create_path'] = true
+ @options['sftp_overwrite'] = false
+ @options['sftp_default_permissions'] = 0644
+
+ validate
+ end
+
+ def validate
+ raise ValidationError, "Specified configuration file (#{@config.config_file}) doesn't exists. #{DEFAULT_HELP_TEXT[:general]}" unless File.exists?( @config.config_file )
+ raise ValidationError, "No 'ssh' section in config file in configuration file '#{@config.config_file}'. #{DEFAULT_HELP_TEXT[:general]}" if @config.release.ssh.nil?
+
+ # we need only ssh section
+ @cfg = @config.release.ssh
+
+ raise ValidationError, "Host not specified in configuration file '#{@config.config_file}'. #{DEFAULT_HELP_TEXT[:general]}" if @cfg['host'].nil?
+ raise ValidationError, "Username not specified in configuration file '#{@config.config_file}'. #{DEFAULT_HELP_TEXT[:general]}" if @cfg['username'].nil?
+
+ @options['host'] = @config.release.ssh['host']
+ @options['username'] = @config.release.ssh['username']
+ @options['password'] = @config.release.ssh['password']
+ end
+
+ attr_reader :options
+ attr_reader :cfg
+ end
+end
69 lib/cantiere/topdir.rb
View
@@ -0,0 +1,69 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'rake/tasklib'
+require 'cantiere/repodata'
+
+module Cantiere
+ class Topdir < Rake::TaskLib
+
+ def initialize( config )
+ @config = config
+ @log = LOG
+
+ @topdir = @config.dir.top
+ @arches = SUPPORTED_ARCHES + [ "noarch" ]
+ @oses = SUPPORTED_OSES
+
+ Repodata.new( @config )
+
+ define_tasks
+ end
+
+ def define_tasks
+
+ for os in @oses.keys
+ for version in @oses[os]
+ directory "#{@topdir}/#{os}/#{version}/tmp"
+ directory "#{@topdir}/#{os}/#{version}/SPECS"
+ directory "#{@topdir}/#{os}/#{version}/SOURCES"
+ directory "#{@topdir}/#{os}/#{version}/BUILD"
+ directory "#{@topdir}/#{os}/#{version}/RPMS"
+ directory "#{@topdir}/#{os}/#{version}/SRPMS"
+
+ task "rpm:topdir" => [
+ "#{@topdir}/#{os}/#{version}/tmp",
+ "#{@topdir}/#{os}/#{version}/SPECS",
+ "#{@topdir}/#{os}/#{version}/SOURCES",
+ "#{@topdir}/#{os}/#{version}/BUILD",
+ "#{@topdir}/#{os}/#{version}/RPMS",
+ "#{@topdir}/#{os}/#{version}/SRPMS",
+ ]
+
+ for arch in @arches
+ directory "#{@topdir}/#{os}/#{version}/RPMS/#{arch}"
+
+ task "rpm:topdir" => [ "#{@topdir}/#{os}/#{version}/RPMS/#{arch}" ]
+ end
+ end
+ end
+ end
+ end
+end
35 lib/cantiere/validator/appliance-config-parameter-validator.rb
View
@@ -0,0 +1,35 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/config'
+require 'cantiere/validator/errors'
+
+module Cantiere
+ class ApplianceConfigParameterValidator
+ def validate
+ raise ValidationError, "'#{ENV['CANTIERE_ARCH']}' is not a valid build architecture. Available architectures: #{SUPPORTED_ARCHES.join(", ")}." if (!ENV['JBOSS_CLOUD_ARCH'].nil? and !SUPPORTED_ARCHES.include?( ENV['JBOSS_CLOUD_ARCH']))
+ raise ValidationError, "'#{ENV['CANTIERE_OS_NAME']}' is not a valid OS name. Please enter valid name." if !ENV['JBOSS_CLOUD_OS_NAME'].nil? && !SUPPORTED_OSES.keys.include?( ENV['JBOSS_CLOUD_OS_NAME'] )
+
+ os_name = ENV['CANTIERE_OS_NAME'].nil? ? APPLIANCE_DEFAULTS['os_name'] : ENV['JBOSS_CLOUD_OS_NAME']
+
+ raise ValidationError, "'#{ENV['JBOSS_CLOUD_OS_VERSION']}' is not a valid OS version for #{os_name}. Please enter valid version." if !ENV['JBOSS_CLOUD_OS_VERSION'].nil? && !SUPPORTED_OSES[os_name].include?( ENV['JBOSS_CLOUD_OS_VERSION'] )
+ end
+ end
+end
39 lib/cantiere/validator/config-validator.rb
View
@@ -0,0 +1,39 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+require 'cantiere/config'
+require 'cantiere/validator/errors'
+
+module Cantiere
+ class ConfigValidator
+ def initialize( config )
+ @config = config
+ @log = LOG
+ end
+
+ def validate
+ validate_arch
+ end
+
+ def validate_arch
+ raise ValidationError, "Building x86_64 images from i386 system isn't possible" if @config.arch == "i386" and @config.build_arch == "x86_64"
+ end
+ end
+end
28 lib/cantiere/validator/errors.rb
View
@@ -0,0 +1,28 @@
+# JBoss, Home of Professional Open Source
+# Copyright 2009, Red Hat Middleware LLC, and individual contributors
+# by the @authors tag. See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# This software 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this software; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+module Cantiere
+ class ValidationError < StandardError
+ end
+
+ class ApplianceValidationError < ValidationError
+
+ end
+end
1  lib/net-sftp
@@ -0,0 +1 @@
+Subproject commit 100c5c1bb21c076a3150d1c7de9311c9fd7eea50
1  lib/net-ssh
@@ -0,0 +1 @@
+Subproject commit 5c83de0d95f71aedf8e9c979f46c4a77e4f6c1a7
236 lib/progressbar/progressbar.rb
View
@@ -0,0 +1,236 @@
+#
+# Ruby/ProgressBar - a text progress bar library
+#
+# Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>
+# All rights reserved.
+# This is free software with ABSOLUTELY NO WARRANTY.
+#
+# You can redistribute it and/or modify it under the terms
+# of Ruby's license.
+#
+
+class ProgressBar
+ VERSION = "0.9"
+
+ def initialize (title, total, out = STDERR)
+ @title = title
+ @total = total
+ @out = out
+ @terminal_width = 80
+ @bar_mark = "o"
+ @current = 0
+ @previous = 0
+ @finished_p = false
+ @start_time = Time.now
+ @previous_time = @start_time
+ @title_width = 14
+ @format = "%-#{@title_width}s %3d%% %s %s"
+ @format_arguments = [:title, :percentage, :bar, :stat]
+ clear
+ show
+ end
+ attr_reader :title
+ attr_reader :current
+ attr_reader :total
+ attr_accessor :start_time
+
+ private
+ def fmt_bar
+ bar_width = do_percentage * @terminal_width / 100
+ sprintf("|%s%s|",
+ @bar_mark * bar_width,
+ " " * (@terminal_width - bar_width))
+ end
+
+ def fmt_percentage
+ do_percentage
+ end
+
+ def fmt_stat
+ if @finished_p then elapsed else eta end
+ end
+
+ def fmt_stat_for_file_transfer
+ if @finished_p then
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
+ else
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
+ end
+ end
+
+ def fmt_title
+ @title[0,(@title_width - 1)] + ":"
+ end
+
+ def convert_bytes (bytes)
+ if bytes < 1024
+ sprintf("%6dB", bytes)
+ elsif bytes < 1024 * 1000 # 1000kb
+ sprintf("%5.1fKB", bytes.to_f / 1024)
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
+ else
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
+ end
+ end
+
+ def transfer_rate
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
+ sprintf("%s/s", convert_bytes(bytes_per_second))
+ end
+
+ def bytes
+ convert_bytes(@current)
+ end
+
+ def format_time (t)
+ t = t.to_i
+ sec = t % 60
+ min = (t / 60) % 60
+ hour = t / 3600
+ sprintf("%02d:%02d:%02d", hour, min, sec);
+ end
+
+ # ETA stands for Estimated Time of Arrival.
+ def eta
+ if @current == 0
+ "ETA: --:--:--"
+ else
+ elapsed = Time.now - @start_time
+ eta = elapsed * @total / @current - elapsed;
+ sprintf("ETA: %s", format_time(eta))
+ end
+ end
+
+ def elapsed
+ elapsed = Time.now - @start_time
+ sprintf("Time: %s", format_time(elapsed))
+ end
+
+ def eol
+ if @finished_p then "\n" else "\r" end
+ end
+
+ def do_percentage
+ if @total.zero?
+ 100
+ else
+ @current * 100 / @total
+ end
+ end
+
+ def get_width
+ # FIXME: I don't know how portable it is.
+ default_width = 80
+ begin
+ tiocgwinsz = 0x5413
+ data = [0, 0, 0, 0].pack("SSSS")
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
+ if cols >= 0 then cols else default_width end
+ else
+ default_width
+ end
+ rescue Exception
+ default_width
+ end
+ end
+
+ def show
+ arguments = @format_arguments.map {|method|
+ method = sprintf("fmt_%s", method)
+ send(method)
+ }
+ line = sprintf(@format, *arguments)
+
+ width = get_width
+ if line.length == width - 1
+ @out.print(line + eol)
+ @out.flush
+ elsif line.length >= width
+ @terminal_width = [@terminal_width - (line.length - width + 1), 0].max
+ if @terminal_width == 0 then @out.print(line + eol) else show end
+ else # line.length < width - 1
+ @terminal_width += width - line.length + 1
+ show
+ end
+ @previous_time = Time.now
+ end
+
+ def show_if_needed
+ if @total.zero?
+ cur_percentage = 100
+ prev_percentage = 0
+ else
+ cur_percentage = (@current * 100 / @total).to_i
+ prev_percentage = (@previous * 100 / @total).to_i
+ end
+
+ # Use "!=" instead of ">" to support negative changes
+ if cur_percentage != prev_percentage ||
+ Time.now - @previous_time >= 1 || @finished_p
+ show
+ end
+ end
+
+ public
+ def clear
+ @out.print "\r"
+ @out.print(" " * (get_width - 1))
+ @out.print "\r"
+ end
+
+ def finish
+ @current = @total
+ @finished_p = true
+ show
+ end
+
+ def finished?
+ @finished_p
+ end
+
+ def file_transfer_mode
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
+ end
+
+ def format= (format)
+ @format = format
+ end
+
+ def format_arguments= (arguments)
+ @format_arguments = arguments
+ end
+
+ def halt
+ @finished_p = true
+ show
+ end
+
+ def inc (step = 1)
+ @current += step
+ @current = @total if @current > @total
+ show_if_needed
+ @previous = @current
+ end
+
+ def set (count)
+ if count < 0 || count > @total
+ raise "invalid count: #{count} (total: #{@total})"
+ end
+ @current = count
+ show_if_needed
+ @previous = @current
+ end
+
+ def inspect
+ "#<ProgressBar:#{@current}/#{@total}>"
+ end
+end
+
+class ReversedProgressBar < ProgressBar
+ def do_percentage
+ 100 - super
+ end
+end
+
1  src/README
View
@@ -0,0 +1 @@
+Place here your source files referenced in spec files located in $CANTIERE_HOME/spec/ directory.
Please sign in to comment.
Something went wrong with that request. Please try again.