eb_deployer 0.2.4 → 0.2.5
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/lib/eb_deployer.rb +94 -90
- data/lib/eb_deployer/deployment_strategy.rb +4 -4
- data/lib/eb_deployer/version.rb +1 -1
- data/test/deploy_test.rb +11 -11
- metadata +2 -2
data/lib/eb_deployer.rb
CHANGED
@@ -23,15 +23,15 @@ require 'fileutils'
|
|
23
23
|
|
24
24
|
module EbDeployer
|
25
25
|
|
26
|
-
|
26
|
+
#
|
27
27
|
# Query ouput value of the cloud formation stack
|
28
|
-
# arguments:
|
29
|
-
# key: CloudFormation ouput key
|
30
|
-
# options: a hash
|
31
|
-
# :application application name
|
32
|
-
# :environment environment name (e.g. staging, production)
|
33
28
|
#
|
34
|
-
|
29
|
+
# @param [String] key CloudFormation output key
|
30
|
+
# @param [Hash] opts
|
31
|
+
# @option opts [Symbol] :application application name
|
32
|
+
# @option opts [Symbol] :environment environment name (e.g. staging, production)
|
33
|
+
# @option opts [Symbol] :region AWS Region (e.g. "us-west-2", "us-east-1")
|
34
|
+
#
|
35
35
|
def self.query_resource_output(key, opts)
|
36
36
|
# AWS.config(:logger => Logger.new($stdout))
|
37
37
|
if region = opts[:region]
|
@@ -45,104 +45,108 @@ module EbDeployer
|
|
45
45
|
end
|
46
46
|
|
47
47
|
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# Deploy a package to specfied environments on elastic beanstalk
|
50
50
|
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# :application (required)
|
54
|
-
# Application name, this used for isolate packages and contribute
|
55
|
-
# to your elastic beanstalk cname for environments
|
51
|
+
# @param [Hash] opts
|
56
52
|
#
|
57
|
-
# :
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# (env-a-xxx, env-b-xxx) if blue-green deployment strategy specified
|
53
|
+
# @option opts [Symbol] :application *required* Application name, this
|
54
|
+
# used for isolate packages and contribute to your elastic beanstalk cname
|
55
|
+
# for environments
|
61
56
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
57
|
+
# @option opts [Symbol] :environment *required* Environment for same
|
58
|
+
# application, e.g. testing, staging, production. This will map to 2 elastic
|
59
|
+
# beanstalk environments (env-a-xxx, env-b-xxx) if blue-green deployment
|
60
|
+
# strategy specified
|
66
61
|
#
|
67
|
-
# :
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# recommend use md5 digest of the installer so that everytime you
|
72
|
-
# upload new installer it forms a new version. e.g.
|
62
|
+
# @option opts [Symbol] :package *required* package for the application
|
63
|
+
# which should be suitable for elastic beanstalk deploying. For example, a
|
64
|
+
# war file should be provided for java solution stacks and a ZIP file
|
65
|
+
# should be provided for Rails or Sinatra stack.
|
73
66
|
#
|
74
|
-
#
|
75
|
-
#
|
67
|
+
# @option opts [Symbol] :option_settings (optional) Elastic Beanstalk
|
68
|
+
# settings that will apply to the environments you deploying. Value should be
|
69
|
+
# array of hash with format such as:
|
76
70
|
#
|
77
|
-
# :solution_stack_name (optional default "64bit Amazon Linux running Tomcat 7")
|
78
|
-
# The elastic beanstalk solution stack you want to deploy on top of.
|
79
|
-
# Current possible values include:
|
80
|
-
#
|
81
|
-
# :option_settings (or :settings) (optional)
|
82
|
-
# Elastic Beanstalk settings that will apply to the environments you
|
83
|
-
# deploying. Value should be array of hash with format such as:
|
84
71
|
# [{
|
85
72
|
# :namespace => 'aws:autoscaling:launchconfiguration',
|
86
73
|
# :option_name => 'InstanceType',
|
87
74
|
# :value => 'm1.small' }]
|
88
|
-
#
|
89
|
-
#
|
75
|
+
#
|
76
|
+
# When there are many, Using an external yaml file to hold those
|
77
|
+
# configuration is recommended. Such as:
|
78
|
+
#
|
90
79
|
# YAML.load(File.read("my_settings_file.yml"))
|
91
|
-
# For all available options take a look at
|
92
|
-
# http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html
|
93
|
-
#
|
94
|
-
# :resources (optional)
|
95
|
-
# If :resources specified, EBDeployer will use the CloudFormation
|
96
|
-
# template you provide to create a default CloudFormation stack with
|
97
|
-
# name <application_name>-<env-name> for the environment current
|
98
|
-
# deploying. Value of resources need to be hash with following
|
99
|
-
# keys:
|
100
|
-
# :template => CloudFormation template file with JSON format
|
101
|
-
# :parameters (or :inputs) => A Hash, input values for the CloudFormation
|
102
|
-
# template
|
103
|
-
# :transforms => A Hash with key map to your CloudFormation
|
104
|
-
# template outputs and value as lambda that return a single or array of
|
105
|
-
# elastic beanstalk settings.
|
106
|
-
# :capabilities => An array. You need set it to ['CAPABILITY_IAM']
|
107
|
-
# if you want to provision IAM Instance Profile.
|
108
|
-
#
|
109
|
-
# :strategy (optional default :blue-green)
|
110
|
-
# There are two options: blue-green or inplace-update. Blue green
|
111
|
-
# keep two elastic beanstalk environments and always deploy to
|
112
|
-
# inactive one, to achive zero downtime. inplace-update strategy
|
113
|
-
# will only keep one environment, and update the version inplace on
|
114
|
-
# deploy. this will save resources but will have downtime.
|
115
|
-
#
|
116
|
-
# :phoenix_mode (optional default false)
|
117
|
-
# If phoenix mode is turn on, it will terminate the old elastic
|
118
|
-
# beanstalk environment and recreate on deploy. For blue-green
|
119
|
-
# deployment it terminate the inactive environment first then
|
120
|
-
# recreate it. This is useful to avoiding configuration drift and
|
121
|
-
# accumulating state on the ec2 instances. Also it has the benifit of
|
122
|
-
# keeping your ec2 instance system package upto date, because everytime ec2
|
123
|
-
# instance boot up from AMI it does a system update.
|
124
|
-
#
|
125
|
-
# :smoke_test (optional)
|
126
|
-
# Value should be a proc or a lambda which accept single argument that will
|
127
|
-
# passed in as environment DNS name. Smoke test proc or lambda will be
|
128
|
-
# called at the end of the deployment for inplace-update deployment
|
129
|
-
# strategy. For blue-green deployment it will run after inactive
|
130
|
-
# environment update finish and before switching.
|
131
|
-
# Defining a smoke test is high recommended for serious usage. The
|
132
|
-
# simplest one could just be checking the server is up using curl, e.g.
|
133
|
-
#
|
134
|
-
# :smoke_test => lambda { |host|
|
135
|
-
# curl_http_code = "curl -k -s -o /dev/null -w \"%{http_code}\" https://#{host}"
|
136
|
-
# Timeout.timeout(600) do
|
137
|
-
# while `#{curl_http_code}`.strip != '200'
|
138
|
-
# sleep 5
|
139
|
-
# end
|
140
|
-
# end
|
141
|
-
# }
|
142
80
|
#
|
81
|
+
# For all available options take a look at
|
82
|
+
# http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options.html
|
143
83
|
#
|
84
|
+
# @option opts [Symbol] :phoenix_mode (false) If phoenix mode is turn on, it
|
85
|
+
# will terminate the old elastic beanstalk environment and recreate on
|
86
|
+
# deploy. For blue-green deployment it terminate the inactive environment
|
87
|
+
# first then recreate it. This is useful to avoiding configuration drift and
|
88
|
+
# accumulating state on the EC2 instances. Also it has the benifit of keeping
|
89
|
+
# your EC2 instance system package upto date, because everytime EC2 instance
|
90
|
+
# boot up from AMI it does a system update.
|
91
|
+
#
|
92
|
+
#
|
93
|
+
# @option opts [Symbol] :region set the region for application deployment
|
94
|
+
# (e.g. "us-west-2", "us-east-1"). See available zones at
|
95
|
+
# http://aws.amazon.com/elasticbeanstalk/faqs/#regions
|
96
|
+
#
|
97
|
+
# @option opts [Symbol] :resources If :resources specified, EBDeployer will
|
98
|
+
# use the CloudFormation template you provide to create a default
|
99
|
+
# CloudFormation stack with name <application_name>-<env-name> for the
|
100
|
+
# environment current deploying. Value of resources need to be hash with
|
101
|
+
# following keys:
|
102
|
+
#
|
103
|
+
# :template => CloudFormation template file with JSON format
|
104
|
+
# :parameters (or :inputs) => A Hash, input values for the CloudFormation template
|
105
|
+
# :transforms => A Hash with key map to your CloudFormation
|
106
|
+
# template outputs and value as lambda that return a single or array of
|
107
|
+
# elastic beanstalk settings.
|
108
|
+
#
|
109
|
+
# :capabilities => An array. You need set it to ['CAPABILITY_IAM']
|
110
|
+
#
|
111
|
+
# if you want to provision IAM Instance Profile.
|
112
|
+
#
|
113
|
+
# @option opts [Symbol] :settings See `option_settings`
|
114
|
+
#
|
115
|
+
# @option opts [Symbol] :smoke_test Value should be a proc or a lambda which
|
116
|
+
# accept single argument that will passed in as environment DNS name. Smoke
|
117
|
+
# test proc or lambda will be called at the end of the deployment for
|
118
|
+
# inplace-update deployment strategy. For blue-green deployment it will run
|
119
|
+
# after inactive environment update finish and before switching. Defining a
|
120
|
+
# smoke test is high recommended for serious usage. The simplest one could
|
121
|
+
# just be checking the server is up using curl, e.g.
|
122
|
+
#
|
123
|
+
# :smoke_test => lambda { |host|
|
124
|
+
# curl_http_code = "curl -k -s -o /dev/null -w \"%{http_code}\" https://#{host}"
|
125
|
+
# Timeout.timeout(600) do
|
126
|
+
# while `#{curl_http_code}`.strip != '200'
|
127
|
+
# sleep 5
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
# }
|
131
|
+
#
|
132
|
+
# @option opts [Symbol] :strategy (:blue-green) There are two options:
|
133
|
+
# blue-green or inplace-update. Blue green keep two elastic beanstalk
|
134
|
+
# environments and always deploy to inactive one, to achive zero downtime.
|
135
|
+
# inplace-update strategy will only keep one environment, and update the
|
136
|
+
# version inplace on deploy. this will save resources but will have downtime.
|
137
|
+
#
|
138
|
+
# @option opts [Symbol] :solution_stack_name ("64bit Amazon Linux running Tomcat 7")
|
139
|
+
# The elastic beanstalk solution stack you want to deploy on top of.
|
140
|
+
#
|
141
|
+
# @option opts [Symbol] :version_label *required*. Version label give the
|
142
|
+
# package uploaded a unique identifier. Should use something related to
|
143
|
+
# pipeline counter if you have build pipeline setup to build the installer.
|
144
|
+
# For the convient of dev we recommend use md5 digest of the installer so
|
145
|
+
# that everytime you upload new installer it forms a new version. e.g.
|
146
|
+
#
|
147
|
+
# :version_label => ENV['MY_PIPELINE_COUNTER']
|
148
|
+
# || "dev-" + Digest::MD5.file(my_package).hexdigest
|
144
149
|
#
|
145
|
-
|
146
150
|
def self.deploy(opts)
|
147
151
|
# AWS.config(:logger => Logger.new($stdout))
|
148
152
|
if region = opts[:region]
|
@@ -58,13 +58,13 @@ module EbDeployer
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.create(strategy_name, app, env_name, eb_driver, env_creation_opts={})
|
61
|
-
case strategy_name.
|
62
|
-
when
|
61
|
+
case strategy_name.to_s
|
62
|
+
when 'inplace_update', 'inplace-update'
|
63
63
|
InplaceUpdate.new(app, env_name, eb_driver, env_creation_opts)
|
64
|
-
when
|
64
|
+
when 'blue_green', 'blue-green'
|
65
65
|
BlueGreen.new(app, env_name, eb_driver, env_creation_opts)
|
66
66
|
else
|
67
|
-
raise 'strategy_name:' + strategy_name + ' not supported'
|
67
|
+
raise 'strategy_name: ' + strategy_name.to_s + ' not supported'
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
data/lib/eb_deployer/version.rb
CHANGED
data/test/deploy_test.rb
CHANGED
@@ -97,7 +97,7 @@ class DeployTest < Minitest::Test
|
|
97
97
|
def test_blue_green_deployment_strategy_should_create_blue_env_on_first_deployment
|
98
98
|
deploy(:application => 'simple',
|
99
99
|
:environment => "production",
|
100
|
-
:strategy => '
|
100
|
+
:strategy => 'blue-green',
|
101
101
|
:version_label => 42)
|
102
102
|
|
103
103
|
assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production-a'))
|
@@ -108,12 +108,12 @@ class DeployTest < Minitest::Test
|
|
108
108
|
def test_blue_green_deployment_should_create_green_env_if_blue_exists
|
109
109
|
deploy(:application => 'simple',
|
110
110
|
:environment => "production",
|
111
|
-
:strategy => '
|
111
|
+
:strategy => 'blue-green',
|
112
112
|
:version_label => 42)
|
113
113
|
|
114
114
|
deploy(:application => 'simple',
|
115
115
|
:environment => "production",
|
116
|
-
:strategy => '
|
116
|
+
:strategy => 'blue-green',
|
117
117
|
:version_label => 43)
|
118
118
|
|
119
119
|
assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production-a'))
|
@@ -124,12 +124,12 @@ class DeployTest < Minitest::Test
|
|
124
124
|
def test_blue_green_deployment_should_swap_cname_to_make_active_most_recent_updated_env
|
125
125
|
deploy(:application => 'simple',
|
126
126
|
:environment => "production",
|
127
|
-
:strategy => '
|
127
|
+
:strategy => 'blue-green',
|
128
128
|
:version_label => 42)
|
129
129
|
|
130
130
|
deploy(:application => 'simple',
|
131
131
|
:environment => "production",
|
132
|
-
:strategy => '
|
132
|
+
:strategy => 'blue-green',
|
133
133
|
:version_label => 43)
|
134
134
|
|
135
135
|
assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-a')))
|
@@ -139,7 +139,7 @@ class DeployTest < Minitest::Test
|
|
139
139
|
|
140
140
|
deploy(:application => 'simple',
|
141
141
|
:environment => "production",
|
142
|
-
:strategy => '
|
142
|
+
:strategy => 'blue-green',
|
143
143
|
:version_label => 44)
|
144
144
|
|
145
145
|
assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-b')))
|
@@ -154,7 +154,7 @@ class DeployTest < Minitest::Test
|
|
154
154
|
[42, 43, 44].each do |version_label|
|
155
155
|
deploy(:application => 'simple',
|
156
156
|
:environment => "production",
|
157
|
-
:strategy => '
|
157
|
+
:strategy => 'blue-green',
|
158
158
|
:smoke_test => smoke_test,
|
159
159
|
:version_label => version_label)
|
160
160
|
end
|
@@ -248,13 +248,13 @@ class DeployTest < Minitest::Test
|
|
248
248
|
def test_blue_green_deployment_should_delete_and_recreate_inactive_env_if_phoenix_mode_is_enabled
|
249
249
|
deploy(:application => 'simple',
|
250
250
|
:environment => "production",
|
251
|
-
:strategy => '
|
251
|
+
:strategy => 'blue-green',
|
252
252
|
:version_label => 42,
|
253
253
|
:phoenix_mode => true)
|
254
254
|
|
255
255
|
deploy(:application => 'simple',
|
256
256
|
:environment => "production",
|
257
|
-
:strategy => '
|
257
|
+
:strategy => 'blue-green',
|
258
258
|
:version_label => 43,
|
259
259
|
:phoenix_mode => true)
|
260
260
|
|
@@ -266,7 +266,7 @@ class DeployTest < Minitest::Test
|
|
266
266
|
|
267
267
|
deploy(:application => 'simple',
|
268
268
|
:environment => "production",
|
269
|
-
:strategy => '
|
269
|
+
:strategy => 'blue-green',
|
270
270
|
:version_label => 44,
|
271
271
|
:phoenix_mode => true)
|
272
272
|
|
@@ -295,7 +295,7 @@ class DeployTest < Minitest::Test
|
|
295
295
|
|
296
296
|
def deploy(opts)
|
297
297
|
EbDeployer.deploy({:package => @sample_package,
|
298
|
-
:strategy => :
|
298
|
+
:strategy => :'inplace-update',
|
299
299
|
:version_label => 1}.merge(opts).merge(stubs))
|
300
300
|
end
|
301
301
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eb_deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|