fpm-cookery 0.32.0 → 0.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +5 -2
- data/CHANGELOG.md +19 -0
- data/Rakefile +34 -0
- data/docs/index.rst +1 -0
- data/docs/pages/using-hiera.rst +285 -0
- data/fpm-cookery.gemspec +6 -1
- data/lib/fpm/cookery/book.rb +29 -2
- data/lib/fpm/cookery/book_hook.rb +1 -0
- data/lib/fpm/cookery/chain_packager.rb +4 -2
- data/lib/fpm/cookery/cli.rb +45 -5
- data/lib/fpm/cookery/config.rb +2 -1
- data/lib/fpm/cookery/environment.rb +17 -8
- data/lib/fpm/cookery/exceptions.rb +3 -1
- data/lib/fpm/cookery/facts.rb +50 -35
- data/lib/fpm/cookery/hiera.rb +35 -0
- data/lib/fpm/cookery/hiera/defaults.rb +50 -0
- data/lib/fpm/cookery/hiera/scope.rb +35 -0
- data/lib/fpm/cookery/inheritable_attr.rb +222 -0
- data/lib/fpm/cookery/log/hiera.rb +21 -0
- data/lib/fpm/cookery/omnibus_packager.rb +4 -2
- data/lib/fpm/cookery/package/package.rb +1 -0
- data/lib/fpm/cookery/package/version.rb +11 -4
- data/lib/fpm/cookery/packager.rb +13 -11
- data/lib/fpm/cookery/recipe.rb +167 -105
- data/lib/fpm/cookery/source.rb +6 -8
- data/lib/fpm/cookery/source_handler.rb +18 -3
- data/lib/fpm/cookery/source_handler/curl.rb +2 -2
- data/lib/fpm/cookery/source_handler/directory.rb +10 -11
- data/lib/fpm/cookery/source_handler/noop.rb +1 -2
- data/lib/fpm/cookery/source_handler/svn.rb +1 -1
- data/lib/fpm/cookery/version.rb +1 -1
- data/lib/hiera/fpm_cookery_logger.rb +12 -0
- data/recipes/redis/config/common.yaml +11 -0
- data/recipes/redis/config/git_2.4.2_tag.yaml +4 -0
- data/recipes/redis/config/git_2.4.yaml +4 -0
- data/recipes/redis/config/git_sha_072a905.yaml +4 -0
- data/recipes/redis/config/svn_r2400.yaml +4 -0
- data/recipes/redis/config/svn_trunk.yaml +3 -0
- data/recipes/redis/recipe.rb +2 -27
- data/spec/book_spec.rb +34 -0
- data/spec/config_spec.rb +19 -0
- data/spec/environment_spec.rb +37 -0
- data/spec/facts_spec.rb +54 -31
- data/spec/fixtures/hiera_config/CentOS.yaml +1 -0
- data/spec/fixtures/hiera_config/common.yaml +12 -0
- data/spec/fixtures/hiera_config/custom.yaml +3 -0
- data/spec/fixtures/hiera_config/rpm.yaml +12 -0
- data/spec/hiera_spec.rb +158 -0
- data/spec/inheritable_attr_spec.rb +202 -0
- data/spec/package_dir_spec.rb +37 -0
- data/spec/package_maintainer_spec.rb +4 -1
- data/spec/package_version_spec.rb +50 -0
- data/spec/path_spec.rb +20 -0
- data/spec/recipe_spec.rb +161 -56
- data/spec/source_integrity_check_spec.rb +7 -6
- data/spec/spec_helper.rb +14 -0
- data/spec/support/shared_context.rb +71 -0
- metadata +108 -4
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'hiera'
|
2
|
+
require 'fpm/cookery/log'
|
3
|
+
|
4
|
+
module FPM
|
5
|
+
module Cookery
|
6
|
+
module Log
|
7
|
+
module Hiera
|
8
|
+
extend SingleForwardable
|
9
|
+
|
10
|
+
# These are the methods that Hiera requires to be defined
|
11
|
+
def_delegators FPM::Cookery::Log, :warn, :debug
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def suitable?
|
16
|
+
defined?(::FPM::Cookery) == "constant"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'fpm/cookery/packager'
|
2
2
|
require 'fpm/cookery/facts'
|
3
|
+
require 'fpm/cookery/exceptions'
|
3
4
|
|
4
5
|
module FPM
|
5
6
|
module Cookery
|
@@ -21,8 +22,9 @@ module FPM
|
|
21
22
|
recipe_file = build_recipe_file_path(name)
|
22
23
|
Log.info "Loading dependency recipe #{name} from #{recipe_file}"
|
23
24
|
unless File.exists?(recipe_file)
|
24
|
-
|
25
|
-
|
25
|
+
error_message = "Cannot find a recipe for #{name} at #{recipe_file}"
|
26
|
+
Log.fatal error_message
|
27
|
+
raise Error::ExecutionFailure, error_message
|
26
28
|
end
|
27
29
|
|
28
30
|
FPM::Cookery::Book.instance.load_recipe(recipe_file, config) do |dep_recipe|
|
@@ -33,6 +33,7 @@ module FPM
|
|
33
33
|
@fpm.attributes[:rpm_group] = 'root'
|
34
34
|
@fpm.attributes[:rpm_defattrfile] = '-'
|
35
35
|
@fpm.attributes[:rpm_defattrdir] = '-'
|
36
|
+
@fpm.attributes[:rpm_dist] = recipe.rpm_dist.to_s if recipe.rpm_dist
|
36
37
|
@fpm.attributes[:excludes] = recipe.exclude
|
37
38
|
|
38
39
|
# Package type specific code should be called in package_setup.
|
@@ -16,7 +16,11 @@ module FPM
|
|
16
16
|
:default => '-'
|
17
17
|
}
|
18
18
|
|
19
|
-
|
19
|
+
# fpm sets the default version in FPM::Command; since we bypass the
|
20
|
+
# command line interface, we need to set our own value.
|
21
|
+
DEFAULT_VERSION = '1.0'
|
22
|
+
|
23
|
+
attr_reader :epoch, :revision
|
20
24
|
|
21
25
|
def initialize(recipe, target, config)
|
22
26
|
@recipe = recipe
|
@@ -30,11 +34,16 @@ module FPM
|
|
30
34
|
@config[:vendor] || @recipe.vendor
|
31
35
|
end
|
32
36
|
|
37
|
+
def version
|
38
|
+
@version ||= DEFAULT_VERSION
|
39
|
+
end
|
40
|
+
|
33
41
|
def revision_delimiter
|
34
42
|
REVISION_DELIMITER[:default]
|
35
43
|
end
|
36
44
|
|
37
45
|
def vendor_delimiter
|
46
|
+
return @config[:vendor_delimiter] if @config[:vendor_delimiter]
|
38
47
|
VENDOR_DELIMITER[@target.to_sym] || VENDOR_DELIMITER[:default]
|
39
48
|
end
|
40
49
|
|
@@ -49,9 +58,7 @@ module FPM
|
|
49
58
|
private
|
50
59
|
|
51
60
|
def split_version(version)
|
52
|
-
|
53
|
-
|
54
|
-
version.nil? ? [epoch, nil] : [version, epoch]
|
61
|
+
(version || '').split(':', 2).reject(&:empty?).reverse
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
data/lib/fpm/cookery/packager.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#require 'digest/md5'
|
2
2
|
#require 'fpm/cookery/recipe_inspector'
|
3
3
|
require 'fpm/cookery/dependency_inspector'
|
4
|
+
require 'fpm/cookery/exceptions'
|
4
5
|
require 'fpm/cookery/utils'
|
5
6
|
require 'fpm/cookery/source_integrity_check'
|
6
7
|
require 'fpm/cookery/path'
|
@@ -57,10 +58,12 @@ module FPM
|
|
57
58
|
Log.info("All dependencies installed!")
|
58
59
|
end
|
59
60
|
|
61
|
+
def package_name
|
62
|
+
[recipe.name, recipe.version, recipe.revision].compact.join('-')
|
63
|
+
end
|
60
64
|
|
61
65
|
def dispense
|
62
66
|
env = ENV.to_hash
|
63
|
-
package_name = "#{recipe.name}-#{recipe.version}"
|
64
67
|
platform = FPM::Cookery::Facts.platform
|
65
68
|
target = FPM::Cookery::Facts.target
|
66
69
|
|
@@ -76,9 +79,7 @@ module FPM
|
|
76
79
|
|
77
80
|
recipe.installing = false
|
78
81
|
|
79
|
-
if
|
80
|
-
source = recipe.source_handler
|
81
|
-
|
82
|
+
if (source = recipe.source_handler).fetchable?
|
82
83
|
recipe.cachedir.mkdir
|
83
84
|
Dir.chdir(recipe.cachedir) do
|
84
85
|
recipe.run_lifecycle_hook(:before_source_download)
|
@@ -105,7 +106,7 @@ module FPM
|
|
105
106
|
Filename: #{check.filename}
|
106
107
|
|
107
108
|
__ERROR
|
108
|
-
|
109
|
+
raise Error::ExecutionFailure, 'checksums do not match'
|
109
110
|
end #end checksum missing
|
110
111
|
end #end check
|
111
112
|
end #end checksum
|
@@ -114,7 +115,7 @@ module FPM
|
|
114
115
|
recipe.builddir.mkdir
|
115
116
|
Dir.chdir(recipe.builddir) do
|
116
117
|
recipe.run_lifecycle_hook(:before_source_extraction)
|
117
|
-
extract_cookie = extract_cookie_name
|
118
|
+
extract_cookie = extract_cookie_name
|
118
119
|
|
119
120
|
# Do not extract source again because it might destroy changes
|
120
121
|
# that have been made to the source. (like patches)
|
@@ -132,7 +133,7 @@ module FPM
|
|
132
133
|
end
|
133
134
|
|
134
135
|
# Make the path to the extracted source available in the recipe.
|
135
|
-
recipe.sourcedir =
|
136
|
+
recipe.sourcedir = extracted_source
|
136
137
|
recipe.run_lifecycle_hook(:after_source_extraction, recipe.sourcedir)
|
137
138
|
|
138
139
|
Log.info "Using source directory: #{extracted_source}"
|
@@ -148,7 +149,8 @@ module FPM
|
|
148
149
|
else
|
149
150
|
recipe.run_lifecycle_hook(:before_build)
|
150
151
|
Log.info "Building in #{File.expand_path(extracted_source, recipe.builddir)}"
|
151
|
-
recipe.build
|
152
|
+
recipe.build
|
153
|
+
FileUtils.touch(build_cookie)
|
152
154
|
recipe.run_lifecycle_hook(:after_build)
|
153
155
|
end
|
154
156
|
|
@@ -178,11 +180,11 @@ module FPM
|
|
178
180
|
ENV.replace(env)
|
179
181
|
end
|
180
182
|
|
181
|
-
def extract_cookie_name(name)
|
183
|
+
def extract_cookie_name(name = package_name)
|
182
184
|
(recipe.builddir/".extract-cookie-#{name.gsub(/[^\w]/,'_')}").to_s
|
183
185
|
end
|
184
186
|
|
185
|
-
def build_cookie_name(name)
|
187
|
+
def build_cookie_name(name = package_name)
|
186
188
|
(recipe.builddir/".build-cookie-#{name.gsub(/[^\w]/,'_')}").to_s
|
187
189
|
end
|
188
190
|
|
@@ -244,7 +246,7 @@ module FPM
|
|
244
246
|
end
|
245
247
|
end
|
246
248
|
|
247
|
-
|
249
|
+
raise Error::ExecutionFailure, 'failed to locate all scripts' if error
|
248
250
|
end
|
249
251
|
end
|
250
252
|
end
|
data/lib/fpm/cookery/recipe.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
require 'erb'
|
1
2
|
require 'forwardable'
|
2
3
|
require 'fileutils'
|
4
|
+
require 'json'
|
3
5
|
require 'fpm/cookery/facts'
|
6
|
+
require 'fpm/cookery/hiera'
|
7
|
+
require 'fpm/cookery/inheritable_attr'
|
4
8
|
require 'fpm/cookery/source'
|
5
9
|
require 'fpm/cookery/source_handler'
|
6
10
|
require 'fpm/cookery/utils'
|
7
11
|
require 'fpm/cookery/path_helper'
|
8
12
|
require 'fpm/cookery/environment'
|
9
13
|
require 'fpm/cookery/lifecycle_hooks'
|
14
|
+
require 'fpm/cookery/log'
|
10
15
|
require 'fpm/cookery/package/cpan'
|
11
16
|
require 'fpm/cookery/package/dir'
|
12
17
|
require 'fpm/cookery/package/gem'
|
@@ -24,67 +29,42 @@ module FPM
|
|
24
29
|
include FPM::Cookery::PathHelper
|
25
30
|
include FPM::Cookery::LifecycleHooks
|
26
31
|
|
27
|
-
|
28
|
-
attrs.each do |attr|
|
29
|
-
class_eval %Q{
|
30
|
-
def self.#{attr}(value = nil)
|
31
|
-
value.nil? ? @#{attr} : @#{attr} = value
|
32
|
-
end
|
33
|
-
|
34
|
-
def #{attr}
|
35
|
-
self.class.#{attr}
|
36
|
-
end
|
37
|
-
}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.inherited(klass)
|
42
|
-
super
|
43
|
-
# Apply class data inheritable pattern to @fpm_attributes
|
44
|
-
# class variable.
|
45
|
-
klass.instance_variable_set(:@fpm_attributes, self.fpm_attributes.dup)
|
46
|
-
klass.instance_variable_set(:@environment, self.environment.dup)
|
47
|
-
end
|
32
|
+
extend FPM::Cookery::InheritableAttr
|
48
33
|
|
49
|
-
|
50
|
-
Array(valid_platforms).member?(self.platform) and block_given? ? yield : false
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.architectures(archs)
|
54
|
-
Array(archs).member?(FPM::Cookery::Facts.arch) and block_given? ? yield : false
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.attr_rw_list(*attrs)
|
58
|
-
attrs.each do |attr|
|
59
|
-
class_eval %Q{
|
60
|
-
def self.#{attr}(*list)
|
61
|
-
@#{attr} ||= []
|
62
|
-
@#{attr} << list
|
63
|
-
@#{attr}.flatten!
|
64
|
-
@#{attr}.uniq!
|
65
|
-
@#{attr}
|
66
|
-
end
|
67
|
-
|
68
|
-
def #{attr}
|
69
|
-
self.class.#{attr}
|
70
|
-
end
|
71
|
-
}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
attr_rw :arch, :description, :homepage, :maintainer, :md5, :name,
|
34
|
+
attr_rw :arch, :description, :rpm_dist, :homepage, :maintainer, :md5, :name,
|
76
35
|
:revision, :section, :sha1, :sha256, :spec, :vendor, :version,
|
77
36
|
:pre_install, :post_install, :pre_uninstall, :post_uninstall,
|
78
37
|
:license, :omnibus_package, :omnibus_dir, :chain_package,
|
79
38
|
:default_prefix
|
80
39
|
|
81
|
-
attr_rw_list
|
82
|
-
|
83
|
-
|
40
|
+
attr_rw_list :build_depends, :config_files, :conflicts, :depends,
|
41
|
+
:exclude, :patches, :provides, :replaces, :omnibus_recipes,
|
42
|
+
:omnibus_additional_paths, :chain_recipes,
|
43
|
+
:directories
|
44
|
+
|
45
|
+
attr_rw_hash :fpm_attributes, :environment
|
84
46
|
|
85
|
-
|
47
|
+
attr_rw_path :workdir, :tmp_root, :destdir, :builddir, :pkgdir,
|
48
|
+
:cachedir, :datadir
|
86
49
|
|
87
50
|
class << self
|
51
|
+
# Make sure that +Recipe+ classes responds to these methods, but issue
|
52
|
+
# an exception to inform the caller that they are expected to define
|
53
|
+
# them.
|
54
|
+
[:filename, :config].each do |m|
|
55
|
+
define_method m do
|
56
|
+
raise NotImplementedError, "`.#{__method__}' must be defined when recipe file is loaded"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def platforms(valid_platforms)
|
61
|
+
Array(valid_platforms).member?(self.platform) and block_given? ? yield : false
|
62
|
+
end
|
63
|
+
|
64
|
+
def architectures(archs)
|
65
|
+
Array(archs).member?(FPM::Cookery::Facts.arch) and block_given? ? yield : false
|
66
|
+
end
|
67
|
+
|
88
68
|
def platform
|
89
69
|
FPM::Cookery::Facts.platform
|
90
70
|
end
|
@@ -93,48 +73,36 @@ module FPM
|
|
93
73
|
(depends + build_depends).uniq
|
94
74
|
end
|
95
75
|
|
96
|
-
|
97
|
-
|
98
|
-
# fpm_attributes :xxxx=>1, :yyyy=>2
|
99
|
-
def fpm_attributes(args=nil)
|
100
|
-
if args.is_a?(Hash)
|
101
|
-
@fpm_attributes.merge!(args)
|
102
|
-
end
|
103
|
-
@fpm_attributes
|
76
|
+
def workdir(path = nil)
|
77
|
+
(@workdir ||= Path.new(filename).dirname)/path
|
104
78
|
end
|
105
79
|
|
106
|
-
def
|
107
|
-
@
|
80
|
+
def tmp_root(path = nil)
|
81
|
+
(@tmp_root ||= config.tmp_root ? Path.new(config.tmp_root) : workdir)/path
|
82
|
+
end
|
83
|
+
|
84
|
+
def pkgdir(path = nil)
|
85
|
+
(@pkgdir ||= config.pkg_dir ? Path.new(config.pkg_dir) : workdir('pkg'))/path
|
86
|
+
end
|
87
|
+
|
88
|
+
def cachedir(path = nil)
|
89
|
+
(@cachedir ||= config.cache_dir ? Path.new(config.cache_dir) : workdir('cache'))/path
|
90
|
+
end
|
91
|
+
|
92
|
+
def datadir(path = nil)
|
93
|
+
(@datadir ||= config.data_dir ? Path.new(config.data_dir) : workdir('config'))/path
|
108
94
|
end
|
109
|
-
end
|
110
|
-
@fpm_attributes = {}
|
111
|
-
@environment = FPM::Cookery::Environment.new
|
112
95
|
|
113
|
-
|
114
|
-
|
115
|
-
|
96
|
+
def destdir(path = nil)
|
97
|
+
(@destdir ||= tmp_root('tmp-dest'))/path
|
98
|
+
end
|
116
99
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@cachedir = @config.cache_dir && Path.new(@config.cache_dir)
|
100
|
+
def builddir(path = nil)
|
101
|
+
(@builddir ||= tmp_root('tmp-build'))/path
|
102
|
+
end
|
121
103
|
end
|
122
104
|
|
123
|
-
|
124
|
-
def tmp_root=(value) @tmp_root = Path.new(value) end
|
125
|
-
def destdir=(value) @destdir = Path.new(value) end
|
126
|
-
def builddir=(value) @builddir = Path.new(value) end
|
127
|
-
def pkgdir=(value) @pkgdir = Path.new(value) end
|
128
|
-
def cachedir=(value) @cachedir = Path.new(value) end
|
129
|
-
|
130
|
-
def workdir(path = nil) @workdir/path end
|
131
|
-
def tmp_root(path = nil) @tmp_root/path end
|
132
|
-
def destdir(path = nil) (@destdir || tmp_root('tmp-dest'))/path end
|
133
|
-
def builddir(path = nil) (@builddir || tmp_root('tmp-build'))/path end
|
134
|
-
def pkgdir(path = nil) (@pkgdir || workdir('pkg'))/path end
|
135
|
-
def cachedir(path = nil) (@cachedir || workdir('cache'))/path end
|
136
|
-
def fpm_attributes() self.class.fpm_attributes end
|
137
|
-
def environment() self.class.environment end
|
105
|
+
@environment = FPM::Cookery::Environment.new
|
138
106
|
|
139
107
|
# Resolve dependencies from omnibus package.
|
140
108
|
def depends_all
|
@@ -151,23 +119,60 @@ module FPM
|
|
151
119
|
|
152
120
|
pkg_depends.flatten.uniq
|
153
121
|
end
|
122
|
+
|
123
|
+
extend Forwardable
|
124
|
+
# Delegate to class methods
|
125
|
+
def_instance_delegators :'self.class', :config, :filename
|
154
126
|
end
|
155
127
|
|
156
128
|
class Recipe < BaseRecipe
|
129
|
+
attr_rw_list :source
|
130
|
+
|
157
131
|
def input(config)
|
158
132
|
FPM::Cookery::Package::Dir.new(self, config)
|
159
133
|
end
|
160
134
|
|
161
|
-
def
|
162
|
-
|
163
|
-
|
135
|
+
def source_handler
|
136
|
+
@source_handler ||= SourceHandler.new(Source.new(source, spec), cachedir, builddir)
|
137
|
+
end
|
138
|
+
|
139
|
+
def initialize(defer_application = false)
|
140
|
+
# Note: this must be called prior to instantiating the +SourceHandler+,
|
141
|
+
# so that +source+ can be picked up if it is defined in a +Hiera+ #
|
142
|
+
# data file.
|
143
|
+
apply unless defer_application
|
144
|
+
end
|
145
|
+
|
146
|
+
def to_h
|
147
|
+
attr_registry.values.flatten.each_with_object({}) do |m, a|
|
148
|
+
a[m] = send(m) unless m == :attr_registry
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def to_json
|
153
|
+
JSON.unparse(to_h)
|
154
|
+
end
|
155
|
+
|
156
|
+
def to_pretty_json
|
157
|
+
JSON.pretty_generate(to_h)
|
158
|
+
end
|
159
|
+
|
160
|
+
def template(format)
|
161
|
+
renderer = ERB.new(format, nil, '-')
|
162
|
+
renderer.result(binding)
|
163
|
+
rescue NameError, NoMethodError => e
|
164
|
+
message = "Error evaluating format string: no attribute `#{e.name}' for recipe"
|
165
|
+
Log.error message
|
166
|
+
raise Error::ExecutionFailure, message
|
164
167
|
end
|
165
168
|
|
166
169
|
class << self
|
167
170
|
def source(source = nil, spec = {})
|
171
|
+
#puts "#=> SOURCE: #{@source.inspect}"
|
168
172
|
return @source if source.nil?
|
169
173
|
@source = source
|
170
174
|
@spec = spec
|
175
|
+
@source
|
171
176
|
end
|
172
177
|
alias_method :url, :source
|
173
178
|
|
@@ -175,51 +180,108 @@ module FPM
|
|
175
180
|
return @extracted_source if path.nil?
|
176
181
|
@extracted_source = path
|
177
182
|
end
|
178
|
-
end
|
179
183
|
|
180
|
-
|
181
|
-
|
182
|
-
|
184
|
+
def hiera
|
185
|
+
if !defined?(@hiera) or @hiera.nil?
|
186
|
+
begin
|
187
|
+
@hiera = FPM::Cookery::Hiera::Instance.new(self, :config => hiera_config)
|
188
|
+
rescue StandardError => e
|
189
|
+
error_message = "Encountered error loading Hiera: #{e.message}"
|
190
|
+
Log.fatal error_message
|
191
|
+
raise Error::ExecutionFailure, error_message
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
@hiera
|
196
|
+
end
|
197
|
+
|
198
|
+
# Iterates over all of the +*_attrs+ class methods, calling the
|
199
|
+
# relevant setter methods for all attributes which return non-+nil+
|
200
|
+
# results for +.lookup+.
|
201
|
+
# Note: Hiera does not provide access to a structure that represents
|
202
|
+
# the merged contents of all data files; interaction with the data must
|
203
|
+
# go through one channel, the +.lookup+ method. That is why we have to
|
204
|
+
# iterate over all of these attributes, rather than loading the data
|
205
|
+
# files into a hash and then calling only those methods for which a
|
206
|
+
# key-value pair is specified.
|
207
|
+
def apply
|
208
|
+
scalar_attrs.each { |m| applicator(m) { |r| send(m, r) } }
|
209
|
+
list_attrs.each { |m| applicator(m) { |r| send(m, *r) } }
|
210
|
+
hash_attrs.each { |m| applicator(m) { |r| send(m).merge!(r) } }
|
211
|
+
path_attrs.each { |m| applicator(m) { |r| send("#{m}=", r) } }
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
def hiera_hierarchy
|
216
|
+
hiera_hierarchy = (from_env = ENV['FPM_HIERARCHY']).nil? ? [] : from_env.split(':')
|
217
|
+
(hiera_hierarchy + [config.platform.to_s, config.target.to_s, 'common']).compact
|
218
|
+
end
|
219
|
+
|
220
|
+
def hiera_config
|
221
|
+
# Note: +Hiera.new+ takes either a hash of options (with the sole
|
222
|
+
# top-level key +:options+) or a string representing the path to a
|
223
|
+
# configuration file. If the `--hiera-config' flag was seen, return
|
224
|
+
# that; otherwise, construct a hash of sane defaults.
|
225
|
+
config.hiera_config || {
|
226
|
+
:yaml => { :datadir => datadir.to_s },
|
227
|
+
:json => { :datadir => datadir.to_s },
|
228
|
+
:hierarchy => hiera_hierarchy
|
229
|
+
}
|
230
|
+
end
|
183
231
|
|
184
|
-
|
185
|
-
|
232
|
+
def applicator(method)
|
233
|
+
if (result = lookup(method)).nil?
|
234
|
+
Log.debug("No result for `#{method}'")
|
235
|
+
return
|
236
|
+
end
|
237
|
+
|
238
|
+
Log.debug("Setting `#{method}' to `#{result}'")
|
239
|
+
Proc.new.call(result)
|
240
|
+
end
|
186
241
|
end
|
187
242
|
|
188
243
|
def sourcedir=(sourcedir)
|
189
244
|
@sourcedir = sourcedir
|
190
245
|
end
|
191
246
|
|
192
|
-
attr_reader :
|
247
|
+
attr_reader :sourcedir
|
193
248
|
|
194
249
|
extend Forwardable
|
195
|
-
|
250
|
+
def_instance_delegator :source_handler, :local_path
|
251
|
+
|
252
|
+
# Delegate to class methods
|
253
|
+
def_instance_delegators :'self.class', :source, :extracted_source,
|
254
|
+
:hiera, :lookup, :apply
|
255
|
+
|
256
|
+
extend SingleForwardable
|
257
|
+
def_single_delegator :hiera, :lookup
|
196
258
|
end
|
197
259
|
|
198
|
-
class RubyGemRecipe <
|
260
|
+
class RubyGemRecipe < Recipe
|
199
261
|
def input(config)
|
200
262
|
FPM::Cookery::Package::Gem.new(self, config)
|
201
263
|
end
|
202
264
|
end
|
203
265
|
|
204
|
-
class NPMRecipe <
|
266
|
+
class NPMRecipe < Recipe
|
205
267
|
def input(config)
|
206
268
|
FPM::Cookery::Package::NPM.new(self, config)
|
207
269
|
end
|
208
270
|
end
|
209
271
|
|
210
|
-
class PythonRecipe <
|
272
|
+
class PythonRecipe < Recipe
|
211
273
|
def input(config)
|
212
274
|
FPM::Cookery::Package::Python.new(self, config)
|
213
275
|
end
|
214
276
|
end
|
215
277
|
|
216
|
-
class CPANRecipe <
|
278
|
+
class CPANRecipe < Recipe
|
217
279
|
def input(config)
|
218
280
|
FPM::Cookery::Package::CPAN.new(self, config)
|
219
281
|
end
|
220
282
|
end
|
221
283
|
|
222
|
-
class PEARRecipe <
|
284
|
+
class PEARRecipe < Recipe
|
223
285
|
attr_rw :pear_package_name_prefix, :pear_channel, :pear_php_dir
|
224
286
|
|
225
287
|
def input(config)
|
@@ -227,10 +289,11 @@ module FPM
|
|
227
289
|
end
|
228
290
|
end
|
229
291
|
|
230
|
-
class VirtualenvRecipe <
|
292
|
+
class VirtualenvRecipe < Recipe
|
231
293
|
attr_rw :virtualenv_pypi, :virtualenv_install_location, :virtualenv_fix_name,
|
232
294
|
:virtualenv_pypi_extra_index_urls, :virtualenv_package_name_prefix,
|
233
295
|
:virtualenv_other_files_dir
|
296
|
+
|
234
297
|
def input(config)
|
235
298
|
FPM::Cookery::Package::Virtualenv.new(self, config)
|
236
299
|
end
|
@@ -238,7 +301,6 @@ module FPM
|
|
238
301
|
|
239
302
|
# Helps packaging a directory of content
|
240
303
|
class DirRecipe < Recipe
|
241
|
-
|
242
304
|
def input(config)
|
243
305
|
FPM::Cookery::Package::Dir.new(self, config)
|
244
306
|
end
|