|
| 1 | +gem 'fpm', '<=0.3.11' |
| 2 | +require 'fpm' |
| 3 | +require 'fpm/program' |
| 4 | +require 'pp' |
| 5 | + |
| 6 | +$:.unshift(File.join(File.dirname(__FILE__), '..')) |
| 7 | +require 'version_helper' |
| 8 | + |
| 9 | +class BasePackager |
| 10 | + |
| 11 | + def initialize(package_type) |
| 12 | + self.validate_environment |
| 13 | + |
| 14 | + version_helper = VersionHelper.new |
| 15 | + |
| 16 | + @basedirectory = ENV['WORKSPACE'] |
| 17 | + @semver_version = version_helper.semver_version |
| 18 | + @release = "1" |
| 19 | + @package_type = package_type |
| 20 | + |
| 21 | + case package_type |
| 22 | + when "rpm" |
| 23 | + @first_delimiter, @second_delimiter, @architecture = "-", ".", "noarch" |
| 24 | + when "deb" |
| 25 | + @first_delimiter, @second_delimiter, @architecture = "_", "_", "all" |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + def validate_environment() |
| 30 | + if ENV['WORKSPACE'].nil? |
| 31 | + fail("Environment variable WORKSPACE has not been set.") |
| 32 | + end |
| 33 | + if ENV['BUILD_NUMBER'].nil? |
| 34 | + ENV["BUILD_NUMBER"] = "0" |
| 35 | + end |
| 36 | + if ENV['GIT_COMMIT'].nil? |
| 37 | + ENV['GIT_COMMIT'] = "54b0c58c7ce9f2a8b551351102ee0938"[0,10] |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + def build(module_name) |
| 42 | + ENV["#{ENV['JOB_NAME']}_semver_version"] = @semver_version |
| 43 | + package_name = "cegeka-puppet-#{module_name}" |
| 44 | + destination_file = "#{package_name}#{@first_delimiter}#{@semver_version}-#{@release}#{@second_delimiter}#{@architecture}.#{@package_type}" |
| 45 | + destination_folder = "#{@basedirectory}/#{module_name}/#{RESULTS}/dist" |
| 46 | + url = "https://github.com/cegeka/puppet-#{module_name}" |
| 47 | + description = "Puppet module: #{module_name} by Cegeka\nModule #{module_name} description goes here." |
| 48 | + |
| 49 | + static_arguments = ["-t", @package_type, "-s", "dir", "-a", @architecture, "-m", "Cegeka <[email protected]>", "--prefix", "/etc/puppet/modules"] |
| 50 | + exclude_arguments = ["-x", ".git", "-x", ".gitignore", "-x", "tasks", "-x", "Rakefile", "-x", "target", "-x", ".project", "-x", ".puppet-lintrc"] |
| 51 | + var_arguments = ["-n", package_name, "-v", @semver_version, "--iteration", @release, "--url", url, "--description", description, "-C", @basedirectory, module_name] |
| 52 | + arguments = static_arguments + exclude_arguments + var_arguments |
| 53 | + |
| 54 | + tmpdir = Dir.mktmpdir |
| 55 | + Dir.chdir tmpdir |
| 56 | + FileUtils.mkpath destination_folder |
| 57 | + packagebuild = FPM::Program.new |
| 58 | + ret = packagebuild.run(arguments) |
| 59 | + FileUtils.mv("#{tmpdir}/#{destination_file}","#{destination_folder}/#{destination_file}") |
| 60 | + FileUtils.remove_entry_secure(tmpdir) |
| 61 | + return "Created #{destination_folder}/#{destination_file}" |
| 62 | + end |
| 63 | + |
| 64 | +end |
0 commit comments