fpm-cookery 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.travis.yml +10 -0
  2. data/CHANGELOG.md +8 -0
  3. data/bin/fpm-cook +1 -1
  4. data/fpm-cookery.gemspec +2 -1
  5. data/lib/fpm/cookery/chain_packager.rb +58 -0
  6. data/lib/fpm/cookery/cli.rb +93 -104
  7. data/lib/fpm/cookery/config.rb +86 -0
  8. data/lib/fpm/cookery/dependency_inspector.rb +7 -3
  9. data/lib/fpm/cookery/exceptions.rb +11 -0
  10. data/lib/fpm/cookery/facts.rb +1 -0
  11. data/lib/fpm/cookery/log.rb +1 -1
  12. data/lib/fpm/cookery/package/dir.rb +11 -35
  13. data/lib/fpm/cookery/package/gem.rb +25 -0
  14. data/lib/fpm/cookery/package/maintainer.rb +39 -0
  15. data/lib/fpm/cookery/package/package.rb +100 -0
  16. data/lib/fpm/cookery/package/version.rb +48 -0
  17. data/lib/fpm/cookery/packager.rb +65 -97
  18. data/lib/fpm/cookery/path.rb +4 -0
  19. data/lib/fpm/cookery/recipe.rb +59 -19
  20. data/lib/fpm/cookery/shellout.rb +35 -0
  21. data/lib/fpm/cookery/source_handler/curl.rb +12 -2
  22. data/lib/fpm/cookery/version.rb +1 -1
  23. data/recipes/arr-pm/recipe.rb +4 -0
  24. data/recipes/backports/recipe.rb +4 -0
  25. data/recipes/cabin/recipe.rb +4 -0
  26. data/recipes/clamp/recipe.rb +4 -0
  27. data/recipes/facter/recipe.rb +4 -0
  28. data/recipes/fpm-cookery-gem/addressable.rb +4 -0
  29. data/recipes/fpm-cookery-gem/arr-pm.rb +4 -0
  30. data/recipes/fpm-cookery-gem/backports.rb +4 -0
  31. data/recipes/fpm-cookery-gem/cabin.rb +4 -0
  32. data/recipes/fpm-cookery-gem/childprocess.rb +7 -0
  33. data/recipes/fpm-cookery-gem/clamp.rb +4 -0
  34. data/recipes/fpm-cookery-gem/facter.rb +4 -0
  35. data/recipes/fpm-cookery-gem/ffi.rb +4 -0
  36. data/recipes/fpm-cookery-gem/fpm.rb +7 -0
  37. data/recipes/fpm-cookery-gem/ftw.rb +7 -0
  38. data/recipes/fpm-cookery-gem/hiera.rb +7 -0
  39. data/recipes/fpm-cookery-gem/http_parser.rb.rb +4 -0
  40. data/recipes/fpm-cookery-gem/json.rb +4 -0
  41. data/recipes/fpm-cookery-gem/json_pure.rb +4 -0
  42. data/recipes/fpm-cookery-gem/puppet.rb +7 -0
  43. data/recipes/fpm-cookery-gem/recipe.rb +7 -0
  44. data/recipes/fpm-cookery-gem/rgen.rb +4 -0
  45. data/recipes/fpm-cookery/recipe.rb +1 -1
  46. data/recipes/fpm-cookery/ruby.rb +20 -10
  47. data/recipes/fpm/recipe.rb +4 -0
  48. data/recipes/json/recipe.rb +4 -0
  49. data/recipes/open4/recipe.rb +4 -0
  50. data/spec/config_spec.rb +167 -0
  51. data/spec/facts_spec.rb +7 -0
  52. data/spec/fixtures/test-config-1.yml +2 -0
  53. data/spec/package_maintainer_spec.rb +79 -0
  54. data/spec/package_spec.rb +182 -0
  55. data/spec/package_version_spec.rb +119 -0
  56. data/spec/recipe_spec.rb +18 -0
  57. data/spec/spec_helper.rb +1 -0
  58. metadata +61 -6
@@ -21,6 +21,10 @@ module FPM
21
21
  self + (path || '').gsub(%r{^/}, '')
22
22
  end
23
23
 
24
+ def =~(regex)
25
+ @path =~ regex
26
+ end
27
+
24
28
  def mkdir
25
29
  FileUtils.mkdir_p(self.to_s)
26
30
  end
@@ -5,10 +5,12 @@ require 'fpm/cookery/source'
5
5
  require 'fpm/cookery/source_handler'
6
6
  require 'fpm/cookery/utils'
7
7
  require 'fpm/cookery/path_helper'
8
+ require 'fpm/cookery/package/dir'
9
+ require 'fpm/cookery/package/gem'
8
10
 
9
11
  module FPM
10
12
  module Cookery
11
- class Recipe
13
+ class BaseRecipe
12
14
  include FileUtils
13
15
  include FPM::Cookery::Utils
14
16
  include FPM::Cookery::PathHelper
@@ -56,43 +58,32 @@ module FPM
56
58
  attr_rw :arch, :description, :homepage, :maintainer, :md5, :name,
57
59
  :revision, :section, :sha1, :sha256, :spec, :vendor, :version,
58
60
  :pre_install, :post_install, :pre_uninstall, :post_uninstall,
59
- :license, :omnibus_package, :omnibus_dir
61
+ :license, :omnibus_package, :omnibus_dir, :chain_package
60
62
 
61
63
  attr_rw_list :build_depends, :config_files, :conflicts, :depends,
62
64
  :exclude, :patches, :provides, :replaces, :omnibus_recipes,
63
- :omnibus_additional_paths
65
+ :omnibus_additional_paths, :chain_recipes
64
66
 
65
- class << self
66
- def source(source = nil, spec = {})
67
- return @source if source.nil?
68
- @source = source
69
- @spec = spec
70
- end
71
- alias_method :url, :source
67
+ attr_reader :filename
72
68
 
69
+ class << self
73
70
  def platform
74
71
  FPM::Cookery::Facts.platform
75
72
  end
76
- end
77
73
 
78
- def source
79
- self.class.source
74
+ def depends_all
75
+ (depends + build_depends).uniq
76
+ end
80
77
  end
81
78
 
82
79
  def initialize(filename)
83
80
  @filename = Path.new(filename).expand_path
84
- @source_handler = SourceHandler.new(Source.new(source, spec), cachedir, builddir)
85
81
 
86
82
  # Set some defaults.
87
83
  vendor || self.class.vendor('fpm')
88
84
  revision || self.class.revision(0)
89
85
  end
90
86
 
91
- attr_reader :filename, :source_handler
92
-
93
- extend Forwardable
94
- def_delegator :@source_handler, :local_path
95
-
96
87
  def workdir=(value) @workdir = Path.new(value) end
97
88
  def destdir=(value) @destdir = Path.new(value) end
98
89
  def builddir=(value) @builddir = Path.new(value) end
@@ -104,6 +95,55 @@ module FPM
104
95
  def builddir(path = nil) (@builddir ||= workdir('tmp-build'))/path end
105
96
  def pkgdir(path = nil) (@pkgdir ||= workdir('pkg'))/path end
106
97
  def cachedir(path = nil) (@cachedir ||= workdir('cache'))/path end
98
+
99
+ # Resolve dependencies from omnibus package.
100
+ def depends_all
101
+ pkg_depends = self.class.depends_all
102
+ if self.class.omnibus_package
103
+ self.class.omnibus_recipes.each { |omni_recipe|
104
+ Book.instance.load_recipe(File.expand_path(omni_recipe + '.rb', File.dirname(filename))) do |recipe|
105
+ pkg_depends << recipe.depends_all
106
+ end
107
+ }
108
+ end
109
+
110
+ pkg_depends.flatten.uniq
111
+ end
112
+ end
113
+
114
+ class Recipe < BaseRecipe
115
+ def input(config)
116
+ FPM::Cookery::Package::Dir.new(self, config)
117
+ end
118
+
119
+ def initialize(filename)
120
+ super(filename)
121
+ @source_handler = SourceHandler.new(Source.new(source, spec), cachedir, builddir)
122
+ end
123
+
124
+ class << self
125
+ def source(source = nil, spec = {})
126
+ return @source if source.nil?
127
+ @source = source
128
+ @spec = spec
129
+ end
130
+ alias_method :url, :source
131
+ end
132
+
133
+ def source
134
+ self.class.source
135
+ end
136
+
137
+ attr_reader :source_handler
138
+
139
+ extend Forwardable
140
+ def_delegator :@source_handler, :local_path
141
+ end
142
+
143
+ class RubyGemRecipe < BaseRecipe
144
+ def input(config)
145
+ FPM::Cookery::Package::Gem.new(self, config)
146
+ end
107
147
  end
108
148
  end
109
149
  end
@@ -0,0 +1,35 @@
1
+ require 'fpm/cookery/log'
2
+ require 'systemu'
3
+
4
+ module FPM
5
+ module Cookery
6
+ class Shellout
7
+ class CommandFailed < StandardError
8
+ attr_reader :output
9
+
10
+ def initialize(message, output)
11
+ super(message)
12
+ @output = output
13
+ end
14
+ end
15
+
16
+ def self.git_config_get(key)
17
+ new('git config --get %s', key).run.chomp
18
+ end
19
+
20
+ def initialize(command, *args)
21
+ @command = command.to_s % args
22
+ end
23
+
24
+ def run
25
+ status, stdout, stderr = systemu(@command)
26
+
27
+ if status.success?
28
+ stdout
29
+ else
30
+ raise CommandFailed.new("Shellout command failed: #{@command}", stderr)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -44,7 +44,11 @@ module FPM
44
44
  private
45
45
  def curl(url, path)
46
46
  args = options[:args] || '-fL'
47
- safesystem('curl', args, '--progress-bar', '-o', path, url)
47
+ cmd = ['curl', args, '--progress-bar', '-o', path, url]
48
+ safesystem(*cmd)
49
+ rescue RuntimeError => e
50
+ Log.error("Command failed: #{cmd.join(' ')}")
51
+ raise
48
52
  end
49
53
 
50
54
  def extracted_source
@@ -52,7 +56,13 @@ module FPM
52
56
 
53
57
  case entries.size
54
58
  when 0
55
- raise "Empty archive! (#{local_path})"
59
+ files = Dir['*'].select {|dir| File.file?(dir) }
60
+
61
+ if files.size > 0
62
+ builddir
63
+ else
64
+ raise "Empty archive! (#{local_path})"
65
+ end
56
66
  when 1
57
67
  entries.first
58
68
  else
@@ -1,5 +1,5 @@
1
1
  module FPM
2
2
  module Cookery
3
- VERSION = '0.15.0'
3
+ VERSION = '0.16.0'
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ class ArrPmRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'arr-pm'
3
+ version '0.0.7'
4
+ end
@@ -0,0 +1,4 @@
1
+ class BackportsRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'backports'
3
+ version '2.6.2'
4
+ end
@@ -0,0 +1,4 @@
1
+ class CabinRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'cabin'
3
+ version '0.6.0'
4
+ end
@@ -0,0 +1,4 @@
1
+ class ClampRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'clamp'
3
+ version '0.3.1'
4
+ end
@@ -0,0 +1,4 @@
1
+ class FacterRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'facter'
3
+ version '1.6.16'
4
+ end
@@ -0,0 +1,4 @@
1
+ class AddressableRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "addressable"
3
+ version "2.3.5"
4
+ end
@@ -0,0 +1,4 @@
1
+ class ArrPmRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "arr-pm"
3
+ version "0.0.8"
4
+ end
@@ -0,0 +1,4 @@
1
+ class BackportsRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "backports"
3
+ version "2.6.2"
4
+ end
@@ -0,0 +1,4 @@
1
+ class CabinRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "cabin"
3
+ version "0.6.0"
4
+ end
@@ -0,0 +1,7 @@
1
+ class ChildprocessRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "childprocess"
3
+ version "0.3.9"
4
+
5
+ chain_package true
6
+ chain_recipes "ffi"
7
+ end
@@ -0,0 +1,4 @@
1
+ class ClampRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "clamp"
3
+ version "0.6.0"
4
+ end
@@ -0,0 +1,4 @@
1
+ class FacterRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "facter"
3
+ version "1.7.1"
4
+ end
@@ -0,0 +1,4 @@
1
+ class FfiRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "ffi"
3
+ version "1.0.11"
4
+ end
@@ -0,0 +1,7 @@
1
+ class FpmRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "fpm"
3
+ version "0.4.39"
4
+
5
+ chain_package true
6
+ chain_recipes "json", "cabin", "backports", "arr-pm", "clamp", "childprocess", "ftw"
7
+ end
@@ -0,0 +1,7 @@
1
+ class FtwRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "ftw"
3
+ version "0.0.34"
4
+
5
+ chain_package true
6
+ chain_recipes "http_parser.rb"
7
+ end
@@ -0,0 +1,7 @@
1
+ class HieraRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "hiera"
3
+ version "1.2.1"
4
+
5
+ chain_package true
6
+ chain_recipes "json_pure"
7
+ end
@@ -0,0 +1,4 @@
1
+ class HttpParserRbRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "http_parser.rb"
3
+ version "0.5.3"
4
+ end
@@ -0,0 +1,4 @@
1
+ class JsonRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'json'
3
+ version '1.7.7'
4
+ end
@@ -0,0 +1,4 @@
1
+ class JsonPureRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "json_pure"
3
+ version "1.7.7"
4
+ end
@@ -0,0 +1,7 @@
1
+ class PuppetRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "puppet"
3
+ version "3.2.2"
4
+
5
+ chain_package true
6
+ chain_recipes "hiera", "rgen"
7
+ end
@@ -0,0 +1,7 @@
1
+ class FpmCookeryRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "fpm-cookery"
3
+ version "0.15.0"
4
+
5
+ chain_package true
6
+ chain_recipes "fpm", "facter", "puppet", "addressable"
7
+ end
@@ -0,0 +1,4 @@
1
+ class RgenRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name "rgen"
3
+ version "0.6.5"
4
+ end
@@ -2,7 +2,7 @@ class FPMCookery < FPM::Cookery::Recipe
2
2
  description 'building packages'
3
3
 
4
4
  name 'fpm-cookery'
5
- version '0.14.0'
5
+ version '0.15.0'
6
6
  revision 0
7
7
  homepage 'https://github.com/bernd/fpm-cookery'
8
8
  license 'MIT'
@@ -2,22 +2,32 @@ class Ruby200 < FPM::Cookery::Recipe
2
2
  description 'The Ruby virtual machine'
3
3
 
4
4
  name 'ruby'
5
- version '2.0.0.195'
5
+ version '2.0.0.247'
6
6
  revision 0
7
7
  homepage 'http://www.ruby-lang.org/'
8
- source 'http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.bz2'
9
- sha256 '0be32aef7a7ab6e3708cc1d65cd3e0a99fa801597194bbedd5799c11d652eb5b'
8
+ source 'http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.bz2'
9
+ sha256 '08e3d4b85b8a1118a8e81261f59dd8b4ddcfd70b6ae554e0ec5ceb99c3185e8a'
10
10
 
11
11
  license 'The Ruby License'
12
12
  section 'interpreters'
13
13
 
14
- build_depends 'autoconf', 'libreadline6-dev', 'bison', 'zlib1g-dev',
15
- 'libssl-dev', 'libyaml-dev', 'libffi-dev', 'libgdbm-dev',
16
- 'libncurses5-dev', 'libreadline6-dev'
14
+ platforms [:ubuntu, :debian] do
15
+ build_depends 'autoconf', 'libreadline6-dev', 'bison', 'zlib1g-dev',
16
+ 'libssl-dev', 'libyaml-dev', 'libffi-dev', 'libgdbm-dev',
17
+ 'libncurses5-dev', 'libreadline6-dev'
18
+ depends 'libffi6', 'libncurses5', 'libreadline6', 'libssl1.0.0',
19
+ 'libtinfo5', 'libyaml-0-2', 'zlib1g', 'libffi6', 'libgdbm3',
20
+ 'libncurses5', 'libreadline6'
21
+ end
17
22
 
18
- depends 'libffi6', 'libncurses5', 'libreadline6', 'libssl1.0.0',
19
- 'libtinfo5', 'libyaml-0-2', 'zlib1g', 'libffi6', 'libgdbm3',
20
- 'libncurses5', 'libreadline6'
23
+ platforms [:fedora, :redhat, :centos] do
24
+ build_depends 'rpmdevtools', 'libffi-devel', 'autoconf', 'bison',
25
+ 'libxml2-devel', 'libxslt-devel', 'openssl-devel',
26
+ 'gdbm-devel', 'zlib-devel'
27
+ depends 'zlib', 'libffi', 'gdbm'
28
+ end
29
+ platforms [:fedora] do depends.push('openssl-libs') end
30
+ platforms [:redhat, :centos] do depends.push('openssl') end
21
31
 
22
32
  def build
23
33
  configure :prefix => destdir,
@@ -32,6 +42,6 @@ class Ruby200 < FPM::Cookery::Recipe
32
42
  # Shrink package.
33
43
  rm_f "#{destdir}/lib/libruby-static.a"
34
44
  safesystem "strip #{destdir}/bin/ruby"
35
- safesystem "find #{destdir} -name '*.so*' | xargs strip"
45
+ safesystem "find #{destdir} -name '*.so' -or -name '*.so.*' | xargs strip"
36
46
  end
37
47
  end
@@ -0,0 +1,4 @@
1
+ class FpmRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'fpm'
3
+ version '0.4.29'
4
+ end
@@ -0,0 +1,4 @@
1
+ class JsonRubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'json'
3
+ version '1.6.6'
4
+ end
@@ -0,0 +1,4 @@
1
+ class Open4RubyGem < FPM::Cookery::RubyGemRecipe
2
+ name 'open4'
3
+ version '1.3.0'
4
+ end
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+ require 'fpm/cookery/config'
3
+ require 'fpm/cookery/cli'
4
+
5
+ describe 'Config' do
6
+ let(:data) { {} }
7
+ let(:default_config) { FPM::Cookery::Config.new }
8
+ let(:config) { FPM::Cookery::Config.new(data) }
9
+
10
+ def self.common_tests(name)
11
+ it 'can be set on init' do
12
+ data[name.to_sym] = '__set__'
13
+
14
+ config.__send__(name).must_equal '__set__'
15
+ end
16
+
17
+ it 'can be set' do
18
+ config.__send__("#{name}=", '__SET__')
19
+ config.__send__(name).must_equal '__SET__'
20
+ end
21
+
22
+ it 'provides a ? method' do
23
+ data[name.to_sym] = false
24
+
25
+ config.__send__("#{name}?").must_equal false
26
+ end
27
+ end
28
+
29
+ describe '#color' do
30
+ it 'defaults to true' do
31
+ default_config.color.must_equal true
32
+ end
33
+
34
+ common_tests(:color)
35
+ end
36
+
37
+ describe '#debug' do
38
+ it 'defaults to true' do
39
+ default_config.debug.must_equal false
40
+ end
41
+
42
+ common_tests(:debug)
43
+ end
44
+
45
+ describe '#target' do
46
+ it 'defaults to nil' do
47
+ default_config.target.must_equal nil
48
+ end
49
+
50
+ common_tests(:target)
51
+ end
52
+
53
+ describe '#platform' do
54
+ it 'defaults to nil' do
55
+ default_config.platform.must_equal nil
56
+ end
57
+
58
+ common_tests(:platform)
59
+ end
60
+
61
+ describe '#maintainer' do
62
+ it 'defaults to nil' do
63
+ default_config.maintainer.must_equal nil
64
+ end
65
+
66
+ common_tests(:maintainer)
67
+ end
68
+
69
+ describe '#vendor' do
70
+ it 'defaults to nil' do
71
+ default_config.vendor.must_equal nil
72
+ end
73
+
74
+ common_tests(:vendor)
75
+ end
76
+
77
+ describe '#skip_package' do
78
+ it 'defaults to false' do
79
+ default_config.skip_package.must_equal false
80
+ end
81
+
82
+ common_tests(:skip_package)
83
+ end
84
+
85
+ describe '#keep_destdir' do
86
+ it 'defaults to false' do
87
+ default_config.keep_destdir.must_equal false
88
+ end
89
+
90
+ common_tests(:keep_destdir)
91
+ end
92
+
93
+ describe '#dependency_check' do
94
+ it 'defaults to false' do
95
+ default_config.dependency_check.must_equal true
96
+ end
97
+
98
+ common_tests(:dependency_check)
99
+ end
100
+
101
+ describe '#to_hash' do
102
+ it 'returns a hash representation of the object' do
103
+ default_config.to_hash.must_equal({
104
+ :color => true,
105
+ :debug => false,
106
+ :target => nil,
107
+ :platform => nil,
108
+ :maintainer => nil,
109
+ :vendor => nil,
110
+ :skip_package => false,
111
+ :keep_destdir => false,
112
+ :dependency_check => true
113
+ })
114
+ end
115
+ end
116
+
117
+ describe 'with an invalid config key' do
118
+ it 'raises an error' do
119
+ data[:__foo__] = true
120
+
121
+ proc { config }.must_raise FPM::Cookery::Error::InvalidConfigKey
122
+ end
123
+
124
+ it 'adds the invalid keys' do
125
+ data[:__foo__] = true
126
+ data[:__bar__] = true
127
+ error = nil
128
+
129
+ begin; config; rescue => e; error = e; end
130
+
131
+ error.invalid_keys.must_equal [:__foo__, :__bar__]
132
+ end
133
+
134
+ it 'works with strings' do
135
+ data['maintainer'] = 'John'
136
+
137
+ config.maintainer.must_equal 'John'
138
+ end
139
+ end
140
+
141
+ describe '.load_file' do
142
+ let(:paths) do
143
+ [
144
+ '/tmp/__abc__',
145
+ File.expand_path('../fixtures/test-config-1.yml', __FILE__)
146
+ ]
147
+ end
148
+
149
+ it 'loads first found file' do
150
+ config = FPM::Cookery::Config.load_file(paths)
151
+
152
+ config.maintainer.must_equal 'John Doe <john@example.com>'
153
+ end
154
+ end
155
+
156
+ describe '.from_cli' do
157
+ it 'loads the config from cli options' do
158
+ cli = FPM::Cookery::CLI.new('path', {})
159
+ cli.parse(%w(-D -t rpm))
160
+
161
+ config = FPM::Cookery::Config.from_cli(cli)
162
+
163
+ config.debug.must_equal true
164
+ config.target.must_equal 'rpm'
165
+ end
166
+ end
167
+ end