eb_deployer 0.0.4 → 0.0.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.
@@ -26,7 +26,7 @@ module EbDeployer
26
26
 
27
27
  def deploy(version_label, env_settings)
28
28
  if !envs.any?(&method(:active_env?))
29
- env('blue', @major_cname_prefix).
29
+ env('a', @major_cname_prefix).
30
30
  deploy(version_label, env_settings)
31
31
  return
32
32
  end
@@ -44,11 +44,11 @@ module EbDeployer
44
44
  end
45
45
 
46
46
  def envs
47
- [env('blue'), env('green')]
47
+ [env('a'), env('b')]
48
48
  end
49
49
 
50
- def env(color, cname_prefix=nil)
51
- Environment.new(@app, @env_name + '-' + color, @eb_driver,
50
+ def env(suffix, cname_prefix=nil)
51
+ Environment.new(@app, @env_name + '-' + suffix, @eb_driver,
52
52
  :solution_stack => @solution_stack,
53
53
  :cname_prefix => cname_prefix || inactive_cname_prefix,
54
54
  :smoke_test => @smoke_test)
@@ -1,9 +1,16 @@
1
1
  module EbDeployer
2
2
  class Environment
3
3
  attr_reader :app, :name
4
+
5
+ def self.unique_ebenv_name(app_name, env_name)
6
+ raise "Environment name #{env_name} is too long, it must be under 15 chars" if env_name.size > 15
7
+ digest = Digest::SHA1.hexdigest(app_name + '-' + env_name)[0..6]
8
+ "#{env_name}-#{digest}"
9
+ end
10
+
4
11
  def initialize(app, env_name, eb_driver, creation_opts={})
5
12
  @app = app
6
- @name = @app + '-' + env_name
13
+ @name = self.class.unique_ebenv_name(app, env_name)
7
14
  @bs = eb_driver
8
15
  @creation_opts = creation_opts
9
16
  @poller = EventPoller.new(@app, @name, @bs)
@@ -30,6 +37,14 @@ module EbDeployer
30
37
 
31
38
  private
32
39
 
40
+
41
+ def shorten(str, max_length, digest_length=5)
42
+ raise "max length (#{max_length}) should be larger than digest_length (#{digest_length})" if max_length < digest_length
43
+ return self if str.size <= max_length
44
+ sha1 = Digest::SHA1.hexdigest(str)
45
+ sha1[0..(digest_length - 1)] + str[(max_length - digest_length - 1)..-1]
46
+ end
47
+
33
48
  def create_or_update_env(version_label, settings)
34
49
  if @bs.environment_exists?(@app, @name)
35
50
  @bs.update_environment(@app, @name, version_label, settings)
@@ -1,3 +1,3 @@
1
1
  module EbDeployer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -6,6 +6,7 @@ class EBStub
6
6
 
7
7
  def create_environment(app, env, solution_stack, cname_prefix, version, settings)
8
8
  raise 'cname prefix is not avaible' if @envs.values.detect { |env| env[:cname_prefix] == cname_prefix }
9
+ raise "env name #{env} is longer than 23 chars" if env.size > 23
9
10
  @envs[env_key(app, env)] = {
10
11
  :solution_stack => solution_stack,
11
12
  :version => version,
data/test/deploy_test.rb CHANGED
@@ -19,30 +19,38 @@ class DeployTest < Minitest::Test
19
19
 
20
20
 
21
21
  def test_first_deployment_create_environment
22
- assert !@eb_driver.environment_exists?('simple', 'simple-production')
22
+ assert !@eb_driver.environment_exists?('simple', eb_envname('simple', 'production'))
23
23
  deploy(:application => 'simple', :environment => "production")
24
- assert @eb_driver.environment_exists?('simple', 'simple-production')
24
+ assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production'))
25
25
  end
26
26
 
27
+ def test_support_very_very_long_app_name
28
+ deploy(:application => 'ver-very-simple-application', :environment => "production")
29
+ assert @eb_driver.environment_exists?('ver-very-simple-application', eb_envname('ver-very-simple-application', 'production'))
30
+ end
31
+
32
+ def test_should_raise_error_when_env_name_is_too_long
33
+ assert_raises(RuntimeError) { deploy(:application => 'simple', :environment => "p" * 16) }
34
+ end
27
35
 
28
36
  def test_update_environment_with_new_version_should_change_version_that_deployed
29
37
  deploy(:application => 'simple',
30
38
  :environment => "production",
31
39
  :version_label => 1)
32
- assert_equal '1', @eb_driver.environment_verion_label('simple', 'simple-production')
40
+ assert_equal '1', @eb_driver.environment_verion_label('simple', eb_envname('simple', 'production'))
33
41
 
34
42
  deploy(:application => 'simple',
35
43
  :environment => "production",
36
44
  :version_label => 2)
37
45
 
38
- assert_equal '2', @eb_driver.environment_verion_label('simple', 'simple-production')
46
+ assert_equal '2', @eb_driver.environment_verion_label('simple', eb_envname('simple', 'production'))
39
47
  end
40
48
 
41
49
  def test_default_cname_that_deployed_should_app_env_name
42
50
  deploy(:application => 'simple',
43
51
  :environment => "production",
44
52
  :version_label => 42)
45
- assert_equal "simple-production", @eb_driver.environment_cname_prefix('simple', 'simple-production')
53
+ assert_equal "simple-production", @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production'))
46
54
  end
47
55
 
48
56
  def test_cname_prefix_can_be_override
@@ -50,10 +58,9 @@ class DeployTest < Minitest::Test
50
58
  :environment => "production",
51
59
  :cname_prefix => 'sports123',
52
60
  :version_label => 42)
53
- assert_equal "sports123", @eb_driver.environment_cname_prefix('simple', 'simple-production')
61
+ assert_equal "sports123", @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production'))
54
62
  end
55
63
 
56
-
57
64
  def test_smoke_test_should_be_run_after_env_created_or_update
58
65
  host_for_smoke_test = nil
59
66
  deploy(:application => 'simple',
@@ -81,8 +88,8 @@ class DeployTest < Minitest::Test
81
88
  :strategy => 'blue_green',
82
89
  :version_label => 42)
83
90
 
84
- assert @eb_driver.environment_exists?('simple', 'simple-production-blue')
85
- assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', 'simple-production-blue')
91
+ assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production-a'))
92
+ assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-a'))
86
93
  end
87
94
 
88
95
 
@@ -97,8 +104,8 @@ class DeployTest < Minitest::Test
97
104
  :strategy => 'blue_green',
98
105
  :version_label => 43)
99
106
 
100
- assert @eb_driver.environment_exists?('simple', 'simple-production-blue')
101
- assert @eb_driver.environment_exists?('simple', 'simple-production-green')
107
+ assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production-a'))
108
+ assert @eb_driver.environment_exists?('simple', eb_envname('simple', 'production-b'))
102
109
  end
103
110
 
104
111
 
@@ -113,9 +120,9 @@ class DeployTest < Minitest::Test
113
120
  :strategy => 'blue_green',
114
121
  :version_label => 43)
115
122
 
116
- assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', 'simple-production-blue'))
123
+ assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-a')))
117
124
 
118
- assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', 'simple-production-green')
125
+ assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-b'))
119
126
 
120
127
 
121
128
  deploy(:application => 'simple',
@@ -123,9 +130,9 @@ class DeployTest < Minitest::Test
123
130
  :strategy => 'blue_green',
124
131
  :version_label => 44)
125
132
 
126
- assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', 'simple-production-green'))
133
+ assert_match(/simple-production-inactive/, @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-b')))
127
134
 
128
- assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', 'simple-production-blue')
135
+ assert_equal 'simple-production', @eb_driver.environment_cname_prefix('simple', eb_envname('simple', 'production-a'))
129
136
  end
130
137
 
131
138
 
@@ -144,4 +151,10 @@ class DeployTest < Minitest::Test
144
151
  'simple-production-inactive.elasticbeanstalk.com',
145
152
  'simple-production-inactive.elasticbeanstalk.com'], smoked_host
146
153
  end
154
+
155
+ private
156
+
157
+ def eb_envname(app_name, env_name)
158
+ EbDeployer::Environment.unique_ebenv_name(app_name, env_name)
159
+ end
147
160
  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.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: