Class: EY::Serverside::Deploy::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard-serverside/configuration.rb

Constant Summary collapse

DEFAULT_CONFIG =
Thor::CoreExt::HashWithIndifferentAccess.new({
  "branch"         => "master",
  "strategy"       => "Git",
  "bundle_without" => "test development",
})

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



18
19
20
21
22
23
# File 'lib/engineyard-serverside/configuration.rb', line 18

def initialize(options={})
  opts = options.dup
  @release_path = opts[:release_path]
  config = JSON.parse(opts.delete("config") || "{}")
  @configuration = DEFAULT_CONFIG.merge(config).merge(opts)
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



26
27
28
# File 'lib/engineyard-serverside/configuration.rb', line 26

def method_missing(meth, *args, &blk)
  c.key?(meth.to_s) ? c[meth.to_s] : super
end

Instance Attribute Details

#configurationObject (readonly) Also known as: c

Returns the value of attribute configuration.



13
14
15
# File 'lib/engineyard-serverside/configuration.rb', line 13

def configuration
  @configuration
end

#release_pathObject



175
176
177
# File 'lib/engineyard-serverside/configuration.rb', line 175

def release_path
  @release_path ||= File.join(release_dir, Time.now.utc.strftime("%Y%m%d%H%M%S"))
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/engineyard-serverside/configuration.rb', line 34

def [](key)
  if respond_to?(key.to_sym)
    send(key.to_sym)
  else
    c[key]
  end
end

#all_releasesObject



123
124
125
# File 'lib/engineyard-serverside/configuration.rb', line 123

def all_releases
  Dir.glob("#{release_dir}/*").sort
end

#appObject



58
59
60
# File 'lib/engineyard-serverside/configuration.rb', line 58

def app
  configuration['app'].to_s
end

#binstubs_pathObject



127
128
129
# File 'lib/engineyard-serverside/configuration.rb', line 127

def binstubs_path
  release_path + '/ey_bundler_binstubs'
end

#bundle_withoutObject



82
83
84
# File 'lib/engineyard-serverside/configuration.rb', line 82

def bundle_without
  configuration['bundle_without']
end

#bundled_gems_pathObject



143
144
145
# File 'lib/engineyard-serverside/configuration.rb', line 143

def bundled_gems_path
  File.join(shared_path, "bundled_gems")
end

#copy_excludeObject



102
103
104
# File 'lib/engineyard-serverside/configuration.rb', line 102

def copy_exclude
  @copy_exclude ||= Array(configuration.fetch("copy_exclude", []))
end

#current_pathObject



135
136
137
# File 'lib/engineyard-serverside/configuration.rb', line 135

def current_path
  File.join(deploy_to, "current")
end

#current_roleObject



98
99
100
# File 'lib/engineyard-serverside/configuration.rb', line 98

def current_role
  current_roles.first
end

#deploy_toObject



70
71
72
# File 'lib/engineyard-serverside/configuration.rb', line 70

def deploy_to
  configuration['deploy_to'] || "/data/#{app}"
end

#environmentObject



106
107
108
# File 'lib/engineyard-serverside/configuration.rb', line 106

def environment
  configuration['framework_env']
end

#exclusionsObject



179
180
181
# File 'lib/engineyard-serverside/configuration.rb', line 179

def exclusions
  copy_exclude.map { |e| %|--exclude="#{e}"| }.join(' ')
end

#failed_release_dirObject



171
172
173
# File 'lib/engineyard-serverside/configuration.rb', line 171

def failed_release_dir
  File.join(deploy_to, "releases_failed")
end

#framework_envsObject



131
132
133
# File 'lib/engineyard-serverside/configuration.rb', line 131

def framework_envs
  "RAILS_ENV=#{environment} RACK_ENV=#{environment} NODE_ENV=#{environment} MERB_ENV=#{environment}"
end

#gemfile_pathObject



147
148
149
# File 'lib/engineyard-serverside/configuration.rb', line 147

def gemfile_path
  File.join(release_path, "Gemfile")
end

#groupObject



90
91
92
# File 'lib/engineyard-serverside/configuration.rb', line 90

def group
  configuration['group'] || user
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/engineyard-serverside/configuration.rb', line 42

def has_key?(key)
  if respond_to?(key.to_sym)
    true
  else
    c.has_key?(key)
  end
end

#latest_releaseObject



110
111
112
# File 'lib/engineyard-serverside/configuration.rb', line 110

def latest_release
  all_releases.last
end

#migrate?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/engineyard-serverside/configuration.rb', line 74

def migrate?
  !!configuration['migrate']
end

#migration_commandObject



78
79
80
# File 'lib/engineyard-serverside/configuration.rb', line 78

def migration_command
  configuration['migrate'] == "migrate" ? DEFAULT_CONFIG["migrate"] : configuration['migrate']
end

#nodeObject



54
55
56
# File 'lib/engineyard-serverside/configuration.rb', line 54

def node
  EY::Serverside.node
end

#oldest_releaseObject



119
120
121
# File 'lib/engineyard-serverside/configuration.rb', line 119

def oldest_release
  all_releases.first
end

#previous_release(current = latest_release) ⇒ Object



114
115
116
117
# File 'lib/engineyard-serverside/configuration.rb', line 114

def previous_release(current=latest_release)
  index = all_releases.index(current)
  all_releases[index-1]
end

#release_dirObject



167
168
169
# File 'lib/engineyard-serverside/configuration.rb', line 167

def release_dir
  File.join(deploy_to, "releases")
end

#repository_cacheObject



66
67
68
# File 'lib/engineyard-serverside/configuration.rb', line 66

def repository_cache
  configuration['repository_cache'] || File.join(deploy_to, 'shared', 'cached-copy')
end

#respond_to?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/engineyard-serverside/configuration.rb', line 30

def respond_to?(meth, include_private=false)
  c.key?(meth.to_s) ? true : super
end

#revisionObject



62
63
64
# File 'lib/engineyard-serverside/configuration.rb', line 62

def revision
  IO.read(File.join(latest_release, 'REVISION'))
end

#roleObject



94
95
96
# File 'lib/engineyard-serverside/configuration.rb', line 94

def role
  node['instance_role']
end

#ruby_version_commandObject



155
156
157
# File 'lib/engineyard-serverside/configuration.rb', line 155

def ruby_version_command
  "ruby -v"
end

#ruby_version_fileObject



151
152
153
# File 'lib/engineyard-serverside/configuration.rb', line 151

def ruby_version_file
  File.join(bundled_gems_path, "RUBY_VERSION")
end

#shared_pathObject



139
140
141
# File 'lib/engineyard-serverside/configuration.rb', line 139

def shared_path
  File.join(deploy_to, "shared")
end

#system_version_commandObject



163
164
165
# File 'lib/engineyard-serverside/configuration.rb', line 163

def system_version_command
  "uname -m"
end

#system_version_fileObject



159
160
161
# File 'lib/engineyard-serverside/configuration.rb', line 159

def system_version_file
  File.join(bundled_gems_path, "SYSTEM_VERSION")
end

#to_jsonObject



50
51
52
# File 'lib/engineyard-serverside/configuration.rb', line 50

def to_json
  configuration.to_json
end

#userObject



86
87
88
# File 'lib/engineyard-serverside/configuration.rb', line 86

def user
  configuration['user'] || ENV['USER']
end