elastic-beanstalk 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -1
- data/elastic-beanstalk.gemspec +1 -0
- data/lib/elastic/beanstalk.rb +3 -1
- data/lib/elastic/beanstalk/smoke_tester.rb +19 -15
- data/lib/elastic/beanstalk/spinner.rb +29 -0
- data/lib/elastic/beanstalk/tasks/eb.rake +112 -0
- data/lib/elastic/beanstalk/version.rb +1 -1
- data/spec/lib/elastic/beanstalk/eb_smoke_tester_spec.rb +4 -3
- metadata +19 -2
data/README.md
CHANGED
@@ -69,7 +69,7 @@ The default is the 'development' environment, change this via command line by pr
|
|
69
69
|
### Step 4. Get some coffee
|
70
70
|
This will take a while. We intend to provide an example in the wiki and/or samples dir that implements a [caching strategy detailed here](http://horewi.cz/faster-rails-3-deployments-to-aws-elastic-beanstalk.html) to speed up deployment.
|
71
71
|
|
72
|
-
## Rake Tasks
|
72
|
+
## EB Rake Tasks
|
73
73
|
|
74
74
|
rake eb:clobber # Remove any generated package
|
75
75
|
rake eb:config # Setup AWS.config and merge/override environments into one resolved configuration
|
@@ -78,6 +78,19 @@ This will take a while. We intend to provide an example in the wiki and/or samp
|
|
78
78
|
rake eb:package # Package zip source bundle for Elastic Beanstalk
|
79
79
|
rake eb:show_config[version] # Show resolved configuration without doing anything
|
80
80
|
|
81
|
+
## RDS Rake Tasks
|
82
|
+
|
83
|
+
RDS tasks are intended to make integration of RDS task into the deployment process simple.
|
84
|
+
i.e. create a snapshot before or after an `eb:deploy`, the following `rake` tasks exist:
|
85
|
+
|
86
|
+
rake eb:rds:create_snapshot[instance_id,snapshot_id] # Creates an RDS snapshot
|
87
|
+
rake eb:rds:instances # List RDS instances
|
88
|
+
rake eb:rds:snapshots # List RDS snapshots
|
89
|
+
|
90
|
+
For example, this would create a snapshot prior to the deployment (and migration) to version 1.1.0:
|
91
|
+
|
92
|
+
rake eb:rds:create_snapshot[acme, pre-1.1.0] eb:deploy[1.1.0]
|
93
|
+
|
81
94
|
## A real-world example
|
82
95
|
|
83
96
|
Deploy version 1.1.3 of acme to production
|
data/elastic-beanstalk.gemspec
CHANGED
data/lib/elastic/beanstalk.rb
CHANGED
@@ -6,9 +6,11 @@ module Elastic
|
|
6
6
|
require 'elastic/beanstalk/extensions'
|
7
7
|
require 'elastic/beanstalk/smoke_tester'
|
8
8
|
require 'elastic/beanstalk/version'
|
9
|
+
require 'elastic/beanstalk/spinner'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
EbConfig = Elastic::Beanstalk::Config
|
13
14
|
EbExtensions = Elastic::Beanstalk::Extensions
|
14
|
-
EbSmokeTester = Elastic::Beanstalk::SmokeTester
|
15
|
+
EbSmokeTester = Elastic::Beanstalk::SmokeTester
|
16
|
+
Spinner = Elastic::Beanstalk::Spinner
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
require 'net/http'
|
3
|
+
require 'elastic/beanstalk/spinner'
|
3
4
|
|
4
5
|
module Elastic
|
5
6
|
module Beanstalk
|
@@ -12,28 +13,31 @@ module Elastic
|
|
12
13
|
|
13
14
|
puts '-------------------------------------------------------------------------------'
|
14
15
|
# puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\tsleep_wait: #{sleep_wait}\n\texpected_text: #{expected_text}\n"
|
15
|
-
puts "Smoke
|
16
|
+
puts "Smoke Test: \n\turl: #{url}\n\ttimeout: #{timeout}\n\texpected_text: #{expected_text}"
|
16
17
|
response = nil
|
17
18
|
begin
|
18
19
|
Timeout.timeout(timeout) do
|
19
20
|
i = 0
|
20
|
-
|
21
|
-
|
22
|
-
i += 1
|
21
|
+
print "\nRunning..."
|
22
|
+
Spinner.show {
|
23
23
|
begin
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
24
|
+
sleep sleep_wait.to_i unless (i == 0)
|
25
|
+
i += 1
|
26
|
+
begin
|
27
|
+
response = Net::HTTP.get_response(URI(url))
|
28
|
+
#rescue SocketError => e
|
29
|
+
# response = ResponseStub.new({code: e.message, body: ''})
|
30
|
+
rescue => e
|
31
|
+
response = ResponseStub.new({code: e.message, body: ''})
|
32
|
+
end
|
33
|
+
|
34
|
+
#puts "\t\t[#{response.code}]"
|
35
|
+
#puts "\t#{response.body}"
|
36
|
+
end until (!response.nil? && response.code.to_i == 200 && response.body.include?(expected_text))
|
37
|
+
}
|
34
38
|
end
|
35
39
|
ensure
|
36
|
-
puts "\nFinal response
|
40
|
+
puts "\n\nFinal response code: [#{response.code}] expectation met: #{response.body.include?(expected_text)}"
|
37
41
|
puts '-------------------------------------------------------------------------------'
|
38
42
|
end
|
39
43
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Elastic
|
2
|
+
module Beanstalk
|
3
|
+
|
4
|
+
module Spinner
|
5
|
+
# it's a singleton, thus implemented as a self-extended module
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def show(fps=10)
|
9
|
+
chars = %w{ | / - \\ }
|
10
|
+
delay = 1.0/fps
|
11
|
+
iter = 0
|
12
|
+
spinner = Thread.new do
|
13
|
+
while iter do # Keep spinning until told otherwise
|
14
|
+
|
15
|
+
print chars[0]
|
16
|
+
sleep delay
|
17
|
+
print "\b"
|
18
|
+
chars.push chars.shift
|
19
|
+
end
|
20
|
+
end
|
21
|
+
yield.tap {# After yielding to the block, save the return value
|
22
|
+
iter = false # Tell the thread to exit, cleaning up after itself…
|
23
|
+
spinner.join # …and wait for it to do so.
|
24
|
+
} # Use the block's return value as the method's
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -5,9 +5,121 @@ require 'eb_deployer'
|
|
5
5
|
require 'time_diff'
|
6
6
|
require 'elastic/beanstalk'
|
7
7
|
require 'yaml'
|
8
|
+
require 'table_print'
|
9
|
+
require 'timeout'
|
8
10
|
|
9
11
|
namespace :eb do
|
10
12
|
|
13
|
+
namespace :rds do
|
14
|
+
|
15
|
+
desc 'List RDS snapshots'
|
16
|
+
task :snapshots => [:config] do |t, args|
|
17
|
+
# absolutely do not run this without specifying columns, otherwise it will call all defined methods including :delete
|
18
|
+
print_snapshots(rds.snapshots.to_a)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'List RDS instances'
|
22
|
+
task :instances => [:config] do |t, args|
|
23
|
+
# absolutely do not run this without specifying columns, otherwise it will call all defined methods including :delete
|
24
|
+
print_instances(rds.instances.to_a)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Creates an RDS snapshot'
|
28
|
+
task :create_snapshot, [:instance_id, :snapshot_id] => [:config] do |t, args|
|
29
|
+
|
30
|
+
snapshot_id = args[:snapshot_id]
|
31
|
+
|
32
|
+
db = db(args[:instance_id])
|
33
|
+
|
34
|
+
from_time = Time.now
|
35
|
+
puts "\n\n---------------------------------------------------------------------------------------------------------------------------------------"
|
36
|
+
snapshot = db.create_snapshot(snapshot_id)
|
37
|
+
#snapshot = snapshot(snapshot_id) # for quick testing of code below
|
38
|
+
|
39
|
+
|
40
|
+
#ID | STATUS | GB | TYPE | ENGINE | ZONE | CREATED_AT | INSTANCE_CREATE_TIME
|
41
|
+
#------|----------|----|--------|--------------|------------|------------|------------------------
|
42
|
+
#pre-2 | creating | 10 | manual | mysql 5.6.12 | us-east-1d | | 2013-09-10 21:37:27
|
43
|
+
# available
|
44
|
+
print_snapshots(snapshot)
|
45
|
+
puts "\n"
|
46
|
+
|
47
|
+
timeout = 20 * 60
|
48
|
+
sleep_wait = 5
|
49
|
+
begin
|
50
|
+
Timeout.timeout(timeout) do
|
51
|
+
i = 0
|
52
|
+
|
53
|
+
print "\nCreating snapshot[#{snapshot_id}]..."
|
54
|
+
Spinner.show {
|
55
|
+
begin
|
56
|
+
sleep sleep_wait.to_i unless (i == 0)
|
57
|
+
i += 1
|
58
|
+
|
59
|
+
snapshot = snapshot(snapshot_id)
|
60
|
+
|
61
|
+
end until (snapshot.status.eql? 'available')
|
62
|
+
}
|
63
|
+
end
|
64
|
+
ensure
|
65
|
+
puts "\n\nSnapshot[#{snapshot_id}]: #{snapshot.status}. Finished in #{Time.diff(from_time, Time.now, '%N %S')[:diff]}.\n"
|
66
|
+
puts "---------------------------------------------------------------------------------------------------------------------------------------\n\n"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def snapshot(snapshot_id)
|
71
|
+
AWS::RDS::DBSnapshot.new(snapshot_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def db(instance_id)
|
75
|
+
db_instance = AWS::RDS::DBInstance.new(instance_id)
|
76
|
+
raise "DB Instance[#{instance_id}] does not exist." unless db_instance.exists?
|
77
|
+
db_instance
|
78
|
+
end
|
79
|
+
|
80
|
+
def rds
|
81
|
+
@rds ||= AWS::RDS.new
|
82
|
+
@rds
|
83
|
+
end
|
84
|
+
|
85
|
+
def print_snapshots(snapshots)
|
86
|
+
tp snapshots,
|
87
|
+
{snapshot_id: {display_method: :id}},
|
88
|
+
:status,
|
89
|
+
{gb: {display_method: :allocated_storage}},
|
90
|
+
{type: {display_method: :snapshot_type}},
|
91
|
+
{engine: lambda { |i| "#{i.engine} #{i.engine_version}" }},
|
92
|
+
{zone: {display_method: :availability_zone_name}},
|
93
|
+
:created_at,
|
94
|
+
:instance_create_time
|
95
|
+
#:master_username,
|
96
|
+
end
|
97
|
+
|
98
|
+
def print_instances(instances)
|
99
|
+
tp instances,
|
100
|
+
{instance_id: {display_method: :id}},
|
101
|
+
{name: {display_method: :db_name}},
|
102
|
+
:status,
|
103
|
+
{gb: {display_method: :allocated_storage}},
|
104
|
+
:iops,
|
105
|
+
{class: {display_method: :db_instance_class}},
|
106
|
+
{engine: lambda { |i| "#{i.engine} #{i.engine_version}" }},
|
107
|
+
{zone: {display_method: :availability_zone_name}},
|
108
|
+
:multi_az,
|
109
|
+
#{endpoint_address: {max_width: 120}},
|
110
|
+
{:endpoint_address => {:width => 120}},
|
111
|
+
{port: {display_method: :endpoint_port}},
|
112
|
+
#:latest_restorable_time,
|
113
|
+
#:auto_minor_version_upgrade,
|
114
|
+
#:read_replica_db_instance_identifiers,
|
115
|
+
#:read_replica_source_db_instance_identifier,
|
116
|
+
#:backup_retention_period,
|
117
|
+
#:master_username,
|
118
|
+
:created_at
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
11
123
|
###########################################
|
12
124
|
#
|
13
125
|
#
|
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe EbExtensions do
|
4
4
|
|
5
|
-
|
5
|
+
##this is a driver only, perhaps make this a reasonable test someday...
|
6
6
|
#it "#test_url" do
|
7
|
-
# url = 'http://acme-development-inactive.elasticbeanstalk.com/ping'
|
7
|
+
# #url = 'http://acme-development-inactive.elasticbeanstalk.com/ping'
|
8
|
+
# url = 'http://google.com'
|
8
9
|
# expected_text = 'You came to this page by mistake, go back where you came from'
|
9
|
-
# EbSmokeTester.test_url(url,
|
10
|
+
# EbSmokeTester.test_url(url, 10, 2, expected_text)
|
10
11
|
#end
|
11
12
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -139,6 +139,22 @@ dependencies:
|
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: table_print
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
142
158
|
description: ! ' The simplest way to configure and deploy an Elastic Beanstalk
|
143
159
|
application via rake.
|
144
160
|
|
@@ -164,6 +180,7 @@ files:
|
|
164
180
|
- lib/elastic/beanstalk/extensions.rb
|
165
181
|
- lib/elastic/beanstalk/railtie.rb
|
166
182
|
- lib/elastic/beanstalk/smoke_tester.rb
|
183
|
+
- lib/elastic/beanstalk/spinner.rb
|
167
184
|
- lib/elastic/beanstalk/tasks/eb.rake
|
168
185
|
- lib/elastic/beanstalk/version.rb
|
169
186
|
- spec/lib/deep_symbolize_spec.rb
|