Class: EY::Serverside::Deploy::Configuration
- Inherits:
-
Object
- Object
- EY::Serverside::Deploy::Configuration
show all
- Includes:
- Paths::LegacyHelpers
- Defined in:
- lib/engineyard-serverside/configuration.rb
Constant Summary
collapse
- DEFAULT_KEEP_RELEASES =
3
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
-
#active_revision ⇒ Object
-
#append_config_source(config_source) ⇒ Object
-
#check_database_adapter? ⇒ Boolean
-
#configuration ⇒ Object
(also: #c)
-
#configured_services ⇒ Object
-
#current_role ⇒ Object
-
#extra_bundle_install_options ⇒ Object
-
#fetch(key, *args, &block) ⇒ Object
Fetch a key from the config.
-
#fetch_deprecated(attr, replacement, default) ⇒ Object
-
#framework_env_names ⇒ Object
-
#framework_envs ⇒ Object
-
#has_database? ⇒ Boolean
The nodatabase.yml file is dropped by server configuration when there is no database in the cluster.
-
#has_key?(key) ⇒ Boolean
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
-
#latest_revision ⇒ Object
(also: #revision)
-
#load_ey_yml_data(data, shell) ⇒ Object
-
#load_source(klass, shell, uri) ⇒ Object
-
#method_missing(meth, *args, &blk) ⇒ Object
Delegate to the configuration objects.
-
#migrate? ⇒ Boolean
-
#node ⇒ Object
-
#paths ⇒ Object
Use [] to access attributes instead of calling methods so that we get nils instead of NoMethodError.
-
#precompile_assets? ⇒ Boolean
-
#precompile_assets_inferred? ⇒ Boolean
-
#previous_revision ⇒ Object
-
#reload_configuration! ⇒ Object
reset cached configuration hash.
-
#required_downtime_stack? ⇒ Boolean
Assume downtime required if stack is not specified (nil) just in case.
-
#respond_to?(meth, include_private = false) ⇒ Boolean
-
#role ⇒ Object
-
#rollback_paths! ⇒ Object
-
#ruby_version_command ⇒ Object
-
#set_framework_envs ⇒ Object
-
#skip_precompile_assets? ⇒ Boolean
-
#source(shell) ⇒ Object
Infer the deploy source strategy to use based on flag or default to specified strategy.
-
#string_keys(hsh) ⇒ Object
-
#system_version_command ⇒ Object
-
#to_json ⇒ Object
#all_releases, legacy_path_helper
Constructor Details
Returns a new instance of Configuration.
126
127
128
129
130
131
|
# File 'lib/engineyard-serverside/configuration.rb', line 126
def initialize(options)
opts = string_keys(options)
config = MultiJson.load(opts.delete("config") || "{}")
append_config_source opts append_config_source config end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
Delegate to the configuration objects
204
205
206
|
# File 'lib/engineyard-serverside/configuration.rb', line 204
def method_missing(meth, *args, &blk)
configuration.key?(meth.to_s) ? configuration.fetch(meth.to_s) : super
end
|
Class Method Details
.def_boolean_option(name, default = nil, &block) ⇒ Object
Calls def_option and adds a name? predicate method
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/engineyard-serverside/configuration.rb', line 28
def self.def_boolean_option(name, default=nil, &block)
key ||= name.to_s
define_method(name) do
if block
val = fetch(key) {instance_eval(&block)}
else
val = fetch(key, default)
end
not [false,nil,'false','nil'].include?(val) end
alias_method(:"#{name}?", name)
end
|
.def_option(name, default = nil, key = nil, &block) ⇒ Object
Defines a fetch method for the specified key. If no default and no block is specified, it means the key is required and if it’s accessed without a value, it should raise.
18
19
20
21
22
23
24
25
|
# File 'lib/engineyard-serverside/configuration.rb', line 18
def self.def_option(name, default=nil, key=nil, &block)
key ||= name.to_s
if block_given?
define_method(name) { fetch(key) {instance_eval(&block)} }
else
define_method(name) { fetch(key, default) }
end
end
|
.def_required_option(name, key = nil) ⇒ Object
Required options do not have a default value. An option being required does not mean that it is always supplied, it just means that if it is accessed and it does not exist, an error will be raised instead of returning a nil default value.
46
47
48
49
50
51
|
# File 'lib/engineyard-serverside/configuration.rb', line 46
def self.def_required_option(name, key=nil)
key ||= name.to_s
define_method(name) do
fetch(key) { raise "Required configuration option not found: #{key.inspect}" }
end
end
|
Instance Method Details
#[](key) ⇒ Object
191
192
193
194
195
196
197
|
# File 'lib/engineyard-serverside/configuration.rb', line 191
def [](key)
if respond_to?(key.to_sym)
send(key.to_sym)
else
configuration[key]
end
end
|
#active_revision ⇒ Object
282
283
284
|
# File 'lib/engineyard-serverside/configuration.rb', line 282
def active_revision
paths.active_revision.read.strip
end
|
#append_config_source(config_source) ⇒ Object
137
138
139
140
141
|
# File 'lib/engineyard-serverside/configuration.rb', line 137
def append_config_source(config_source)
@config_sources ||= []
@config_sources.unshift(config_source.dup)
reload_configuration!
end
|
#check_database_adapter? ⇒ Boolean
303
304
305
|
# File 'lib/engineyard-serverside/configuration.rb', line 303
def check_database_adapter?
!ignore_database_adapter_warning? && has_database?
end
|
#configuration ⇒ Object
Also known as:
c
143
144
145
|
# File 'lib/engineyard-serverside/configuration.rb', line 143
def configuration
@configuration ||= @config_sources.inject({}) {|low,high| low.merge(high)}
end
|
355
356
357
358
359
360
|
# File 'lib/engineyard-serverside/configuration.rb', line 355
def configured_services
services = YAML.load_file(paths.shared_services_yml.to_s)
services.respond_to?(:keys) && !services.empty? ? services.keys : nil
rescue
nil
end
|
#current_role ⇒ Object
315
316
317
|
# File 'lib/engineyard-serverside/configuration.rb', line 315
def current_role
current_roles.to_a.first
end
|
331
332
333
334
335
336
|
# File 'lib/engineyard-serverside/configuration.rb', line 331
def
opts = []
opts += ["--without", bundle_without] if bundle_without
opts += [bundle_options] if bundle_options
opts.flatten
end
|
#fetch(key, *args, &block) ⇒ Object
Fetch a key from the config. You must supply either a default second argument, or a default block
187
188
189
|
# File 'lib/engineyard-serverside/configuration.rb', line 187
def fetch(key, *args, &block)
configuration.fetch(key.to_s, *args, &block)
end
|
#fetch_deprecated(attr, replacement, default) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/engineyard-serverside/configuration.rb', line 53
def fetch_deprecated(attr, replacement, default)
called = false
result = fetch(attr) { called = true; default }
if !called @deprecation_warning ||= {}
@deprecation_warning[attr] ||= begin
EY::Serverside.deprecation_warning "The configuration key '#{attr}' is deprecated in favor of '#{replacement}'."
true
end
end
result
end
|
#framework_env_names ⇒ Object
319
320
321
|
# File 'lib/engineyard-serverside/configuration.rb', line 319
def framework_env_names
%w[RAILS_ENV RACK_ENV NODE_ENV MERB_ENV]
end
|
#framework_envs ⇒ Object
323
324
325
|
# File 'lib/engineyard-serverside/configuration.rb', line 323
def framework_envs
framework_env_names.map { |e| "#{e}=#{framework_env}" }.join(' ')
end
|
#has_database? ⇒ Boolean
The nodatabase.yml file is dropped by server configuration when there is no database in the cluster.
298
299
300
301
|
# File 'lib/engineyard-serverside/configuration.rb', line 298
def has_database?
paths.shared_config.join('database.yml').exist? &&
!paths.shared_config.join('nodatabase.yml').exist?
end
|
#has_key?(key) ⇒ Boolean
199
200
201
|
# File 'lib/engineyard-serverside/configuration.rb', line 199
def has_key?(key)
respond_to?(key.to_sym) || configuration.has_key?(key)
end
|
#latest_revision ⇒ Object
Also known as:
revision
286
287
288
|
# File 'lib/engineyard-serverside/configuration.rb', line 286
def latest_revision
paths.latest_revision.read.strip
end
|
#load_ey_yml_data(data, shell) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/engineyard-serverside/configuration.rb', line 154
def load_ey_yml_data(data, shell)
loaded = false
environments = data['environments']
if environments && environments[environment_name]
shell.substatus "ey.yml configuration loaded for environment #{environment_name.inspect}."
env_data = string_keys(environments[environment_name])
shell.debug "#{environment_name}:\n#{env_data.pretty_inspect}"
append_config_source(env_data) loaded = true
end
defaults = data['defaults']
if defaults
shell.substatus "ey.yml configuration loaded."
append_config_source(string_keys(defaults)) shell.debug "defaults:\n#{defaults.pretty_inspect}"
loaded = true
end
if loaded
true
else
shell.info "No matching ey.yml configuration found for environment #{environment_name.inspect}."
shell.debug "ey.yml:\n#{data.pretty_inspect}"
false
end
end
|
#load_source(klass, shell, uri) ⇒ Object
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/engineyard-serverside/configuration.rb', line 238
def load_source(klass, shell, uri)
klass.new(
shell,
:verbose => verbose,
:repository_cache => paths.repository_cache,
:app => app,
:uri => uri,
:ref => branch
)
end
|
#migrate? ⇒ Boolean
307
308
309
|
# File 'lib/engineyard-serverside/configuration.rb', line 307
def migrate?
!!migration_command
end
|
#node ⇒ Object
216
217
218
|
# File 'lib/engineyard-serverside/configuration.rb', line 216
def node
EY::Serverside.node
end
|
#paths ⇒ Object
Use [] to access attributes instead of calling methods so that we get nils instead of NoMethodError.
Rollback doesn’t know about the repository location (nor should it need to), but it would like to use #short_log_message.
254
255
256
257
258
259
260
261
262
|
# File 'lib/engineyard-serverside/configuration.rb', line 254
def paths
@paths ||= Paths.new({
:home => configuration['home_path'],
:app_name => app_name,
:deploy_root => configuration['deploy_to'],
:active_release => configuration['release_path'],
:repository_cache => configuration['repository_cache'],
})
end
|
#precompile_assets? ⇒ Boolean
342
343
344
|
# File 'lib/engineyard-serverside/configuration.rb', line 342
def precompile_assets?
precompile_assets == true || precompile_assets == "true"
end
|
#precompile_assets_inferred? ⇒ Boolean
338
339
340
|
# File 'lib/engineyard-serverside/configuration.rb', line 338
def precompile_assets_inferred?
precompile_assets.nil? || precompile_assets == "detect"
end
|
#previous_revision ⇒ Object
291
292
293
294
|
# File 'lib/engineyard-serverside/configuration.rb', line 291
def previous_revision
prev = paths.previous_revision
prev && prev.readable? && prev.read.strip
end
|
#reload_configuration! ⇒ Object
reset cached configuration hash
150
151
152
|
# File 'lib/engineyard-serverside/configuration.rb', line 150
def reload_configuration!
@configuration = nil
end
|
#required_downtime_stack? ⇒ Boolean
Assume downtime required if stack is not specified (nil) just in case.
351
352
353
|
# File 'lib/engineyard-serverside/configuration.rb', line 351
def required_downtime_stack?
[nil, 'nginx_mongrel', 'glassfish'].include? stack
end
|
#respond_to?(meth, include_private = false) ⇒ Boolean
208
209
210
|
# File 'lib/engineyard-serverside/configuration.rb', line 208
def respond_to?(meth, include_private=false)
configuration.key?(meth.to_s) || super
end
|
#role ⇒ Object
311
312
313
|
# File 'lib/engineyard-serverside/configuration.rb', line 311
def role
node['instance_role']
end
|
#rollback_paths! ⇒ Object
264
265
266
267
268
269
270
271
272
|
# File 'lib/engineyard-serverside/configuration.rb', line 264
def rollback_paths!
rollback_paths = paths.rollback
if rollback_paths
@paths = rollback_paths
true
else
false
end
end
|
#ruby_version_command ⇒ Object
274
275
276
|
# File 'lib/engineyard-serverside/configuration.rb', line 274
def ruby_version_command
"ruby -v"
end
|
#set_framework_envs ⇒ Object
327
328
329
|
# File 'lib/engineyard-serverside/configuration.rb', line 327
def set_framework_envs
framework_env_names.each { |e| ENV[e] = environment }
end
|
#skip_precompile_assets? ⇒ Boolean
346
347
348
|
# File 'lib/engineyard-serverside/configuration.rb', line 346
def skip_precompile_assets?
precompile_assets == false || precompile_assets == "false"
end
|
#source(shell) ⇒ Object
Infer the deploy source strategy to use based on flag or default to specified strategy.
Returns a Source object.
224
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/engineyard-serverside/configuration.rb', line 224
def source(shell)
if archive && git
shell.fatal "Both --git and --archive specified. Precedence is not defined. Aborting"
raise "Both --git and --archive specified. Precedence is not defined. Aborting"
end
if archive
load_source(EY::Serverside::Source::Archive, shell, archive)
elsif source_class
load_source(EY::Serverside::Source.const_get(source_class), shell, git)
else load_source(EY::Serverside::Source::Git, shell, git)
end
end
|
#string_keys(hsh) ⇒ Object
133
134
135
|
# File 'lib/engineyard-serverside/configuration.rb', line 133
def string_keys(hsh)
hsh.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
end
|
#system_version_command ⇒ Object
278
279
280
|
# File 'lib/engineyard-serverside/configuration.rb', line 278
def system_version_command
"uname -m"
end
|
#to_json ⇒ Object
212
213
214
|
# File 'lib/engineyard-serverside/configuration.rb', line 212
def to_json
MultiJson.dump(configuration)
end
|