eb_deployer_updated 0.8.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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +14 -0
  6. data/CHANGELOG.md +127 -0
  7. data/Gemfile +10 -0
  8. data/LICENSE +22 -0
  9. data/README.md +136 -0
  10. data/Rakefile +12 -0
  11. data/TODOS.md +11 -0
  12. data/bin/eb_deploy +13 -0
  13. data/eb_deployer.gemspec +22 -0
  14. data/lib/eb_deployer/application.rb +96 -0
  15. data/lib/eb_deployer/aws_driver/beanstalk.rb +158 -0
  16. data/lib/eb_deployer/aws_driver/cloud_formation_driver.rb +53 -0
  17. data/lib/eb_deployer/aws_driver/s3_driver.rb +35 -0
  18. data/lib/eb_deployer/aws_driver.rb +8 -0
  19. data/lib/eb_deployer/cf_event_source.rb +26 -0
  20. data/lib/eb_deployer/cloud_formation_provisioner.rb +120 -0
  21. data/lib/eb_deployer/component.rb +45 -0
  22. data/lib/eb_deployer/config_loader.rb +64 -0
  23. data/lib/eb_deployer/default_component.rb +32 -0
  24. data/lib/eb_deployer/default_config.rb +20 -0
  25. data/lib/eb_deployer/default_config.yml +159 -0
  26. data/lib/eb_deployer/deployment_strategy/blue_green.rb +79 -0
  27. data/lib/eb_deployer/deployment_strategy/blue_only.rb +45 -0
  28. data/lib/eb_deployer/deployment_strategy/inplace_update.rb +16 -0
  29. data/lib/eb_deployer/deployment_strategy.rb +20 -0
  30. data/lib/eb_deployer/eb_environment.rb +204 -0
  31. data/lib/eb_deployer/eb_event_source.rb +35 -0
  32. data/lib/eb_deployer/environment.rb +60 -0
  33. data/lib/eb_deployer/event_poller.rb +51 -0
  34. data/lib/eb_deployer/package.rb +39 -0
  35. data/lib/eb_deployer/resource_stacks.rb +20 -0
  36. data/lib/eb_deployer/smoke_test.rb +23 -0
  37. data/lib/eb_deployer/tasks.rb +45 -0
  38. data/lib/eb_deployer/throttling_handling.rb +17 -0
  39. data/lib/eb_deployer/utils.rb +33 -0
  40. data/lib/eb_deployer/version.rb +3 -0
  41. data/lib/eb_deployer/version_cleaner.rb +30 -0
  42. data/lib/eb_deployer.rb +339 -0
  43. data/lib/generators/eb_deployer/install/install_generator.rb +82 -0
  44. data/lib/generators/eb_deployer/install/templates/eb_deployer.rake +1 -0
  45. data/lib/generators/eb_deployer/install/templates/eb_deployer.yml.erb +181 -0
  46. data/lib/generators/eb_deployer/install/templates/ebextensions/01_postgres_packages.config +5 -0
  47. data/lib/generators/eb_deployer/install/templates/postgres_rds.json +88 -0
  48. data/test/aws_driver_stubs.rb +350 -0
  49. data/test/beanstalk_test.rb +23 -0
  50. data/test/blue_green_deploy_test.rb +114 -0
  51. data/test/blue_only_deploy_test.rb +78 -0
  52. data/test/cf_event_poller_test.rb +32 -0
  53. data/test/cloud_formation_provisioner_test.rb +47 -0
  54. data/test/config_loader_test.rb +205 -0
  55. data/test/deploy_test.rb +42 -0
  56. data/test/eb_environment_test.rb +120 -0
  57. data/test/eb_event_poller_test.rb +32 -0
  58. data/test/inplace_update_deploy_test.rb +110 -0
  59. data/test/multi_components_deploy_test.rb +164 -0
  60. data/test/rails_generators_test.rb +67 -0
  61. data/test/resources_deploy_test.rb +191 -0
  62. data/test/smoke_test_test.rb +23 -0
  63. data/test/template_deploy_test.rb +13 -0
  64. data/test/test_helper.rb +68 -0
  65. data/test/tier_setting_deploy_test.rb +24 -0
  66. data/test/versions_deploy_test.rb +120 -0
  67. metadata +194 -0
@@ -0,0 +1,164 @@
1
+ require 'deploy_test'
2
+
3
+ class MultiComponentsDeployTest < DeployTest
4
+ def test_deploy_with_components
5
+ do_deploy
6
+ assert @eb.environment_exists?('simple', t('prod-web', 'simple'))
7
+ assert @eb.environment_exists?('simple', t('prod-bg', 'simple'))
8
+ assert @eb.environment_exists?('simple', t('prod-api', 'simple'))
9
+ assert !@eb.environment_exists?('simple', t('prod', 'simple'))
10
+ end
11
+
12
+ def test_deploy_with_components_with_blue_green
13
+ do_bg_deploy
14
+ assert @eb.environment_exists?('simple', t('prod-web-a', 'simple'))
15
+ assert @eb.environment_exists?('simple', t('prod-bg-a', 'simple'))
16
+ assert @eb.environment_exists?('simple', t('prod-api-a', 'simple'))
17
+ do_bg_deploy
18
+ assert @eb.environment_exists?('simple', t('prod-web-b', 'simple'))
19
+ assert @eb.environment_exists?('simple', t('prod-bg-b', 'simple'))
20
+ assert @eb.environment_exists?('simple', t('prod-api-b', 'simple'))
21
+ end
22
+
23
+ def test_cname_include_component_name
24
+ do_deploy
25
+ assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web', 'simple'))
26
+ assert_equal 'simple-prod-api', @eb.environment_cname_prefix('simple', t('prod-api', 'simple'))
27
+ end
28
+
29
+ def test_cname_include_component_name_in_blue_green
30
+ do_bg_deploy
31
+ assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web-a', 'simple'))
32
+
33
+ do_bg_deploy
34
+ assert_equal 'simple-prod-web', @eb.environment_cname_prefix('simple', t('prod-web-b', 'simple'))
35
+ assert_equal 'simple-prod-web-inactive', @eb.environment_cname_prefix('simple', t('prod-web-a', 'simple'))
36
+ end
37
+
38
+ def test_components_inheritate_creation_options_from_environment
39
+ do_deploy
40
+ assert_equal 'WebServer', @eb.environment_tier('simple', t('prod-web', 'simple'))
41
+ end
42
+
43
+ def test_components_can_override_creation_opts
44
+ do_deploy(:tier => 'WebServer',
45
+ :components => [{'name' => 'web'}, {'name' => 'bg', 'tier' => "Worker"}])
46
+ assert_equal 'WebServer', @eb.environment_tier('simple', t('prod-web', 'simple'))
47
+ assert_equal 'Worker', @eb.environment_tier('simple', t('prod-bg', 'simple'))
48
+ end
49
+
50
+ def test_components_specific_eb_settings_will_override_env_eb_settings
51
+ minsize_3 = {:namespace => 'aws:autoscaling:launchconfiguration',
52
+ :option_name => 'MinSize',
53
+ :value => '3' }
54
+ minsize_2 = {:namespace => 'aws:autoscaling:launchconfiguration',
55
+ :option_name => 'MinSize',
56
+ :value => '2' }
57
+
58
+ do_deploy(:option_settings => [minsize_3],
59
+ :components => [{'name' => 'web'},
60
+ {'name' => 'api',
61
+ 'option_settings' => [minsize_2]}])
62
+ assert_equal [minsize_3], @eb.environment_settings('simple', t('prod-web', 'simple'))
63
+ assert_equal [minsize_3, minsize_2], @eb.environment_settings('simple', t('prod-api', 'simple'))
64
+ end
65
+
66
+ def test_override_deployment_strategy
67
+ do_deploy(:components => [{'name' => 'web',
68
+ 'strategy' => 'blue-green' },
69
+ {'name' => 'bg',
70
+ 'strategy' => 'inplace-update'}])
71
+
72
+ assert @eb.environment_exists?('simple', t('prod-web-a', 'simple'))
73
+ assert @eb.environment_exists?('simple', t('prod-bg', 'simple'))
74
+ end
75
+
76
+ def test_can_deploy_single_component
77
+ do_deploy(:component => "bg")
78
+ assert !@eb.environment_exists?('simple', t('prod-web', 'simple'))
79
+ assert !@eb.environment_exists?('simple', t('prod-api', 'simple'))
80
+ assert @eb.environment_exists?('simple', t('prod-bg', 'simple'))
81
+ end
82
+
83
+ def test_should_raise_exception_when_try_to_deploy_a_none_exists_component
84
+ assert_raises(RuntimeError) do
85
+ do_deploy(:component => "foo")
86
+ end
87
+ end
88
+
89
+
90
+ def test_can_have_inactive_settings_which_will_be_applied_to_inactive_env
91
+ settings = {:inactive_settings =>
92
+ [{:namespace => 'aws:autoscaling:launchconfiguration',
93
+ :option_name => 'MinSize',
94
+ :value => 1}],
95
+ :components =>
96
+ [{:name => 'web',
97
+ :option_settings =>
98
+ [{:namespace => 'aws:autoscaling:launchconfiguration',
99
+ :option_name => 'MinSize',
100
+ :value => 10}]}]}
101
+
102
+ do_bg_deploy(settings)
103
+ assert_equal 10, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
104
+
105
+ do_bg_deploy(settings)
106
+ assert_equal 1, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
107
+ assert_equal 10, @eb.environment_settings('simple', t('prod-web-b', 'simple')).last[:value]
108
+
109
+ do_bg_deploy(settings)
110
+ assert_equal 10, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
111
+ assert_equal 1, @eb.environment_settings('simple', t('prod-web-b', 'simple')).last[:value]
112
+ end
113
+
114
+ def test_can_provide_inactive_settings_at_component_level
115
+ settings = {:option_settings =>
116
+ [{:namespace => 'aws:autoscaling:launchconfiguration',
117
+ :option_name => 'MinSize',
118
+ :value => 10}],
119
+ :components =>
120
+ [{:name => 'web',
121
+ :inactive_settings =>
122
+ [{:namespace => 'aws:autoscaling:launchconfiguration',
123
+ :option_name => 'MinSize',
124
+ :value => 2}]},
125
+ {:name => 'api',
126
+ :inactive_settings =>
127
+ [{:namespace => 'aws:autoscaling:launchconfiguration',
128
+ :option_name => 'MinSize',
129
+ :value => 1}]}]}
130
+
131
+ do_bg_deploy(settings)
132
+ assert_equal 10, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
133
+ assert_equal 10, @eb.environment_settings('simple', t('prod-api-a', 'simple')).last[:value]
134
+
135
+ do_bg_deploy(settings)
136
+ assert_equal 2, @eb.environment_settings('simple', t('prod-web-a', 'simple')).last[:value]
137
+ assert_equal 1, @eb.environment_settings('simple', t('prod-api-a', 'simple')).last[:value]
138
+ end
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
149
+
150
+ private
151
+ def do_deploy(options={})
152
+ deploy({:application => 'simple',
153
+ :environment => 'prod',
154
+ :components => [{ 'name' => 'web' },
155
+ { 'name' => 'bg' },
156
+ { 'name' => 'api' }]
157
+ }.merge(options))
158
+ end
159
+
160
+ def do_bg_deploy(options={})
161
+ do_deploy(options.merge(:strategy => 'blue-green'))
162
+ end
163
+
164
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+ require 'rails'
3
+ require 'shellwords'
4
+ require 'generators/eb_deployer/install/install_generator'
5
+
6
+ class RailsGenratorsTest < Rails::Generators::TestCase
7
+ tests EbDeployer::Generators::InstallGenerator
8
+ destination File.expand_path('../../tmp', __FILE__)
9
+ setup :prepare_destination
10
+
11
+ setup do
12
+ mkdir_p path('config')
13
+ touch path('config/database.yml')
14
+ touch path('Gemfile')
15
+ end
16
+
17
+ test "install" do
18
+ run_generator
19
+
20
+ assert_file 'config/eb_deployer.yml'
21
+ assert_file 'lib/tasks/eb_deployer.rake'
22
+
23
+ assert_file 'config/rds.json'
24
+ assert_file '.ebextensions/01_postgres_packages.config'
25
+ assert_file 'config/database.yml', /database: <%= ENV\['DATABASE_NAME'\]/m, /host: <%= ENV\['DATABASE_HOST'\]/m
26
+ assert_file 'Gemfile', /gem "pg"/
27
+ end
28
+
29
+ test "should comment production configuration in database.yml" do
30
+ File.open(path('config/database.yml'), 'w') do |f|
31
+ f.write(<<-YAML)
32
+ development:
33
+ host: localhost
34
+
35
+ production:
36
+ host: localhost
37
+
38
+ test:
39
+ host: localhost
40
+ YAML
41
+ end
42
+ run_generator
43
+ assert_file 'config/database.yml', <<-YAML
44
+ development:
45
+ host: localhost
46
+
47
+ # production:
48
+ # host: localhost
49
+
50
+ test:
51
+ host: localhost
52
+
53
+ production:
54
+ adapter: postgresql
55
+ database: <%= ENV['DATABASE_NAME'] || 'tmp_production' %>
56
+ host: <%= ENV['DATABASE_HOST'] || 'localhost' %>
57
+ port: <%= ENV['DATABASE_PORT'] || 5432 %>
58
+ username: <%= ENV['DATABASE_USERNAME'] || #{ENV['USER'].inspect} %>
59
+ password: <%= ENV['DATABASE_PASSWORD'] %>
60
+ min_messages: ERROR
61
+ YAML
62
+ end
63
+
64
+ def path(*f)
65
+ File.join(destination_root, *f)
66
+ end
67
+ end
@@ -0,0 +1,191 @@
1
+ require 'deploy_test'
2
+
3
+ class ResourcesDeployTest < DeployTest
4
+
5
+ def test_deploy_with_resources_declared_will_create_a_cf_stack_for_env
6
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
7
+ deploy(:application => 'simple', :environment => "production",
8
+ :resources => {
9
+ :template => cf_template
10
+ })
11
+ assert @cf_driver.stack_exists?('simple-production')
12
+ assert_equal({}, @cf_driver.stack_config('simple-production')[:parameters])
13
+ assert_equal([], @cf_driver.stack_config('simple-production')[:capabilities])
14
+ assert_nil(@cf_driver.stack_config('simple-production')[:stack_policy_body])
15
+ end
16
+
17
+ def test_deploy_with_resources_declared_will_create_a_cf_stack_for_env_with_policy
18
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
19
+ cf_policy = sample_file("sample_policy.json", JSON.dump({'Policy' => {'P1' => {}}}))
20
+ deploy(:application => 'simple', :environment => "production",
21
+ :resources => {
22
+ :template => cf_template,
23
+ :policy => cf_policy
24
+ })
25
+ assert @cf_driver.stack_exists?('simple-production')
26
+ assert_equal({}, @cf_driver.stack_config('simple-production')[:parameters])
27
+ assert_equal([], @cf_driver.stack_config('simple-production')[:capabilities])
28
+ assert_equal("{\"Policy\":{\"P1\":{}}}", @cf_driver.stack_config('simple-production')[:stack_policy_body])
29
+ end
30
+
31
+ def test_deploy_with_resources_declared_will_update_a_cf_stack_for_env_with_policy
32
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
33
+ cf_policy = sample_file("sample_policy.json", JSON.dump({'Policy' => {'P1' => {}}}))
34
+ deploy(:application => 'simple', :environment => "production",
35
+ :resources => {
36
+ :template => cf_template,
37
+ :policy => cf_policy
38
+ })
39
+ assert @cf_driver.stack_exists?('simple-production')
40
+ deploy(:application => 'simple', :environment => "production",
41
+ :resources => {
42
+ :template => cf_template,
43
+ :policy => cf_policy,
44
+ :override_policy => false
45
+ })
46
+ assert_equal({}, @cf_driver.stack_config('simple-production')[:parameters])
47
+ assert_equal([], @cf_driver.stack_config('simple-production')[:capabilities])
48
+ assert_equal("{\"Policy\":{\"P1\":{}}}", @cf_driver.stack_config('simple-production')[:stack_policy_body])
49
+ end
50
+
51
+ def test_deploy_with_resources_declared_will_update_a_cf_stack_for_env_with_temp_policy
52
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
53
+ cf_policy = sample_file("sample_policy.json", JSON.dump({'Policy' => {'P1' => {}}}))
54
+ deploy(:application => 'simple', :environment => "production",
55
+ :resources => {
56
+ :template => cf_template,
57
+ :policy => cf_policy
58
+ })
59
+ assert @cf_driver.stack_exists?('simple-production')
60
+ deploy(:application => 'simple', :environment => "production",
61
+ :resources => {
62
+ :template => cf_template,
63
+ :policy => cf_policy,
64
+ :override_policy => true
65
+ })
66
+ assert_equal({}, @cf_driver.stack_config('simple-production')[:parameters])
67
+ assert_equal([], @cf_driver.stack_config('simple-production')[:capabilities])
68
+ assert_equal("{\"Policy\":{\"P1\":{}}}", @cf_driver.stack_config('simple-production')[:stack_policy_during_update_body])
69
+ end
70
+
71
+ def test_provision_resources_with_capacities
72
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
73
+ deploy(:application => 'simple', :environment => "production",
74
+ :resources => {
75
+ :template => cf_template,
76
+ :capabilities => ['CAPABILITY_IAM']
77
+ })
78
+ assert_equal ['CAPABILITY_IAM'], @cf_driver.stack_config('simple-production')[:capabilities]
79
+ end
80
+
81
+ def test_provision_resources_with_parameters
82
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
83
+ deploy(:application => 'simple', :environment => "production",
84
+ :resources => {
85
+ :template => cf_template,
86
+ :parameters => {'a' => 1}
87
+ })
88
+ assert_equal({'a' => 1 }, @cf_driver.stack_config('simple-production')[:parameters])
89
+ end
90
+
91
+ def test_skip_resource_update
92
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
93
+ deploy(:application => 'simple', :environment => "production",
94
+ :resources => {
95
+ :template => cf_template,
96
+ :parameters => {'a' => 1 }
97
+ })
98
+ assert_equal(1, @cf_driver.stack_config('simple-production')[:parameters]['a'])
99
+ deploy(:application => 'simple', :environment => "production",
100
+ :resources => {
101
+ :template => cf_template,
102
+ :parameters => {'a' => 2 }
103
+ })
104
+ assert_equal(2, @cf_driver.stack_config('simple-production')[:parameters]['a'])
105
+ deploy(:application => 'simple',
106
+ :environment => "production",
107
+ :skip_resource_stack_update => true,
108
+ :resources => {
109
+ :template => cf_template,
110
+ :parameters => {'a' => 3 }
111
+ })
112
+ assert_equal(2, @cf_driver.stack_config('simple-production')[:parameters]['a'])
113
+ end
114
+
115
+ def test_should_still_query_output_to_set_eb_options_even_skip_resources_update_is_specified
116
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}},
117
+ 'Outputs' => {'O1' => {}, 'O2' => {}}}))
118
+ deploy(:application => 'simple', :environment => "production",
119
+ :resources => {
120
+ :template => cf_template
121
+ })
122
+
123
+ deploy(:application => 'simple', :environment => "production",
124
+ :skip_resource_stack_update => true,
125
+ :resources => {
126
+ :template => cf_template,
127
+ :transforms => {
128
+ 'O2' => lambda { |v| {:namespace => 'aws.foo', :option_name => 'o2', :value => "transformed " + v} }
129
+ }
130
+ })
131
+
132
+ assert @eb.environment_settings('simple', t('production', 'simple')).
133
+ include?({:namespace => 'aws.foo', :option_name => 'o2', :value => 'transformed value of O2'})
134
+ end
135
+
136
+
137
+ def test_transforms_resource_provsion_output_to_elastic_beanstalk_settings
138
+ cf_template = temp_file(JSON.dump({
139
+ 'Resources' => {'R1' => {}},
140
+ 'Outputs' => {'O1' => {}, 'O2' => {}}
141
+ }))
142
+ deploy(:application => 'simple', :environment => "production",
143
+ :resources => {
144
+ :template => cf_template,
145
+ :transforms => {
146
+ 'O1' => lambda { |v| {:namespace => 'aws.foo', :option_name => 'o1', :value => v} }
147
+ }
148
+ })
149
+ assert @eb.environment_settings('simple', t('production', 'simple')).
150
+ include?({:namespace => 'aws.foo', :option_name => 'o1', :value => 'value of O1'})
151
+ end
152
+
153
+ def test_can_query_resource_stack_output_after_deploy
154
+ cf_template = temp_file(JSON.dump({
155
+ 'Resources' => {'R1' => {}},
156
+ 'Outputs' => {'O1' => {}, 'O2' => {}}
157
+ }))
158
+ deploy(:application => 'simple',
159
+ :environment => "production",
160
+ :resources => { :template => cf_template })
161
+ assert_equal 'value of O1', query_resource_output('O1',
162
+ :application => 'simple',
163
+ :environment => "production")
164
+ assert_equal 'value of O2', query_resource_output('O2',
165
+ :application => 'simple',
166
+ :environment => "production")
167
+
168
+ end
169
+
170
+ def test_should_raise_error_if_query_resources_that_have_not_been_provisioned_yet
171
+ assert_raises(EbDeployer::ResourceNotInReadyState) do
172
+ query_resource_output('O1',
173
+ :application => 'simple',
174
+ :environment => "production")
175
+ end
176
+ end
177
+
178
+ def test_custom_stack_name
179
+ cf_template = temp_file(JSON.dump({
180
+ 'Resources' => {'R1' => {}},
181
+ 'Outputs' => {'O1' => {}, 'O2' => {}}
182
+ }))
183
+ deploy(:application => 'simple',
184
+ :environment => "production",
185
+ :resources => { :template => cf_template },
186
+ :stack_name => 'my-lovely-stack')
187
+
188
+ assert !@cf_driver.stack_exists?('simple-production')
189
+ assert @cf_driver.stack_exists?('my-lovely-stack')
190
+ end
191
+ end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class SmokeTestTest < Test::Unit::TestCase
4
+ def test_call_proc_type_smoke_tests
5
+ host_name_in_proc = nil
6
+ EbDeployer::SmokeTest.new(lambda {|v| host_name_in_proc = v }).run("foo")
7
+
8
+ assert_equal 'foo', host_name_in_proc
9
+ end
10
+
11
+ def test_eval_string_type_smoke_test
12
+ $host_name_in_proc = nil
13
+ EbDeployer::SmokeTest.new("$host_name_in_proc=host_name").run("foo")
14
+ assert_equal 'foo', $host_name_in_proc
15
+ end
16
+
17
+ def test_should_raise_if_test_body_raise
18
+ assert_raises(RuntimeError) do
19
+ EbDeployer::SmokeTest.new("raise host_name").run("foo")
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'deploy_test'
2
+
3
+ class TemplateDeployTest < DeployTest
4
+ def test_default_no_template
5
+ deploy(:application => 'simple', :environment => "production")
6
+ assert_equal nil, @eb.template_name('simple', t('production', 'simple'))
7
+ end
8
+
9
+ def test_can_set_a_template
10
+ deploy(:application => 'simple', :environment => "production", :template_name => 'SomeTemplate')
11
+ assert_equal 'SomeTemplate', @eb.template_name('simple', t('production', 'simple'))
12
+ end
13
+ end
@@ -0,0 +1,68 @@
1
+ $:.unshift(File.expand_path("../../lib", __FILE__))
2
+
3
+ require 'tempfile'
4
+ require 'eb_deployer'
5
+ require 'aws_driver_stubs'
6
+ require 'test/unit'
7
+
8
+ def silence_warnings(&block)
9
+ old_verbose, $VERBOSE = $VERBOSE, nil
10
+ yield
11
+ ensure
12
+ $VERBOSE = old_verbose
13
+ end
14
+
15
+ silence_warnings { EbDeployer::Utils::BACKOFF_INITIAL_SLEEP = 0 }
16
+ silence_warnings { EbDeployer::EventPoller::POLL_INTERVAL = 0 }
17
+
18
+ class ErrorRaisingWrapper < SimpleDelegator
19
+ def initialize(stub)
20
+ @errors = {}
21
+ super(stub)
22
+ end
23
+
24
+ def set_error(method, error)
25
+ set_error_generator(method) do
26
+ error
27
+ end
28
+ end
29
+
30
+ def set_error_generator(method, &error_gen)
31
+ define_delegate_method(method)
32
+ @errors[method] = Proc.new(&error_gen)
33
+ end
34
+
35
+ private
36
+ def define_delegate_method(method)
37
+ method = method.to_s
38
+ original_method_name = "__#{method}_without_error"
39
+ raise "method #{method} not defined" unless self.respond_to?(method)
40
+ return if self.respond_to?(original_method_name)
41
+
42
+ self.instance_eval <<-CODE
43
+ def #{original_method_name}(*args, &block)
44
+ self.__get_obj__.send(:#{method}, *args, &block)
45
+ end
46
+
47
+ def #{method}(*args, &block)
48
+ if error_gen = @errors[:#{method}]
49
+ error = error_gen.call
50
+ raise error if error
51
+ end
52
+ super
53
+ end
54
+ CODE
55
+ end
56
+ end
57
+
58
+ class Test::Unit::TestCase
59
+ def sample_file(file_name, content='s' * 100)
60
+ path = File.join('/tmp', file_name)
61
+ File.open(path, 'w') { |f| f << content }
62
+ path
63
+ end
64
+
65
+ def t(env, app_name)
66
+ EbDeployer::EbEnvironment.unique_ebenv_name(env, app_name)
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ require 'deploy_test'
2
+
3
+ class TierSettingDeployTest < DeployTest
4
+ def test_sets_default_tier_as_webserver
5
+ deploy(:application => 'simple', :environment => "production")
6
+ assert_equal 'WebServer', @eb.environment_tier('simple', t('production', 'simple'))
7
+ end
8
+
9
+ def test_can_change_tier
10
+ deploy(:application => 'simple', :environment => "production", :tier => 'Worker')
11
+ assert_equal 'Worker', @eb.environment_tier('simple', t('production', 'simple'))
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
24
+ end
@@ -0,0 +1,120 @@
1
+ require 'deploy_test'
2
+
3
+ class VersionsDeployTest < DeployTest
4
+
5
+ def test_deployment_with_s3_package_specification
6
+ File.open('mingle_package.yml', 'w') do |f|
7
+ f.write("s3_bucket: test-bucket\n")
8
+ f.write("s3_key: test-mingle.war")
9
+ end
10
+
11
+ deploy(:application => 'simple', :environment => "production",
12
+ :package => 'mingle_package.yml', :version_label => 1)
13
+ assert @eb.application_exists?('simple')
14
+ last_version = @eb.application_versions('simple').last
15
+ assert_equal({'s3_bucket' => 'test-bucket', 's3_key' => 'test-mingle.war'}, last_version[:source_bundle])
16
+ ensure
17
+ FileUtils.rm_rf('mingle_package.yml')
18
+ end
19
+
20
+
21
+
22
+ def test_version_prefix_should_be_prepended_to_version_label
23
+ deploy(:application => 'simple',
24
+ :environment => "production",
25
+ :version_label => 1,
26
+ :version_prefix => "prod-")
27
+ assert_equal 'prod-1', @eb.environment_verion_label('simple', t('production', 'simple'))
28
+ end
29
+
30
+ def test_should_keep_only_number_of_versions_specified
31
+ deploy(:application => 'simple',
32
+ :environment => "production",
33
+ :version_label => 1)
34
+
35
+ deploy(:application => 'simple',
36
+ :environment => "production",
37
+ :version_label => 2)
38
+
39
+ deploy(:application => 'simple',
40
+ :environment => "production",
41
+ :version_label => 3,
42
+ :keep_latest => 2)
43
+
44
+ assert_equal '1', @eb.versions_deleted('simple').first
45
+ end
46
+
47
+ def test_should_only_remove_versions_with_matching_prefix
48
+ deploy(:application => 'simple',
49
+ :environment => "production",
50
+ :version_label => 1,
51
+ :version_prefix => "prod1-",
52
+ :keep_latest => 1)
53
+ deploy(:application => 'simple',
54
+ :environment => "production",
55
+ :version_label => 2,
56
+ :version_prefix => "prod1-",
57
+ :keep_latest => 1)
58
+ deploy(:application => 'simple',
59
+ :environment => "production",
60
+ :version_label => 1,
61
+ :version_prefix => "prod2-",
62
+ :keep_latest => 1)
63
+
64
+ assert_equal 'prod1-1', @eb.versions_deleted('simple').first
65
+ assert_equal 1, @eb.versions_deleted('simple').count
66
+
67
+ app_versions = @eb.application_versions('simple').map { |apv| apv[:version_label] }
68
+ assert_equal ["prod1-2", "prod2-1"], app_versions
69
+ end
70
+
71
+ def test_default_cname_that_deployed_should_app_env_name
72
+ deploy(:application => 'simple',
73
+ :environment => "production",
74
+ :version_label => 42)
75
+ assert_equal "simple-production", @eb.environment_cname_prefix('simple', t('production', 'simple'))
76
+ end
77
+
78
+ def test_cname_prefix_can_be_override
79
+ deploy(:application => 'simple',
80
+ :environment => "production",
81
+ :cname_prefix => 'sports123',
82
+ :version_label => 42)
83
+ assert_equal "sports123", @eb.environment_cname_prefix('simple', t('production', 'simple'))
84
+ end
85
+
86
+ def test_pass_s3_object_name_as_package_file
87
+ package_name = 'test-bucket:test-mingle.war'
88
+
89
+ deploy(:package => package_name,
90
+ :application => 'simple',
91
+ :environment => "production",
92
+ :version_label => 1)
93
+
94
+ assert @eb.application_exists?('simple')
95
+ last_version = @eb.application_versions('simple').last
96
+ assert_equal({'s3_bucket' => 'test-bucket', 's3_key' => 'test-mingle.war'}, last_version[:source_bundle])
97
+ end
98
+
99
+ def test_set_s3_bucket_name_on_deployment
100
+ deploy(:application => 'simple',
101
+ :environment => "production",
102
+ :package_bucket => 'thoughtworks.simple')
103
+
104
+ assert @s3_driver.bucket_exists?('thoughtworks.simple.packages')
105
+ end
106
+
107
+
108
+ def test_pass_pathname_as_package_file
109
+ deploy(:package => Pathname.new(@sample_package),
110
+ :application => 'simple',
111
+ :environment => "production",
112
+ :package_bucket => 'thoughtworks.simple')
113
+
114
+ s3_objects = @s3_driver.objects('thoughtworks.simple.packages')
115
+ assert_equal 1, s3_objects.size
116
+ assert_equal @sample_package, s3_objects.values.first.to_s
117
+ end
118
+
119
+
120
+ end