elastic-beanstalk 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -56,12 +56,12 @@ This will take a while. We intend to provide an example in the wiki and/or samp
56
56
 
57
57
  ## Rake Tasks
58
58
 
59
- eb:config # Setup AWS.config and merge/override environments into one resolved configuration.
60
- eb:show_config # Show resolved configuration without doing anything. arguments[:version]
61
- eb:clobber # Remove any generated package.
62
- eb:package # Package zip source bundle for Elastic Beanstalk.
63
- eb:deploy # Deploy to Elastic Beanstalk. arguments[:version]
64
- eb:destroy # ** Warning: Destroy Elastic Beanstalk application and *all* environments. arguments[:force]
59
+ rake eb:clobber # Remove any generated package
60
+ rake eb:config # Setup AWS.config and merge/override environments into one resolved configuration
61
+ rake eb:deploy[version] # Deploy to Elastic Beanstalk
62
+ rake eb:destroy[force] # ** Warning: Destroy Elastic Beanstalk application and *all* environments
63
+ rake eb:package # Package zip source bundle for Elastic Beanstalk
64
+ rake eb:show_config[version] # Show resolved configuration without doing anything
65
65
 
66
66
  ## A real-world example
67
67
 
@@ -1,33 +1,39 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'elastic_beanstalk/version'
4
+ require 'elastic/beanstalk/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'elastic-beanstalk'
8
- spec.version = ElasticBeanstalk::VERSION
8
+ spec.version = Elastic::Beanstalk::VERSION
9
9
  spec.authors = ['Kevin Ross']
10
10
  spec.email = ['kevin.ross@alienfast.com']
11
- spec.description = %q{The simplest way to configure and deploy an Elastic Beanstalk application via rake.}
12
- spec.summary = %q{Configure and deploy a rails app to Elastic Beanstalk via rake in 60 seconds. Maintain multiple environment DRY configurations and .ebextensions in one easy to use configuration file.}
11
+ spec.description = <<-TEXT
12
+ The simplest way to configure and deploy an Elastic Beanstalk application via rake.
13
+ TEXT
14
+ spec.summary = <<-TEXT
15
+ Configure and deploy a rails app to Elastic Beanstalk via rake in 60 seconds.
16
+ Maintain multiple environment DRY configurations and .ebextensions in one easy
17
+ to use configuration file.
18
+ TEXT
13
19
  spec.homepage = 'https://github.com/alienfast/elastic-beanstalk'
14
20
  spec.license = 'MIT'
15
21
 
16
22
  spec.files = `git ls-files`.split($/).reject { |f| f =~ /^samples\// }
17
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = %w(lib)
25
+ spec.require_paths = ['lib']
20
26
 
27
+ # development
21
28
  spec.add_development_dependency 'bundler', '~> 1.3'
22
29
  spec.add_development_dependency 'rake'
23
30
  spec.add_development_dependency 'rspec', '>= 2.14.1'
24
31
 
25
- # spec.add_runtime_dependency
26
- spec.add_development_dependency 'rails' #, '>=3.2.13'
27
- spec.add_development_dependency 'eb_deployer'
28
- spec.add_development_dependency 'awesome_print'
29
- spec.add_development_dependency 'time_diff'
30
- spec.add_development_dependency 'zipruby'
31
- spec.add_development_dependency 'safe_yaml', '0.9.3'
32
-
32
+ # runtime
33
+ spec.add_runtime_dependency 'railties', '>= 3.2'
34
+ #spec.add_runtime_dependency 'rails' #, '>=3.2.13'
35
+ spec.add_runtime_dependency 'eb_deployer'
36
+ spec.add_runtime_dependency 'awesome_print'
37
+ spec.add_runtime_dependency 'time_diff'
38
+ spec.add_runtime_dependency 'zipruby'
33
39
  end
@@ -0,0 +1,14 @@
1
+ module Elastic
2
+ module Beanstalk
3
+ require 'elastic/beanstalk/railtie' if defined?(Rails::Railtie)
4
+ require 'deep_symbolize'
5
+ require 'elastic/beanstalk/config'
6
+ require 'elastic/beanstalk/extensions'
7
+ require 'elastic/beanstalk/smoke_tester'
8
+ require 'elastic/beanstalk/version'
9
+ end
10
+ end
11
+
12
+ EbConfig = Elastic::Beanstalk::Config
13
+ EbExtensions = Elastic::Beanstalk::Extensions
14
+ EbSmokeTester = Elastic::Beanstalk::SmokeTester
@@ -0,0 +1,205 @@
1
+ require 'deep_symbolize'
2
+ require 'yaml'
3
+
4
+ module Elastic
5
+ module Beanstalk
6
+ #
7
+ # EbConfig allows for default settings and mounting a specific environment with overriding
8
+ # hash values and merging of array values.
9
+ #
10
+ # NOTE: Anything can be overridden and merged into top-level settings (hashes) including
11
+ # anything that is an array value. Array values are merged *not* replaced. If you think
12
+ # something is screwy, see the defaults in the #init as those add some default array values.
13
+ # If this behavior of merging arrays or the defaults are somehow un-sensible, file an issue and we'll revisit it.
14
+ #
15
+ module Config
16
+ # it's a singleton, thus implemented as a self-extended module
17
+ extend self
18
+
19
+ def init
20
+
21
+ # seed the sensible defaults here
22
+ @configuration = {
23
+ environment: nil,
24
+ disallow_environments: %w(cucumber test),
25
+ strategy: :blue_green,
26
+ package: {
27
+ dir: 'pkg',
28
+ verbose: false,
29
+ includes: %w(**/* .ebextensions/**/*),
30
+ exclude_files: [],
31
+ exclude_dirs: %w(pkg tmp log test-reports)
32
+ },
33
+ options: {}
34
+ }
35
+ end
36
+
37
+ init()
38
+ attr_reader :configuration
39
+
40
+ # This is the main point of entry - we call Settings.load! and provide
41
+ # a name of the file to read as it's argument. We can also pass in some
42
+ # options, but at the moment it's being used to allow per-environment
43
+ # overrides in Rails
44
+ def load!(environment = nil, filename = resolve_path('config/eb.yml'))
45
+
46
+ # merge all top level settings with the defaults set in the #init
47
+ #@configuration.deep_merge!( YAML::load_file(filename).deep_symbolize )
48
+ deep_merge!(@configuration, YAML::load_file(filename).deep_symbolize)
49
+
50
+ # add the environment to the top level settings
51
+ @configuration[:environment] = (environment.nil? ? nil : environment.to_s)
52
+
53
+ # overlay the specific environment if provided
54
+ if environment && @configuration[environment.to_sym]
55
+
56
+ # this is environment specific, so prune any environment
57
+ # based settings from the initial set so that they can be overlaid.
58
+ [:development, :test, :staging, :production].each do |env|
59
+ @configuration.delete(env)
60
+ end
61
+
62
+ # re-read the file
63
+ environment_settings = YAML::load_file(filename).deep_symbolize
64
+
65
+ # snag the requested environment
66
+ environment_settings = environment_settings[environment.to_sym]
67
+
68
+ # finally overlay what was provided
69
+ #@configuration.deep_merge!(environment_settings)
70
+ deep_merge!(@configuration, environment_settings)
71
+ end
72
+
73
+
74
+ #ap @configuration
75
+ #generate_accessors
76
+ end
77
+
78
+ def deep_merge!(target, data)
79
+ merger = proc { |key, v1, v2|
80
+ if (Hash === v1 && Hash === v2)
81
+ v1.merge(v2, &merger)
82
+ elsif (Array === v1 && Array === v2)
83
+ v1.concat(v2)
84
+ else
85
+ v2
86
+ end
87
+ }
88
+ target.merge! data, &merger
89
+ end
90
+
91
+ def reload!(options = {}, filename)
92
+ clear
93
+ #filename.nil? ?
94
+ load!(options) # : load!(options, filename)
95
+ end
96
+
97
+ def to_yaml
98
+
99
+ end
100
+
101
+ def method_missing(name, *args, &block)
102
+ @configuration[name.to_sym] ||
103
+ #fail(NoMethodError, "Unknown settings root \'#{name}\'", caller)
104
+ nil
105
+ end
106
+
107
+ def clear
108
+ init
109
+ end
110
+
111
+ def options
112
+ @configuration[:options] = {} if @configuration[:options].nil?
113
+ @configuration[:options]
114
+ end
115
+
116
+ # custom methods for the specifics of eb.yml settings
117
+ def option_settings
118
+ result = []
119
+ options.each_key do |namespace|
120
+ options[namespace].each do |option_name, value|
121
+ result << to_option_setting(namespace, option_name, value)
122
+ end
123
+ end
124
+
125
+ #{"option_settings" => result}
126
+ result
127
+ end
128
+
129
+ def set_option(namespace, option_name, value)
130
+ namespace = namespace.to_sym
131
+
132
+ if options[namespace].nil?
133
+ options[namespace] = {option_name.to_sym => value}
134
+ else
135
+ options[namespace][option_name.to_sym] = value
136
+ end
137
+
138
+ #puts '888888hello'
139
+ end
140
+
141
+ def find_option_setting(name)
142
+ name = name.to_sym
143
+ options.each_key do |namespace|
144
+ options[namespace].each do |option_name, value|
145
+ if option_name.eql? name
146
+ return to_option_setting(namespace, option_name, value)
147
+ end
148
+ end
149
+ end
150
+ return nil
151
+ end
152
+
153
+ def find_option_setting_value(name)
154
+ o = find_option_setting(name)
155
+ o[:value] unless o.nil?
156
+ end
157
+
158
+ def to_option_setting(namespace, option_name, value)
159
+ {
160
+ :"namespace" => "#{namespace}",
161
+ :"option_name" => "#{option_name}",
162
+ :"value" => "#{value}"
163
+ }
164
+ end
165
+
166
+ def resolve_path(relative_path)
167
+ if defined?(Rails)
168
+
169
+ #puts '**********************Using Rails.root'
170
+ Rails.root.join(relative_path)
171
+ elsif defined?(Rake.original_dir)
172
+
173
+ #puts '**********************Using Rake.original_dir'
174
+ Rake.original_dir.join(relative_path)
175
+ else
176
+
177
+ #puts '**********************Using Last resort Dir.pwd'
178
+ #raise 'I have no idea what the root dir is yet.'
179
+ File.expand_path(relative_path, Dir.pwd)
180
+ end
181
+ end
182
+
183
+
184
+ #def environment
185
+ # @configuration[:environment]
186
+ #end
187
+ #
188
+ #def options
189
+ # @configuration[:options]
190
+ #end
191
+
192
+ private
193
+
194
+ #def generate_accessors
195
+ # # generate a method for accessors
196
+ # @configuration.each do |key, value|
197
+ # define_method(key) do
198
+ # value
199
+ # end unless ['options', 'environment'].include? key
200
+ # end
201
+ #end
202
+ end
203
+
204
+ end
205
+ end
@@ -0,0 +1,45 @@
1
+ module Elastic
2
+ module Beanstalk
3
+
4
+ module Extensions
5
+ # it's a singleton, thus implemented as a self-extended module
6
+ extend self
7
+
8
+ def write_extensions
9
+
10
+ ebextensions = EbConfig.ebextensions
11
+ return if ebextensions.nil?
12
+
13
+ Dir.mkdir absolute_file_name(nil) rescue nil
14
+
15
+ ebextensions.each_key do |filename|
16
+ contents = EbConfig.ebextensions[filename]
17
+
18
+ filename = absolute_file_name(filename)
19
+
20
+ # when converting to_yaml, kill the symbols as EB doesn't like it.
21
+ contents = contents.deep_symbolize(true).to_yaml.gsub(/---\n/, "")
22
+ #puts "\n#{filename}:\n----------------------------------------------------\n#{contents}----------------------------------------------------\n"
23
+ File.write(filename, contents)
24
+ end
25
+ end
26
+
27
+ def delete_extensions
28
+ ebextensions = EbConfig.ebextensions
29
+ return if ebextensions.nil?
30
+
31
+ ebextensions.each_key do |filename|
32
+ File.delete(absolute_file_name filename)
33
+ end
34
+ end
35
+
36
+ def absolute_file_name(filename)
37
+ EbConfig.resolve_path(".ebextensions/#{filename}")
38
+ end
39
+
40
+ def ebextensions_dir(filename)
41
+ EbConfig.resolve_path(".ebextensions/#{filename}")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ #require 'beanstalk'
2
+ #require 'rails'
3
+
4
+ module Elastic
5
+ module Beanstalk
6
+
7
+ # https://gist.github.com/josevalim/af7e572c2dc973add221
8
+ class Railtie < Rails::Railtie
9
+
10
+ #railtie_name :elastic
11
+
12
+ rake_tasks do
13
+ load 'elastic/beanstalk/tasks/eb.rake'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,49 @@
1
+ module Elastic
2
+ module Beanstalk
3
+
4
+ module SmokeTester
5
+ # it's a singleton, thus implemented as a self-extended module
6
+ extend self
7
+
8
+ def test_url(url, timeout, sleep_wait, expected_text)
9
+
10
+ puts '-------------------------------------------------------------------------------'
11
+ # puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\tsleep_wait: #{sleep_wait}\n\texpected_text: #{expected_text}\n"
12
+ puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\texpected_text: #{expected_text}\n"
13
+ response = nil
14
+ begin
15
+ Timeout.timeout(timeout) do
16
+ i = 0
17
+ begin
18
+ sleep sleep_wait.to_i unless (i == 0)
19
+ i += 1
20
+ begin
21
+ response = Net::HTTP.get_response(URI(url))
22
+ rescue SocketError => e
23
+ response = ResponseStub.new({code: e.message, body: ''})
24
+ end
25
+
26
+ puts "\t\t[#{response.code}]"
27
+ #puts "\t#{response.body}"
28
+ end until (!response.nil? && response.code.to_i == 200 && response.body.include?(expected_text))
29
+ end
30
+ ensure
31
+ puts "\nFinal response: \n\tcode: [#{response.code}] \n\texpectation met: #{response.body.include?(expected_text)}"
32
+ puts '-------------------------------------------------------------------------------'
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ class ResponseStub
39
+
40
+ attr_reader :code, :body
41
+
42
+ def initialize(args)
43
+ @code = args[:code]
44
+ @body = args[:body]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,8 +1,9 @@
1
1
  require 'digest'
2
2
  require 'zipruby' # gem 'zipruby'
3
3
  require 'ap' # gem 'awesome_print'
4
- require 'elastic_beanstalk/eb_config'
5
- require 'elastic_beanstalk/eb_extensions'
4
+ require 'eb_deployer'
5
+ require 'elastic/beanstalk/config'
6
+ require 'elastic/beanstalk/extensions'
6
7
 
7
8
  namespace :eb do
8
9
 
@@ -228,7 +229,7 @@ namespace :eb do
228
229
  end
229
230
 
230
231
  def package_verbose?
231
- EbConfig.package[:verbose]
232
+ EbConfig.package[:verbose] || false
232
233
  end
233
234
 
234
235
  def package_file
@@ -0,0 +1,5 @@
1
+ module Elastic
2
+ module Beanstalk
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- #require 'elastic_beanstalk/eb_smoke_tester'
2
+ #require 'elastic/eb_smoke_tester'
3
3
 
4
4
  describe EbExtensions do
5
5
 
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  # our gem
5
- require 'elastic_beanstalk'
5
+ require 'elastic/beanstalk'
6
6
 
7
7
  RSpec.configure do |config|
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-beanstalk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,21 +60,21 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.14.1
62
62
  - !ruby/object:Gem::Dependency
63
- name: rails
63
+ name: railties
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
69
+ version: '3.2'
70
+ type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '3.2'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: eb_deployer
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
- type: :development
86
+ type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
@@ -99,7 +99,7 @@ dependencies:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
- type: :development
102
+ type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
@@ -115,7 +115,7 @@ dependencies:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
- type: :development
118
+ type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
@@ -131,7 +131,7 @@ dependencies:
131
131
  - - ! '>='
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
- type: :development
134
+ type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  none: false
@@ -139,24 +139,10 @@ dependencies:
139
139
  - - ! '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: safe_yaml
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - '='
148
- - !ruby/object:Gem::Version
149
- version: 0.9.3
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - '='
156
- - !ruby/object:Gem::Version
157
- version: 0.9.3
158
- description: The simplest way to configure and deploy an Elastic Beanstalk application
159
- via rake.
142
+ description: ! ' The simplest way to configure and deploy an Elastic Beanstalk
143
+ application via rake.
144
+
145
+ '
160
146
  email:
161
147
  - kevin.ross@alienfast.com
162
148
  executables: []
@@ -171,18 +157,18 @@ files:
171
157
  - Rakefile
172
158
  - elastic-beanstalk.gemspec
173
159
  - lib/deep_symbolize.rb
174
- - lib/elastic_beanstalk.rb
175
- - lib/elastic_beanstalk/eb_config.rb
176
- - lib/elastic_beanstalk/eb_extensions.rb
177
- - lib/elastic_beanstalk/eb_smoke_tester.rb
178
- - lib/elastic_beanstalk/railtie.rb
179
- - lib/elastic_beanstalk/version.rb
180
- - lib/tasks/eb.rake
160
+ - lib/elastic/beanstalk.rb
161
+ - lib/elastic/beanstalk/config.rb
162
+ - lib/elastic/beanstalk/extensions.rb
163
+ - lib/elastic/beanstalk/railtie.rb
164
+ - lib/elastic/beanstalk/smoke_tester.rb
165
+ - lib/elastic/beanstalk/tasks/eb.rake
166
+ - lib/elastic/beanstalk/version.rb
181
167
  - spec/lib/deep_symbolize_spec.rb
182
- - spec/lib/elastic_beanstalk/eb_config_spec.rb
183
- - spec/lib/elastic_beanstalk/eb_extensions_spec.rb
184
- - spec/lib/elastic_beanstalk/eb_smoke_tester_spec.rb
185
- - spec/lib/elastic_beanstalk/eb_spec.yml
168
+ - spec/lib/elastic/beanstalk/eb_config_spec.rb
169
+ - spec/lib/elastic/beanstalk/eb_extensions_spec.rb
170
+ - spec/lib/elastic/beanstalk/eb_smoke_tester_spec.rb
171
+ - spec/lib/elastic/beanstalk/eb_spec.yml
186
172
  - spec/spec_helper.rb
187
173
  homepage: https://github.com/alienfast/elastic-beanstalk
188
174
  licenses:
@@ -199,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
185
  version: '0'
200
186
  segments:
201
187
  - 0
202
- hash: -3169788302017420497
188
+ hash: -3659734422273774522
203
189
  required_rubygems_version: !ruby/object:Gem::Requirement
204
190
  none: false
205
191
  requirements:
@@ -208,19 +194,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
194
  version: '0'
209
195
  segments:
210
196
  - 0
211
- hash: -3169788302017420497
197
+ hash: -3659734422273774522
212
198
  requirements: []
213
199
  rubyforge_project:
214
200
  rubygems_version: 1.8.25
215
201
  signing_key:
216
202
  specification_version: 3
217
- summary: Configure and deploy a rails app to Elastic Beanstalk via rake in 60 seconds. Maintain
218
- multiple environment DRY configurations and .ebextensions in one easy to use configuration
219
- file.
203
+ summary: Configure and deploy a rails app to Elastic Beanstalk via rake in 60 seconds.
204
+ Maintain multiple environment DRY configurations and .ebextensions in one easy to
205
+ use configuration file.
220
206
  test_files:
221
207
  - spec/lib/deep_symbolize_spec.rb
222
- - spec/lib/elastic_beanstalk/eb_config_spec.rb
223
- - spec/lib/elastic_beanstalk/eb_extensions_spec.rb
224
- - spec/lib/elastic_beanstalk/eb_smoke_tester_spec.rb
225
- - spec/lib/elastic_beanstalk/eb_spec.yml
208
+ - spec/lib/elastic/beanstalk/eb_config_spec.rb
209
+ - spec/lib/elastic/beanstalk/eb_extensions_spec.rb
210
+ - spec/lib/elastic/beanstalk/eb_smoke_tester_spec.rb
211
+ - spec/lib/elastic/beanstalk/eb_spec.yml
226
212
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
-
2
- module ElasticBeanstalk
3
- require 'deep_symbolize'
4
- require 'elastic_beanstalk/eb_config'
5
- require 'elastic_beanstalk/eb_extensions'
6
- require 'elastic_beanstalk/eb_smoke_tester'
7
- require 'elastic_beanstalk/railtie' if defined?(Rails)
8
- require 'elastic_beanstalk/version'
9
- end
10
-
11
- EbConfig = ElasticBeanstalk::EbConfig
12
- EbExtensions = ElasticBeanstalk::EbExtensions
13
- EbSmokeTester = ElasticBeanstalk::EbSmokeTester
@@ -1,203 +0,0 @@
1
- require 'deep_symbolize'
2
- require 'yaml'
3
-
4
- module ElasticBeanstalk
5
- #
6
- # EbConfig allows for default settings and mounting a specific environment with overriding
7
- # hash values and merging of array values.
8
- #
9
- # NOTE: Anything can be overridden and merged into top-level settings (hashes) including
10
- # anything that is an array value. Array values are merged *not* replaced. If you think
11
- # something is screwy, see the defaults in the #init as those add some default array values.
12
- # If this behavior of merging arrays or the defaults are somehow un-sensible, file an issue and we'll revisit it.
13
- #
14
- module EbConfig
15
- # it's a singleton, thus implemented as a self-extended module
16
- extend self
17
-
18
- def init
19
-
20
- # seed the sensible defaults here
21
- @configuration = {
22
- environment: nil,
23
- disallow_environments: %w(cucumber test),
24
- strategy: :blue_green,
25
- package: {
26
- dir: 'pkg',
27
- verbose: false,
28
- includes: %w(**/* .ebextensions/**/*),
29
- exclude_files: [],
30
- exclude_dirs: %w(pkg tmp log test-reports)
31
- },
32
- options: {}
33
- }
34
- end
35
-
36
- init()
37
- attr_reader :configuration
38
-
39
- # This is the main point of entry - we call Settings.load! and provide
40
- # a name of the file to read as it's argument. We can also pass in some
41
- # options, but at the moment it's being used to allow per-environment
42
- # overrides in Rails
43
- def load!(environment = nil, filename = resolve_path('config/eb.yml'))
44
-
45
- # merge all top level settings with the defaults set in the #init
46
- #@configuration.deep_merge!( YAML::load_file(filename).deep_symbolize )
47
- deep_merge!(@configuration, YAML::load_file(filename).deep_symbolize)
48
-
49
- # add the environment to the top level settings
50
- @configuration[:environment] = (environment.nil? ? nil : environment.to_s)
51
-
52
- # overlay the specific environment if provided
53
- if environment && @configuration[environment.to_sym]
54
-
55
- # this is environment specific, so prune any environment
56
- # based settings from the initial set so that they can be overlaid.
57
- [:development, :test, :staging, :production].each do |env|
58
- @configuration.delete(env)
59
- end
60
-
61
- # re-read the file
62
- environment_settings = YAML::load_file(filename).deep_symbolize
63
-
64
- # snag the requested environment
65
- environment_settings = environment_settings[environment.to_sym]
66
-
67
- # finally overlay what was provided
68
- #@configuration.deep_merge!(environment_settings)
69
- deep_merge!(@configuration, environment_settings)
70
- end
71
-
72
-
73
- #ap @configuration
74
- #generate_accessors
75
- end
76
-
77
- def deep_merge!(target, data)
78
- merger = proc { |key, v1, v2|
79
- if (Hash === v1 && Hash === v2)
80
- v1.merge(v2, &merger)
81
- elsif (Array === v1 && Array === v2)
82
- v1.concat(v2)
83
- else
84
- v2
85
- end
86
- }
87
- target.merge! data, &merger
88
- end
89
-
90
- def reload!(options = {}, filename)
91
- clear
92
- #filename.nil? ?
93
- load!(options) # : load!(options, filename)
94
- end
95
-
96
- def to_yaml
97
-
98
- end
99
-
100
- def method_missing(name, *args, &block)
101
- @configuration[name.to_sym] ||
102
- #fail(NoMethodError, "Unknown settings root \'#{name}\'", caller)
103
- nil
104
- end
105
-
106
- def clear
107
- init
108
- end
109
-
110
- def options
111
- @configuration[:options] = {} if @configuration[:options].nil?
112
- @configuration[:options]
113
- end
114
-
115
- # custom methods for the specifics of eb.yml settings
116
- def option_settings
117
- result = []
118
- options.each_key do |namespace|
119
- options[namespace].each do |option_name, value|
120
- result << to_option_setting(namespace, option_name, value)
121
- end
122
- end
123
-
124
- #{"option_settings" => result}
125
- result
126
- end
127
-
128
- def set_option(namespace, option_name, value)
129
- namespace = namespace.to_sym
130
-
131
- if options[namespace].nil?
132
- options[namespace] = {option_name.to_sym => value}
133
- else
134
- options[namespace][option_name.to_sym] = value
135
- end
136
-
137
- #puts '888888hello'
138
- end
139
-
140
- def find_option_setting(name)
141
- name = name.to_sym
142
- options.each_key do |namespace|
143
- options[namespace].each do |option_name, value|
144
- if option_name.eql? name
145
- return to_option_setting(namespace, option_name, value)
146
- end
147
- end
148
- end
149
- return nil
150
- end
151
-
152
- def find_option_setting_value(name)
153
- o = find_option_setting(name)
154
- o[:value] unless o.nil?
155
- end
156
-
157
- def to_option_setting(namespace, option_name, value)
158
- {
159
- :"namespace" => "#{namespace}",
160
- :"option_name" => "#{option_name}",
161
- :"value" => "#{value}"
162
- }
163
- end
164
-
165
- def resolve_path(relative_path)
166
- if defined?(Rails)
167
-
168
- puts '**********************Using Rails.root'
169
- Rails.root.join(relative_path)
170
- elsif defined?(Rake.original_dir)
171
-
172
- puts '**********************Using Rake.original_dir'
173
- Rake.original_dir.join(relative_path)
174
- else
175
-
176
- puts '**********************Using Last resort Dir.pwd'
177
- #raise 'I have no idea what the root dir is yet.'
178
- File.expand_path(relative_path, Dir.pwd)
179
- end
180
- end
181
-
182
-
183
- #def environment
184
- # @configuration[:environment]
185
- #end
186
- #
187
- #def options
188
- # @configuration[:options]
189
- #end
190
-
191
- private
192
-
193
- #def generate_accessors
194
- # # generate a method for accessors
195
- # @configuration.each do |key, value|
196
- # define_method(key) do
197
- # value
198
- # end unless ['options', 'environment'].include? key
199
- # end
200
- #end
201
- end
202
-
203
- end
@@ -1,43 +0,0 @@
1
- module ElasticBeanstalk
2
-
3
- module EbExtensions
4
- # it's a singleton, thus implemented as a self-extended module
5
- extend self
6
-
7
- def write_extensions
8
-
9
- ebextensions = EbConfig.ebextensions
10
- return if ebextensions.nil?
11
-
12
- Dir.mkdir absolute_file_name(nil) rescue nil
13
-
14
- ebextensions.each_key do |filename|
15
- contents = EbConfig.ebextensions[filename]
16
-
17
- filename = absolute_file_name(filename)
18
-
19
- # when converting to_yaml, kill the symbols as EB doesn't like it.
20
- contents = contents.deep_symbolize(true).to_yaml.gsub(/---\n/, "")
21
- #puts "\n#{filename}:\n----------------------------------------------------\n#{contents}----------------------------------------------------\n"
22
- File.write(filename, contents)
23
- end
24
- end
25
-
26
- def delete_extensions
27
- ebextensions = EbConfig.ebextensions
28
- return if ebextensions.nil?
29
-
30
- ebextensions.each_key do |filename|
31
- File.delete(absolute_file_name filename)
32
- end
33
- end
34
-
35
- def absolute_file_name(filename)
36
- EbConfig.resolve_path(".ebextensions/#{filename}")
37
- end
38
-
39
- def ebextensions_dir(filename)
40
- EbConfig.resolve_path(".ebextensions/#{filename}")
41
- end
42
- end
43
- end
@@ -1,47 +0,0 @@
1
- module ElasticBeanstalk
2
-
3
- module EbSmokeTester
4
- # it's a singleton, thus implemented as a self-extended module
5
- extend self
6
-
7
- def test_url(url, timeout, sleep_wait, expected_text)
8
-
9
- puts '-------------------------------------------------------------------------------'
10
- # puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\tsleep_wait: #{sleep_wait}\n\texpected_text: #{expected_text}\n"
11
- puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\texpected_text: #{expected_text}\n"
12
- response = nil
13
- begin
14
- Timeout.timeout(timeout) do
15
- i = 0
16
- begin
17
- sleep sleep_wait.to_i unless (i == 0)
18
- i += 1
19
- begin
20
- response = Net::HTTP.get_response(URI(url))
21
- rescue SocketError => e
22
- response = ResponseStub.new({code: e.message, body: ''})
23
- end
24
-
25
- puts "\t\t[#{response.code}]"
26
- #puts "\t#{response.body}"
27
- end until (!response.nil? && response.code.to_i == 200 && response.body.include?(expected_text))
28
- end
29
- ensure
30
- puts "\nFinal response: \n\tcode: [#{response.code}] \n\texpectation met: #{response.body.include?(expected_text)}"
31
- puts '-------------------------------------------------------------------------------'
32
- end
33
- end
34
-
35
- private
36
-
37
- class ResponseStub
38
-
39
- attr_reader :code, :body
40
-
41
- def initialize(args)
42
- @code = args[:code]
43
- @body = args[:body]
44
- end
45
- end
46
- end
47
- end
@@ -1,12 +0,0 @@
1
- require 'elastic_beanstalk'
2
- require 'rails'
3
-
4
- module ElasticBeanstalk
5
- class Railtie < Rails::Railtie
6
- railtie_name :elastic_beanstalk
7
-
8
- rake_tasks do
9
- load '/lib/tasks/eb.rake'
10
- end
11
- end
12
- end
@@ -1,3 +0,0 @@
1
- module ElasticBeanstalk
2
- VERSION = '0.0.1'
3
- end