man_eb_deployer 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.
- checksums.yaml +7 -0
- data/.github/workflows/release.yml +31 -0
- data/.github/workflows/test.yml +16 -0
- data/.gitignore +12 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +143 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +138 -0
- data/Rakefile +12 -0
- data/TODOS.md +11 -0
- data/bin/eb_deploy +13 -0
- data/eb_deployer.gemspec +22 -0
- data/lib/eb_deployer/application.rb +96 -0
- data/lib/eb_deployer/aws_driver/beanstalk.rb +158 -0
- data/lib/eb_deployer/aws_driver/cloud_formation_driver.rb +53 -0
- data/lib/eb_deployer/aws_driver/s3_driver.rb +35 -0
- data/lib/eb_deployer/aws_driver.rb +8 -0
- data/lib/eb_deployer/cf_event_source.rb +26 -0
- data/lib/eb_deployer/cloud_formation_provisioner.rb +120 -0
- data/lib/eb_deployer/component.rb +45 -0
- data/lib/eb_deployer/config_loader.rb +64 -0
- data/lib/eb_deployer/default_component.rb +32 -0
- data/lib/eb_deployer/default_config.rb +20 -0
- data/lib/eb_deployer/default_config.yml +159 -0
- data/lib/eb_deployer/deployment_strategy/blue_green.rb +79 -0
- data/lib/eb_deployer/deployment_strategy/blue_only.rb +45 -0
- data/lib/eb_deployer/deployment_strategy/inplace_update.rb +16 -0
- data/lib/eb_deployer/deployment_strategy.rb +20 -0
- data/lib/eb_deployer/eb_environment.rb +204 -0
- data/lib/eb_deployer/eb_event_source.rb +35 -0
- data/lib/eb_deployer/environment.rb +60 -0
- data/lib/eb_deployer/event_poller.rb +51 -0
- data/lib/eb_deployer/package.rb +39 -0
- data/lib/eb_deployer/resource_stacks.rb +20 -0
- data/lib/eb_deployer/smoke_test.rb +23 -0
- data/lib/eb_deployer/tasks.rb +45 -0
- data/lib/eb_deployer/throttling_handling.rb +17 -0
- data/lib/eb_deployer/utils.rb +33 -0
- data/lib/eb_deployer/version.rb +3 -0
- data/lib/eb_deployer/version_cleaner.rb +30 -0
- data/lib/eb_deployer.rb +339 -0
- data/lib/generators/eb_deployer/install/install_generator.rb +82 -0
- data/lib/generators/eb_deployer/install/templates/eb_deployer.rake +1 -0
- data/lib/generators/eb_deployer/install/templates/eb_deployer.yml.erb +181 -0
- data/lib/generators/eb_deployer/install/templates/ebextensions/01_postgres_packages.config +5 -0
- data/lib/generators/eb_deployer/install/templates/postgres_rds.json +88 -0
- data/test/aws_driver_stubs.rb +350 -0
- data/test/beanstalk_test.rb +23 -0
- data/test/blue_green_deploy_test.rb +114 -0
- data/test/blue_only_deploy_test.rb +78 -0
- data/test/cf_event_poller_test.rb +32 -0
- data/test/cloud_formation_provisioner_test.rb +47 -0
- data/test/config_loader_test.rb +205 -0
- data/test/deploy_test.rb +42 -0
- data/test/eb_environment_test.rb +120 -0
- data/test/eb_event_poller_test.rb +32 -0
- data/test/inplace_update_deploy_test.rb +110 -0
- data/test/multi_components_deploy_test.rb +164 -0
- data/test/rails_generators_test.rb +67 -0
- data/test/resources_deploy_test.rb +191 -0
- data/test/smoke_test_test.rb +23 -0
- data/test/template_deploy_test.rb +13 -0
- data/test/test_helper.rb +68 -0
- data/test/tier_setting_deploy_test.rb +24 -0
- data/test/versions_deploy_test.rb +120 -0
- metadata +176 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'deploy_test'
|
2
|
+
|
3
|
+
class BlueGreenDeployTest < DeployTest
|
4
|
+
def test_blue_green_deployment_strategy_should_create_blue_env_on_first_deployment
|
5
|
+
do_deploy(42)
|
6
|
+
assert @eb.environment_exists?('simple', t('production-a', 'simple'))
|
7
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def test_blue_green_deployment_should_create_green_env_if_blue_exists
|
12
|
+
do_deploy(42)
|
13
|
+
do_deploy(43)
|
14
|
+
assert @eb.environment_exists?('simple', t('production-a', 'simple'))
|
15
|
+
assert @eb.environment_exists?('simple', t('production-b', 'simple'))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_blue_green_deployment_should_swap_cname_to_make_active_most_recent_updated_env
|
20
|
+
do_deploy(42)
|
21
|
+
do_deploy(43)
|
22
|
+
assert_match(/simple-production-inactive/, @eb.environment_cname_prefix('simple', t('production-a', 'simple')))
|
23
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-b', 'simple'))
|
24
|
+
do_deploy(44)
|
25
|
+
assert_match(/simple-production-inactive/, @eb.environment_cname_prefix('simple', t('production-b', 'simple')))
|
26
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def test_blue_green_deploy_should_run_smoke_test_before_cname_switch
|
31
|
+
smoked_host = []
|
32
|
+
smoke_test = lambda { |host| smoked_host << host }
|
33
|
+
[42, 43, 44].each do |version_label|
|
34
|
+
do_deploy(version_label, :smoke_test => smoke_test)
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal ['simple-production.us-west-1.elasticbeanstalk.com',
|
38
|
+
'simple-production-inactive.us-west-1.elasticbeanstalk.com',
|
39
|
+
'simple-production-inactive.us-west-1.elasticbeanstalk.com'], smoked_host
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_blue_green_deploy_should_blue_green_terminate_inactive_env_if_blue_green_terminate_inactive_is_enabled
|
43
|
+
do_deploy(42, :blue_green_terminate_inactive => true, :blue_green_terminate_inactive_wait => 1, :blue_green_terminate_inactive_sleep => 1)
|
44
|
+
do_deploy(43, :blue_green_terminate_inactive => true, :blue_green_terminate_inactive_wait => 0, :blue_green_terminate_inactive_sleep => 0)
|
45
|
+
|
46
|
+
inactive_env = t('production-a', 'simple')
|
47
|
+
assert_equal [inactive_env], @eb.environments_been_deleted('simple')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_blue_green_deployment_should_delete_and_recreate_inactive_env_if_phoenix_mode_is_enabled
|
51
|
+
do_deploy(42, :phoenix_mode => true)
|
52
|
+
do_deploy(43, :phoenix_mode => true)
|
53
|
+
assert_equal [], @eb.environments_been_deleted('simple')
|
54
|
+
|
55
|
+
inactive_env = t('production-a', 'simple')
|
56
|
+
assert_match(/inactive/, @eb.environment_cname_prefix('simple', inactive_env))
|
57
|
+
|
58
|
+
do_deploy(44, :phoenix_mode => true)
|
59
|
+
assert_equal [inactive_env], @eb.environments_been_deleted('simple')
|
60
|
+
|
61
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', inactive_env)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_destroy_should_clean_up_env
|
65
|
+
[42, 44].each do |version|
|
66
|
+
do_deploy(version)
|
67
|
+
end
|
68
|
+
|
69
|
+
destroy(:application => 'simple', :environment => 'production')
|
70
|
+
assert !@eb.environment_exists?('simple', t('production-a', 'simple'))
|
71
|
+
assert !@eb.environment_exists?('simple', t('production-b', 'simple'))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_can_have_inactive_settings_which_will_be_applied_to_inactive_env
|
75
|
+
settings = {:option_settings =>
|
76
|
+
[{:namespace => 'aws:autoscaling:launchconfiguration',
|
77
|
+
:option_name => 'MinSize',
|
78
|
+
:value => 10}],
|
79
|
+
:inactive_settings =>
|
80
|
+
[{:namespace => 'aws:autoscaling:launchconfiguration',
|
81
|
+
:option_name => 'MinSize',
|
82
|
+
:value => 1}]}
|
83
|
+
|
84
|
+
do_deploy(42, settings)
|
85
|
+
assert_equal 10, @eb.environment_settings('simple', t('production-a', 'simple')).last[:value]
|
86
|
+
assert_equal '42', @eb.environment_verion_label('simple', t('production-a', 'simple'))
|
87
|
+
|
88
|
+
do_deploy(43, settings)
|
89
|
+
assert_equal 1, @eb.environment_settings('simple', t('production-a', 'simple')).last[:value]
|
90
|
+
assert_equal '42', @eb.environment_verion_label('simple', t('production-a', 'simple'))
|
91
|
+
|
92
|
+
assert_equal 10, @eb.environment_settings('simple', t('production-b', 'simple')).last[:value]
|
93
|
+
assert_equal '43', @eb.environment_verion_label('simple', t('production-b', 'simple'))
|
94
|
+
|
95
|
+
|
96
|
+
do_deploy(44, settings)
|
97
|
+
assert_equal 10, @eb.environment_settings('simple', t('production-a', 'simple')).last[:value]
|
98
|
+
assert_equal '44', @eb.environment_verion_label('simple', t('production-a', 'simple'))
|
99
|
+
|
100
|
+
assert_equal 1, @eb.environment_settings('simple', t('production-b', 'simple')).last[:value]
|
101
|
+
assert_equal '43', @eb.environment_verion_label('simple', t('production-b', 'simple'))
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def do_deploy(version_label, options={})
|
108
|
+
deploy( {:application => 'simple',
|
109
|
+
:environment => "production",
|
110
|
+
:strategy => 'blue-green',
|
111
|
+
}.merge(options).merge(:version_label => version_label))
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'deploy_test'
|
2
|
+
|
3
|
+
class BlueOnlyDeployTest < DeployTest
|
4
|
+
def test_blue_only_deployment_strategy_should_create_blue_env_on_first_deployment
|
5
|
+
do_deploy(42)
|
6
|
+
assert @eb.environment_exists?('simple', t('production-a', 'simple'))
|
7
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def test_blue_only_deployment_should_create_green_env_if_blue_exists
|
12
|
+
do_deploy(42)
|
13
|
+
do_deploy(43)
|
14
|
+
assert @eb.environment_exists?('simple', t('production-a', 'simple'))
|
15
|
+
assert @eb.environment_exists?('simple', t('production-b', 'simple'))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_blue_only_deployment_should_not_swap_cname_to_make_active_most_recent_updated_env
|
20
|
+
do_deploy(42)
|
21
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
22
|
+
assert_nil(@eb.environment_cname_prefix('simple', t('production-b', 'simple')))
|
23
|
+
do_deploy(43)
|
24
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
25
|
+
assert_match(/simple-production-inactive/, @eb.environment_cname_prefix('simple', t('production-b', 'simple')))
|
26
|
+
do_deploy(44)
|
27
|
+
assert_equal 'simple-production', @eb.environment_cname_prefix('simple', t('production-a', 'simple'))
|
28
|
+
assert_match(/simple-production-inactive/, @eb.environment_cname_prefix('simple', t('production-b', 'simple')))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_blue_only_deploy_should_run_smoke_test_before_cname_switch
|
33
|
+
smoked_host = []
|
34
|
+
smoke_test = lambda { |host| smoked_host << host }
|
35
|
+
[42, 43, 44].each do |version_label|
|
36
|
+
do_deploy(version_label, :smoke_test => smoke_test)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal ['simple-production.us-west-1.elasticbeanstalk.com',
|
40
|
+
'simple-production-inactive.us-west-1.elasticbeanstalk.com',
|
41
|
+
'simple-production-inactive.us-west-1.elasticbeanstalk.com'], smoked_host
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def test_blue_only_deployment_should_delete_and_recreate_inactive_env_if_phoenix_mode_is_enabled
|
46
|
+
do_deploy(42, :phoenix_mode => true)
|
47
|
+
do_deploy(43, :phoenix_mode => true)
|
48
|
+
assert_equal [], @eb.environments_been_deleted('simple')
|
49
|
+
|
50
|
+
inactive_env = t('production-b', 'simple')
|
51
|
+
assert_match(/inactive/, @eb.environment_cname_prefix('simple', inactive_env))
|
52
|
+
|
53
|
+
do_deploy(44, :phoenix_mode => true)
|
54
|
+
assert_equal [inactive_env], @eb.environments_been_deleted('simple')
|
55
|
+
|
56
|
+
assert_match(/inactive/, @eb.environment_cname_prefix('simple', inactive_env))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_destroy_should_clean_up_env
|
60
|
+
[42, 44].each do |version|
|
61
|
+
do_deploy(version)
|
62
|
+
end
|
63
|
+
|
64
|
+
destroy(:application => 'simple', :environment => 'production')
|
65
|
+
assert !@eb.environment_exists?('simple', t('production-a', 'simple'))
|
66
|
+
assert !@eb.environment_exists?('simple', t('production-b', 'simple'))
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def do_deploy(version_label, options={})
|
72
|
+
deploy( {:application => 'simple',
|
73
|
+
:environment => "production",
|
74
|
+
:strategy => 'blue-only',
|
75
|
+
}.merge(options).merge(:version_label => version_label))
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CfEventPollerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@cf = CFStub.new
|
6
|
+
@poller = EbDeployer::EventPoller.new(EbDeployer::CfEventSource.new("mystack", @cf))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_run_handle_block_through_all_events_when_there_is_no_from_anchor
|
10
|
+
messages_handled = []
|
11
|
+
@cf.set_events('mystack', ['a', 'b', nil])
|
12
|
+
@poller.poll(nil) do |event|
|
13
|
+
break if event.resource_status.nil?
|
14
|
+
messages_handled << event.resource_status
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal ['a', 'b'], messages_handled
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def test_can_poll_all_events_after_an_anchor
|
22
|
+
@cf.set_events('mystack', ['a', 'b'], ['c', 'd', nil])
|
23
|
+
anchor = @poller.get_anchor
|
24
|
+
messages_handled = []
|
25
|
+
@poller.poll(anchor) do |event|
|
26
|
+
break if event.resource_status.nil?
|
27
|
+
messages_handled << event.resource_status
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_equal ['c', 'd'], messages_handled
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CloudFormationProvisionerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@cf = CFStub.new
|
6
|
+
@provisioner = EbDeployer::CloudFormationProvisioner.new("myresources", @cf)
|
7
|
+
@template = sample_file("sample_template.json")
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def test_convert_inputs_as_params_to_cf
|
12
|
+
resources = { 'template' => @template, 'inputs' => { 'Foo' => 'Bar' } }
|
13
|
+
@provisioner.provision(resources, [])
|
14
|
+
|
15
|
+
assert_equal({ 'Foo' => 'Bar' }, @cf.stack_config("myresources")[:parameters])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_transform_to_eb_settings
|
19
|
+
resources = { 'template' => @template,
|
20
|
+
'outputs' => {
|
21
|
+
'S' => {
|
22
|
+
'namespace' => "foo",
|
23
|
+
"option_name" => "bar"
|
24
|
+
}
|
25
|
+
}}
|
26
|
+
|
27
|
+
@provisioner.provision(resources, [])
|
28
|
+
settings = @provisioner.transform_outputs(resources)
|
29
|
+
assert_equal [{'namespace' => 'foo', 'option_name' => 'bar', 'value' => 'value of S'}], settings
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_stack_is_tagged
|
33
|
+
resources = { 'template' => @template }
|
34
|
+
|
35
|
+
@provisioner.provision(resources, [{key: 'Tag1', value: 'Value1'}])
|
36
|
+
|
37
|
+
assert_equal([{key: 'Tag1', value: 'Value1'}], @cf.stack_config("myresources")[:tags])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_stack_is_not_tagged_when_no_tags_specified
|
41
|
+
resources = { 'template' => @template }
|
42
|
+
|
43
|
+
@provisioner.provision(resources, [])
|
44
|
+
|
45
|
+
assert_equal([], @cf.stack_config("myresources")[:tags])
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ConfigLoaderTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@loader = EbDeployer::ConfigLoader.new
|
6
|
+
@sample_package = sample_file('app-package.war')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_all_default_cases
|
10
|
+
config = @loader.load(generate_input(<<-YAML))
|
11
|
+
application: myapp
|
12
|
+
common:
|
13
|
+
option_settings:
|
14
|
+
resources:
|
15
|
+
environments:
|
16
|
+
dev:
|
17
|
+
production:
|
18
|
+
YAML
|
19
|
+
assert_equal('myapp', config[:application])
|
20
|
+
assert_equal(@sample_package, config[:package])
|
21
|
+
assert_equal('dev', config[:environment])
|
22
|
+
assert_equal(md5_digest(@sample_package), config[:version_label])
|
23
|
+
assert_equal([], config[:option_settings])
|
24
|
+
assert_equal(nil, config[:resources])
|
25
|
+
assert_equal(nil, config[:common])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_use_package_as_version_label_when_using_s3_obj_as_package
|
29
|
+
config = @loader.load(generate_input(<<-YAML, :package => 'bucket:obj'))
|
30
|
+
application: myapp
|
31
|
+
common:
|
32
|
+
strategy: inplace-update
|
33
|
+
environments:
|
34
|
+
dev:
|
35
|
+
YAML
|
36
|
+
assert_equal('myapp', config[:application])
|
37
|
+
assert_equal('bucket:obj', config[:package])
|
38
|
+
assert_equal('bucket:obj', config[:version_label])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_common_settings_get_merge_into_the_config
|
42
|
+
config = @loader.load(generate_input(<<-YAML))
|
43
|
+
application: myapp
|
44
|
+
common:
|
45
|
+
strategy: inplace-update
|
46
|
+
package_bucket: thoughtworks
|
47
|
+
phoenix_mode: true
|
48
|
+
option_settings:
|
49
|
+
- namespace: aws:autoscaling:launchconfiguration
|
50
|
+
option_name: InstanceType
|
51
|
+
value: m1.small
|
52
|
+
resources:
|
53
|
+
environments:
|
54
|
+
dev:
|
55
|
+
production:
|
56
|
+
YAML
|
57
|
+
assert_equal('inplace-update', config[:strategy])
|
58
|
+
assert_equal('thoughtworks', config[:package_bucket])
|
59
|
+
assert_equal([{'namespace' => 'aws:autoscaling:launchconfiguration',
|
60
|
+
'option_name' => 'InstanceType',
|
61
|
+
'value' => 'm1.small'}], config[:option_settings])
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_eval_random_hash
|
65
|
+
yaml = <<-YAML
|
66
|
+
application: myapp
|
67
|
+
common:
|
68
|
+
resources:
|
69
|
+
template: config/my_rds.json
|
70
|
+
inputs:
|
71
|
+
DBPassword: <%= random_hash %>
|
72
|
+
environments:
|
73
|
+
dev:
|
74
|
+
production:
|
75
|
+
YAML
|
76
|
+
first_time = @loader.load(generate_input(yaml))[:resources]['inputs']['DBPassword']
|
77
|
+
second_time = @loader.load(generate_input(yaml))[:resources]['inputs']['DBPassword']
|
78
|
+
assert first_time && second_time
|
79
|
+
assert first_time != second_time
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_environment_specific_setting_will_override_common_settings
|
83
|
+
yaml = <<-YAML
|
84
|
+
application: myapp
|
85
|
+
common:
|
86
|
+
phoenix_mode: true
|
87
|
+
environments:
|
88
|
+
dev:
|
89
|
+
phoenix_mode: false
|
90
|
+
production:
|
91
|
+
YAML
|
92
|
+
|
93
|
+
assert !@loader.load(generate_input(yaml, :environment => 'dev'))[:phoenix_mode]
|
94
|
+
assert @loader.load(generate_input(yaml, :environment => 'production'))[:phoenix_mode]
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_env_specific_option_settings_will_merge_with_commons
|
98
|
+
config = @loader.load(generate_input(<<-YAML, :environment => 'production'))
|
99
|
+
application: myapp
|
100
|
+
common:
|
101
|
+
strategy: inplace-update
|
102
|
+
phoenix_mode: true
|
103
|
+
option_settings:
|
104
|
+
- namespace: aws:autoscaling:launchconfiguration
|
105
|
+
option_name: InstanceType
|
106
|
+
value: m1.small
|
107
|
+
resources:
|
108
|
+
environments:
|
109
|
+
dev:
|
110
|
+
production:
|
111
|
+
option_settings:
|
112
|
+
- namespace: aws:autoscaling:asg
|
113
|
+
option_name: MinSize
|
114
|
+
value: "2"
|
115
|
+
YAML
|
116
|
+
assert_equal([{'namespace' => 'aws:autoscaling:launchconfiguration',
|
117
|
+
'option_name' => 'InstanceType',
|
118
|
+
'value' => 'm1.small'},
|
119
|
+
{'namespace' => 'aws:autoscaling:asg',
|
120
|
+
'option_name' => 'MinSize',
|
121
|
+
'value' => "2"}], config[:option_settings])
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_env_is_required
|
125
|
+
error = assert_raises(RuntimeError) {
|
126
|
+
@loader.load(generate_input(<<-YAML, :environment => 'non_existant'))
|
127
|
+
application: myapp
|
128
|
+
common:
|
129
|
+
strategy: inplace-update
|
130
|
+
environments:
|
131
|
+
dev:
|
132
|
+
YAML
|
133
|
+
}
|
134
|
+
|
135
|
+
assert_match(/non_existant/, error.message)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_set_inactive_settings_at_common_level
|
139
|
+
config = @loader.load(generate_input(<<-YAML, :environment => 'production'))
|
140
|
+
application: myapp
|
141
|
+
common:
|
142
|
+
inactive_settings:
|
143
|
+
- namespace: aws:autoscaling:asg
|
144
|
+
option_name: MinSize
|
145
|
+
value: "1"
|
146
|
+
environments:
|
147
|
+
dev:
|
148
|
+
production:
|
149
|
+
YAML
|
150
|
+
assert_equal([{'namespace' => 'aws:autoscaling:asg',
|
151
|
+
'option_name' => 'MinSize',
|
152
|
+
'value' => '1'}], config[:inactive_settings])
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_set_inactive_settings_at_env_level
|
156
|
+
config = @loader.load(generate_input(<<-YAML, :environment => 'dev'))
|
157
|
+
application: myapp
|
158
|
+
common:
|
159
|
+
inactive_settings:
|
160
|
+
- namespace: aws:autoscaling:asg
|
161
|
+
option_name: MinSize
|
162
|
+
value: "1"
|
163
|
+
environments:
|
164
|
+
dev:
|
165
|
+
inactive_settings:
|
166
|
+
- namespace: aws:autoscaling:asg
|
167
|
+
option_name: MinSize
|
168
|
+
value: "0"
|
169
|
+
production:
|
170
|
+
YAML
|
171
|
+
assert_equal([{'namespace' => 'aws:autoscaling:asg',
|
172
|
+
'option_name' => 'MinSize',
|
173
|
+
'value' => '0'}], config[:inactive_settings])
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_access_environment_name_in_config_yml_file
|
177
|
+
config = @loader.load(generate_input(<<-YAML, :environment => 'dev'))
|
178
|
+
application: myapp
|
179
|
+
common:
|
180
|
+
resources:
|
181
|
+
inputs:
|
182
|
+
env: <%= environment %>
|
183
|
+
environments:
|
184
|
+
dev:
|
185
|
+
production:
|
186
|
+
YAML
|
187
|
+
assert_equal('dev', config[:resources]['inputs']['env'])
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def md5_digest(file)
|
193
|
+
Digest::MD5.file(file).hexdigest
|
194
|
+
end
|
195
|
+
|
196
|
+
def generate_input(config_file_content, overriding={})
|
197
|
+
{ :environment => 'dev',
|
198
|
+
:package => @sample_package,
|
199
|
+
:config_file => generate_config(config_file_content)}.merge(overriding)
|
200
|
+
end
|
201
|
+
|
202
|
+
def generate_config(content)
|
203
|
+
sample_file('eb_deployer.yml', content)
|
204
|
+
end
|
205
|
+
end
|
data/test/deploy_test.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DeployTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@eb = ErrorRaisingWrapper.new(EBStub.new)
|
6
|
+
@s3_driver = S3Stub.new
|
7
|
+
@cf_driver = CFStub.new
|
8
|
+
@sample_package = sample_file('app-package.war')
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def temp_file(content)
|
14
|
+
f = Tempfile.new("foo")
|
15
|
+
f.write(content)
|
16
|
+
f
|
17
|
+
end
|
18
|
+
|
19
|
+
def query_resource_output(key, opts)
|
20
|
+
EbDeployer.query_resource_output(key, {:bs_driver => @eb,
|
21
|
+
:s3_driver => @s3_driver,
|
22
|
+
:cf_driver => @cf_driver}.merge(opts))
|
23
|
+
end
|
24
|
+
|
25
|
+
def deploy(opts)
|
26
|
+
@eb.mark_all_envs_ready
|
27
|
+
EbDeployer.deploy({:package => @sample_package,
|
28
|
+
:strategy => :'inplace-update',
|
29
|
+
:version_label => 1}.merge(opts).merge(stubs))
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy(opts)
|
33
|
+
EbDeployer.destroy(opts.merge(stubs))
|
34
|
+
end
|
35
|
+
|
36
|
+
def stubs
|
37
|
+
{ :bs_driver => @eb,
|
38
|
+
:s3_driver => @s3_driver,
|
39
|
+
:cf_driver => @cf_driver
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EbEnvironmentTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@eb_driver = EBStub.new
|
6
|
+
@eb_driver.create_application("myapp")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_deploy_should_create_corresponding_eb_env
|
10
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
11
|
+
env.deploy("version1")
|
12
|
+
assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_deploy_again_should_update_environment
|
16
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
17
|
+
env.deploy("version1")
|
18
|
+
env.deploy("version2")
|
19
|
+
assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
|
20
|
+
assert_equal 'version2', @eb_driver.environment_verion_label('myapp', t('production', 'myapp'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_option_setttings_get_set_on_eb_env
|
24
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
25
|
+
env.deploy("version1", {s1: 'v1'})
|
26
|
+
assert_equal({s1: 'v1' }, @eb_driver.environment_settings('myapp', t('production', 'myapp')))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_deploy_should_include_tags
|
30
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production', :tags => {:my_tag => 'my_value', :tag2 => 'value2'})
|
31
|
+
env.deploy("version1")
|
32
|
+
assert_equal [{:key => :my_tag, :value => 'my_value'}, {:key => :tag2, :value => 'value2'}], @eb_driver.environment_tags('myapp', t('production', 'myapp'))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_run_smoke_test_after_deploy
|
36
|
+
smoked_host = nil
|
37
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :smoke_test => Proc.new { |host| smoked_host = host }, :cname_prefix => 'myapp-production')
|
38
|
+
env.deploy("version1")
|
39
|
+
|
40
|
+
assert !smoked_host.nil?
|
41
|
+
assert_match( /myapp.*\.elasticbeanstalk\.com/, smoked_host)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_raise_runtime_error_when_deploy_failed
|
45
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
46
|
+
@eb_driver.set_events("myapp", t("production", 'myapp'),
|
47
|
+
[],
|
48
|
+
["start deploying", "Failed to deploy application"])
|
49
|
+
assert_raises(RuntimeError) { env.deploy("version 1") }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_raise_runtime_error_when_eb_extension_execution_failed
|
53
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
54
|
+
@eb_driver.set_events("myapp", t("production", 'myapp'),
|
55
|
+
[],
|
56
|
+
["start deploying",
|
57
|
+
"create environment",
|
58
|
+
"Command failed on instance. Return code: 1 Output: Error occurred during build: Command hooks failed",
|
59
|
+
"Successfully launched environment"])
|
60
|
+
|
61
|
+
assert_raises(RuntimeError) { env.deploy("version 1") }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_raise_runtime_error_when_issues_during_environment_update
|
65
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
66
|
+
@eb_driver.set_events("myapp", t("production", 'myapp'),
|
67
|
+
[],
|
68
|
+
["start deploying",
|
69
|
+
"create environment",
|
70
|
+
"Update environment operation is complete, but with errors. For more information, see troubleshooting documentation."])
|
71
|
+
|
72
|
+
assert_raises(RuntimeError) { env.deploy("version 1") }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_raise_runtime_error_when_issues_during_launch
|
76
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
77
|
+
@eb_driver.set_events("myapp", t("production", 'myapp'),
|
78
|
+
[],
|
79
|
+
["start deploying",
|
80
|
+
"create environment",
|
81
|
+
"Launched environment: dev-a-1234567. However, there were issues during launch. See event log for details."])
|
82
|
+
|
83
|
+
assert_raises(RuntimeError) { env.deploy("version 1") }
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_terminate_should_delete_environment
|
87
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :cname_prefix => 'myapp-production')
|
88
|
+
env.deploy("version1")
|
89
|
+
env.terminate
|
90
|
+
assert !@eb_driver.environment_exists?('myapp', t('production', 'myapp'))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_raise_runtime_error_when_solution_stack_is_not_valid
|
94
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, {
|
95
|
+
:cname_prefix => 'myapp-production',
|
96
|
+
:solution_stack => "python"
|
97
|
+
})
|
98
|
+
@eb_driver.set_solution_stacks(["java", "ruby"])
|
99
|
+
assert_raises(RuntimeError) { env.deploy("version 1") }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_should_no_set_cname_prefix_for_create_unless_for_web_tier
|
103
|
+
env = EbDeployer::EbEnvironment.new("myapp",
|
104
|
+
"production",
|
105
|
+
@eb_driver,
|
106
|
+
:tier => "Worker",
|
107
|
+
:cname_prefix => 'myapp-production')
|
108
|
+
env.deploy("version1")
|
109
|
+
assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
|
110
|
+
assert_nil @eb_driver.environment_cname_prefix('myapp', t('production', 'myapp'))
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_should_be_possible_to_accept_yellow_health_state
|
114
|
+
env = EbDeployer::EbEnvironment.new("myapp", "production", @eb_driver, :accepted_healthy_states => ["Green", "Yellow"])
|
115
|
+
@eb_driver.mark_env_health_state_as("myapp", env.name, "Yellow")
|
116
|
+
env.deploy("version1")
|
117
|
+
assert @eb_driver.environment_exists?('myapp', t('production', 'myapp'))
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EbEventPollerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@eb = EBStub.new
|
6
|
+
@poller = EbDeployer::EventPoller.new(EbDeployer::EbEventSource.new("myapp", "test", @eb))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_run_handle_block_through_all_events_when_there_is_no_from_anchor
|
10
|
+
messages_handled = []
|
11
|
+
@eb.set_events('myapp', 'test', ['a', 'b', nil])
|
12
|
+
@poller.poll(nil) do |event|
|
13
|
+
break if event[:message].nil?
|
14
|
+
messages_handled << event[:message]
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal ['a', 'b'], messages_handled
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def test_can_poll_all_events_after_an_anchor
|
22
|
+
@eb.set_events('myapp', 'test', ['a', 'b'], ['c', 'd', nil])
|
23
|
+
anchor = @poller.get_anchor
|
24
|
+
messages_handled = []
|
25
|
+
@poller.poll(anchor) do |event|
|
26
|
+
break if event[:message].nil?
|
27
|
+
messages_handled << event[:message]
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_equal ['c', 'd'], messages_handled
|
31
|
+
end
|
32
|
+
end
|