eb_deployer 0.4.13 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  module EbDeployer
2
2
  module AWSDriver
3
3
  class Beanstalk
4
+ include Utils
4
5
  attr_reader :client
5
6
 
6
7
  def initialize(client=AWS::ElasticBeanstalk.new.client)
@@ -41,17 +42,16 @@ module EbDeployer
41
42
  end
42
43
 
43
44
  def create_environment(app_name, env_name, stack_name, cname_prefix, version, tier, tags, settings)
44
- request = {
45
+ request = reject_nil({
45
46
  :application_name => app_name,
46
47
  :environment_name => env_name,
47
48
  :solution_stack_name => stack_name,
48
49
  :version_label => version,
49
50
  :option_settings => settings,
50
51
  :tier => environment_tier(tier),
51
- :tags => tags,
52
- :cname_prefix => cname_prefix
53
- }
54
-
52
+ :cname_prefix => cname_prefix,
53
+ :tags => tags
54
+ })
55
55
  @client.create_environment(request)
56
56
  end
57
57
 
@@ -30,7 +30,7 @@ module EbDeployer
30
30
  def output(key)
31
31
  @cf_driver.query_output(@stack_name, key)
32
32
  rescue AWS::CloudFormation::Errors::ValidationError => e
33
- raise ResourceNotInReadyState.new("Resource stack(#{@stack_name}, key: #{key}) not in ready state yet, perhaps you should provision it first?")
33
+ raise ResourceNotInReadyState.new("Resource stack not in ready state yet, perhaps you should provision it first?")
34
34
  end
35
35
 
36
36
  private
@@ -18,24 +18,26 @@ module EbDeployer
18
18
  end
19
19
 
20
20
  def deploy(version_label, eb_settings, inactive_settings=[])
21
+ @strategy.test_compatibility(create_options)
21
22
  @strategy.deploy(version_label,
22
23
  eb_settings + @component_eb_settings,
23
24
  inactive_settings + @component_inactive_settings)
24
25
  end
25
26
 
26
27
  def new_eb_env(suffix=nil, cname_prefix_overriding=nil)
27
- env_name = [@env.name, @name, suffix].compact.join('-')
28
- creation_opts = @env.creation_opts.merge(@options)
29
- creation_opts = creation_opts.merge(:cname_prefix => cname_prefix_overriding || cname_prefix)
30
28
  EbEnvironment.new(@env.app_name,
31
- env_name,
29
+ [@env.name, @name, suffix].compact.join('-'),
32
30
  @eb_driver,
33
- creation_opts)
31
+ create_options.merge(:cname_prefix => cname_prefix_overriding || cname_prefix))
34
32
 
35
33
  end
36
34
 
37
35
  private
38
36
 
37
+ def create_options
38
+ @env.creation_opts.merge(@options)
39
+ end
40
+
39
41
  def default_cname_prefix
40
42
  [@env.app_name, @env.name, @name].join('-')
41
43
  end
@@ -11,8 +11,8 @@ module EbDeployer
11
11
  @creation_opts[:cname_prefix] || default_cname_prefix
12
12
  end
13
13
 
14
-
15
14
  def deploy(version_label, eb_settings, inactive_settings=[])
15
+ @strategy.test_compatibility(@creation_opts)
16
16
  @strategy.deploy(version_label, eb_settings, inactive_settings)
17
17
  end
18
18
 
@@ -5,6 +5,13 @@ module EbDeployer
5
5
  @env = env
6
6
  end
7
7
 
8
+ def test_compatibility(env_create_options)
9
+ tier = env_create_options[:tier]
10
+ if tier && tier.downcase == 'worker'
11
+ raise "Blue green deployment is not supported for Worker tier"
12
+ end
13
+ end
14
+
8
15
  def deploy(version_label, env_settings, inactive_settings=[])
9
16
  if !ebenvs.any?(&method(:active_ebenv?))
10
17
  ebenv('a', @env.cname_prefix).
@@ -5,6 +5,13 @@ module EbDeployer
5
5
  @env = env
6
6
  end
7
7
 
8
+ def test_compatibility(env_create_options)
9
+ tier = env_create_options[:tier]
10
+ if tier && tier.downcase == 'worker'
11
+ raise "Blue only deployment is not supported for Worker tier"
12
+ end
13
+ end
14
+
8
15
  def deploy(version_label, env_settings, inactive_settings=[])
9
16
  if !ebenvs.any?(&method(:active_ebenv?))
10
17
  ebenv('a', @env.cname_prefix).
@@ -5,6 +5,9 @@ module EbDeployer
5
5
  @env = env
6
6
  end
7
7
 
8
+ def test_compatibility(env_create_opts)
9
+ end
10
+
8
11
  def deploy(version_label, env_settings, inactive_settings)
9
12
  @env.new_eb_env.deploy(version_label, env_settings)
10
13
  end
@@ -63,18 +63,41 @@ module EbDeployer
63
63
 
64
64
  private
65
65
 
66
+ def configured_tier
67
+ @creation_opts[:tier]
68
+ end
69
+
70
+ def has_cname?
71
+ !configured_tier || configured_tier.downcase == 'webserver'
72
+ end
73
+
74
+ def configured_cname_prefix
75
+ @creation_opts[:cname_prefix]
76
+ end
77
+
66
78
  def create_eb_env(settings, version_label)
67
79
  solution_stack = @creation_opts[:solution_stack]
68
80
  tags = convert_tags_hash_to_array(@creation_opts.delete(:tags))
69
81
  validate_solutions_stack(solution_stack)
70
82
  with_polling_events(/Successfully launched environment/i) do
71
- @bs.create_environment(@app, @name, solution_stack, @creation_opts[:cname_prefix], version_label, @creation_opts[:tier], tags, settings)
83
+ @bs.create_environment(@app,
84
+ @name,
85
+ solution_stack,
86
+ has_cname? ? configured_cname_prefix : nil,
87
+ version_label,
88
+ configured_tier,
89
+ tags,
90
+ settings)
72
91
  end
73
92
  end
74
93
 
75
94
  def update_eb_env(settings, version_label)
76
95
  with_polling_events(/Environment update completed successfully/i) do
77
- @bs.update_environment(@app, @name, version_label, @creation_opts[:tier], settings)
96
+ @bs.update_environment(@app,
97
+ @name,
98
+ version_label,
99
+ configured_tier,
100
+ settings)
78
101
  end
79
102
  end
80
103
 
@@ -1,3 +1,3 @@
1
1
  module EbDeployer
2
- VERSION = "0.4.13"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -139,12 +139,14 @@ class EBStub
139
139
 
140
140
  def environment_cname_prefix(app_name, env_name)
141
141
  return unless @envs[env_key(app_name, env_name)]
142
- @envs[env_key(app_name, env_name)][:cname_prefix] || app_name + "-" + SecureRandom.hex
142
+ @envs[env_key(app_name, env_name)][:cname_prefix]
143
143
  end
144
144
 
145
145
  def environment_cname(app_name, env_name)
146
146
  return unless @envs[env_key(app_name, env_name)]
147
- environment_cname_prefix(app_name, env_name) + ".elasticbeanstalk.com"
147
+ if cname_prefix = environment_cname_prefix(app_name, env_name)
148
+ cname_prefix + ".elasticbeanstalk.com"
149
+ end
148
150
  end
149
151
 
150
152
 
@@ -7,13 +7,13 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_deploy_should_create_corresponding_eb_env
10
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
10
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
11
11
  env.deploy("version1")
12
12
  assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
13
13
  end
14
14
 
15
15
  def test_deploy_again_should_update_environment
16
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
16
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
17
17
  env.deploy("version1")
18
18
  env.deploy("version2")
19
19
  assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
@@ -21,20 +21,20 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
21
21
  end
22
22
 
23
23
  def test_option_setttings_get_set_on_eb_env
24
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
24
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
25
25
  env.deploy("version1", {s1: 'v1'})
26
26
  assert_equal({s1: 'v1' }, @eb_driver.environment_settings('myapp', t('production', 'myapp')))
27
27
  end
28
28
 
29
29
  def test_deploy_should_include_tags
30
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, {:tags => {:my_tag => 'my_value', :tag2 => 'value2'}})
30
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production', :tags => {:my_tag => 'my_value', :tag2 => 'value2'})
31
31
  env.deploy("version1")
32
32
  assert_equal [{:key => :my_tag, :value => 'my_value'}, {:key => :tag2, :value => 'value2'}], @eb_driver.environment_tags('myapp', t('production', 'myapp'))
33
33
  end
34
34
 
35
35
  def test_should_run_smoke_test_after_deploy
36
36
  smoked_host = nil
37
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :smoke_test => Proc.new { |host| smoked_host = host })
37
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :smoke_test => Proc.new { |host| smoked_host = host }, :cname_prefix => 'myapp-production')
38
38
  env.deploy("version1")
39
39
 
40
40
  assert !smoked_host.nil?
@@ -42,7 +42,7 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
42
42
  end
43
43
 
44
44
  def test_should_raise_runtime_error_when_deploy_failed
45
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
45
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
46
46
  @eb_driver.set_events("myapp", t("production", 'myapp'),
47
47
  [],
48
48
  ["start deploying", "Failed to deploy application"])
@@ -50,7 +50,7 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_should_raise_runtime_error_when_eb_extension_execution_failed
53
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
53
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
54
54
  @eb_driver.set_events("myapp", t("production", 'myapp'),
55
55
  [],
56
56
  ["start deploying",
@@ -62,7 +62,7 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
62
62
  end
63
63
 
64
64
  def test_should_raise_runtime_error_when_issues_during_launch
65
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
65
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
66
66
  @eb_driver.set_events("myapp", t("production", 'myapp'),
67
67
  [],
68
68
  ["start deploying",
@@ -73,7 +73,7 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
73
73
  end
74
74
 
75
75
  def test_terminate_should_delete_environment
76
- env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver)
76
+ env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
77
77
  env.deploy("version1")
78
78
  env.terminate
79
79
  assert !@eb_driver.environment_exists?('myapp', t('production', 'myapp'))
@@ -81,11 +81,23 @@ class EbEnvironmentTest < MiniTest::Unit::TestCase
81
81
 
82
82
  def test_should_raise_runtime_error_when_solution_stack_is_not_valid
83
83
  env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, {
84
+ :cname_prefix => 'myapp-production',
84
85
  :solution_stack => "python"
85
86
  })
86
87
  @eb_driver.set_solution_stacks(["java", "ruby"])
87
88
  assert_raises(RuntimeError) { env.deploy("version 1") }
88
89
  end
89
90
 
91
+ def test_should_no_set_cname_prefix_for_create_unless_for_web_tier
92
+ env = EbDeployer::EbEnvironment.new("myapp",
93
+ "production",
94
+ @eb_driver,
95
+ :tier => "Worker",
96
+ :cname_prefix => 'myapp-production')
97
+ env.deploy("version1")
98
+ assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
99
+ assert_nil @eb_driver.environment_cname_prefix('myapp', t('production', 'myapp'))
100
+ end
101
+
90
102
 
91
103
  end
@@ -135,10 +135,17 @@ class MultiComponentsDeployTest < DeployTest
135
135
  do_bg_deploy(settings)
136
136
  assert_equal 2, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
137
137
  assert_equal 1, @eb.environment_settings('simple', t('prod-api-a', 'simple')).last[:value]
138
-
139
-
140
138
  end
141
139
 
140
+ def test_should_raise_error_when_deploy_work_tier_component_with_blue_green
141
+ assert_raises(RuntimeError) do
142
+ deploy(:application => 'simple',
143
+ :environment => 'prod',
144
+ :strategy => 'blue-green',
145
+ :components => [{ 'name' => 'web' },
146
+ { 'name' => 'bg', 'tier' => 'worker' }])
147
+ end
148
+ end
142
149
 
143
150
  private
144
151
  def do_deploy(options={})
@@ -10,4 +10,15 @@ class TierSettingDeployTest < DeployTest
10
10
  deploy(:application => 'simple', :environment => "production", :tier => 'Worker')
11
11
  assert_equal 'Worker', @eb.environment_tier('simple', t('production', 'simple'))
12
12
  end
13
+
14
+ def test_should_worker_tier_should_not_have_cname_prefix
15
+ deploy(:application => 'simple', :environment => "production", :tier => 'Worker')
16
+ assert_nil @eb.environment_cname_prefix('simple', t('production', 'simple'))
17
+ end
18
+
19
+ def test_should_raise_error_when_deploy_worker_tier_with_blue_green
20
+ assert_raises(RuntimeError) do
21
+ deploy(:application => 'simple', :environment => "production", :tier => 'Worker', :strategy => 'blue-green')
22
+ end
23
+ end
13
24
  end
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.4.13
4
+ version: 0.5.0
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: 2015-03-15 00:00:00.000000000 Z
13
+ date: 2015-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk-v1