eb_deployer 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/eb_deployer.rb CHANGED
@@ -2,6 +2,7 @@ require "eb_deployer/version"
2
2
  require "eb_deployer/deployment_strategy"
3
3
  require "eb_deployer/beanstalk"
4
4
  require "eb_deployer/cloud_formation_provisioner"
5
+ require 'eb_deployer/application'
5
6
  require "eb_deployer/environment"
6
7
  require "eb_deployer/event_poller"
7
8
  require "eb_deployer/package"
@@ -46,8 +47,10 @@ module EbDeployer
46
47
  cname_prefix = opts[:cname_prefix] || [app, env_name].join('-')
47
48
  smoke_test = opts[:smoke_test] || Proc.new {}
48
49
 
49
- package = Package.new(opts[:package], app + "-packages", s3)
50
+ application = Application.new(app, bs, s3)
51
+
50
52
  cf = CloudFormationProvisioner.new("#{app}-#{env_name}", cf)
53
+
51
54
  strategy = DeploymentStrategy.create(strategy_name, app, env_name, bs,
52
55
  :solution_stack => stack_name,
53
56
  :cname_prefix => cname_prefix,
@@ -57,12 +60,7 @@ module EbDeployer
57
60
  env_settings += cf.provision(resources)
58
61
  end
59
62
 
60
- package.upload
61
-
62
- unless bs.application_version_labels.include?(version_label)
63
- bs.create_application_version(app, version_label, package.source_bundle)
64
- end
65
-
63
+ application.create_version(version_label, opts[:package])
66
64
  strategy.deploy(version_label, env_settings)
67
65
  end
68
66
 
@@ -0,0 +1,28 @@
1
+ module EbDeployer
2
+ class Application
3
+ def initialize(name, eb_driver, s3_driver)
4
+ @name = name
5
+ @eb_driver = eb_driver
6
+ @s3_driver = s3_driver
7
+ end
8
+
9
+ def create_version(version_label, package)
10
+ create_application_if_not_exists
11
+
12
+ package = Package.new(package, @name + "-packages", @s3_driver)
13
+ package.upload
14
+
15
+ unless @eb_driver.application_version_labels.include?(version_label)
16
+ @eb_driver.create_application_version(@name, version_label, package.source_bundle)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def create_application_if_not_exists
23
+ unless @eb_driver.application_exists?(@name)
24
+ @eb_driver.create_application(@name)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -12,11 +12,12 @@ module EbDeployer
12
12
  end
13
13
 
14
14
  def provision(resources)
15
- params = extract_params
16
15
  template = File.read(resources[:template])
17
16
  transforms = resources[:transforms]
17
+ capabilities = resources[:capabilities]
18
+ params = resources[:parameters]
18
19
 
19
- stack_exists? ? update_stack(template, params) : create_stack(template, params)
20
+ stack_exists? ? update_stack(template, params, capabilities) : create_stack(template, params, capabilities)
20
21
  wait_for_stack_op_terminate
21
22
  transform_output_to_settings(transforms)
22
23
  end
@@ -29,8 +30,9 @@ module EbDeployer
29
30
 
30
31
  private
31
32
 
32
- def update_stack(template, params)
33
+ def update_stack(template, params, capabilities)
33
34
  @cf_driver.update_stack(@stack_name, template,
35
+ :capabilities => capabilities,
34
36
  :parameters => params)
35
37
  end
36
38
 
@@ -38,9 +40,10 @@ module EbDeployer
38
40
  @cf_driver.stack_exists?(@stack_name)
39
41
  end
40
42
 
41
- def create_stack(template, params)
43
+ def create_stack(template, params, capabilities)
42
44
  @cf_driver.create_stack(@stack_name, template,
43
45
  :disable_rollback => true,
46
+ :capabilities => capabilities,
44
47
  :parameters => params)
45
48
  end
46
49
 
@@ -66,11 +69,6 @@ module EbDeployer
66
69
  end
67
70
  end
68
71
 
69
-
70
- def extract_params
71
- Hash[ENV.map {|k, v| k =~ /^AWSRESOURCES_(.*)/ ? [$1, v] : nil }.compact]
72
- end
73
-
74
72
  def log(msg)
75
73
  puts "[#{Time.now.utc}][resources-stack] #{msg}"
76
74
  end
@@ -1,3 +1,3 @@
1
1
  module EbDeployer
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,9 +1,19 @@
1
1
  class EBStub
2
2
  def initialize
3
+ @apps = []
3
4
  @envs = {}
4
5
  @versions = {}
5
6
  end
6
7
 
8
+ def create_application(app)
9
+ raise 'already exists' if application_exists?(app)
10
+ @apps << app
11
+ end
12
+
13
+ def application_exists?(app)
14
+ @apps.include?(app)
15
+ end
16
+
7
17
  def create_environment(app, env, solution_stack, cname_prefix, version, settings)
8
18
  raise 'cname prefix is not avaible' if @envs.values.detect { |env| env[:cname_prefix] == cname_prefix }
9
19
  raise "env name #{env} is longer than 23 chars" if env.size > 23
@@ -107,7 +117,7 @@ class CFStub
107
117
  end
108
118
 
109
119
  def update_stack(name, template, opts)
110
- @stacks[name] = @stacks[name].merge(:template => template, opts => opts)
120
+ @stacks[name] = @stacks[name].merge(:template => template, :opts => opts)
111
121
  end
112
122
 
113
123
  def stack_status(name)
@@ -122,4 +132,8 @@ class CFStub
122
132
  raise AWS::CloudFormation::Errors::ValidationError.new unless stack_exists?(name)
123
133
  "value of #{key}"
124
134
  end
135
+
136
+ def stack_config(name)
137
+ @stacks[name][:opts]
138
+ end
125
139
  end
data/test/deploy_test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ $:.unshift(File.expand_path("../../lib", __FILE__))
1
2
  require 'tempfile'
2
3
  require 'eb_deployer'
3
4
  require 'aws_driver_stubs'
@@ -12,6 +13,12 @@ class DeployTest < Minitest::Test
12
13
  File.open(@sample_package, 'w') { |f| f << 's' * 100 }
13
14
  end
14
15
 
16
+ def test_first_deplyment_create_eb_application
17
+ assert !@eb_driver.application_exists?('simple')
18
+ deploy(:application => 'simple', :environment => "production")
19
+ assert @eb_driver.application_exists?('simple')
20
+ end
21
+
15
22
  def test_first_deployment_create_environment
16
23
  assert !@eb_driver.environment_exists?('simple', eb_envname('simple', 'production'))
17
24
  deploy(:application => 'simple', :environment => "production")
@@ -155,15 +162,27 @@ class DeployTest < Minitest::Test
155
162
  assert @cf_driver.stack_exists?('simple-production')
156
163
  end
157
164
 
158
- def test_transforms_resource_provsion_output_to_elastic_beanstalk_settings
165
+ def test_provision_resources_with_capacities
159
166
  cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
160
167
  deploy(:application => 'simple', :environment => "production",
161
168
  :resources => {
162
- :template => cf_template
169
+ :template => cf_template,
170
+ :capabilities => ['CAPABILITY_IAM']
163
171
  })
164
- assert @cf_driver.stack_exists?('simple-production')
172
+ assert_equal ['CAPABILITY_IAM'], @cf_driver.stack_config('simple-production')[:capabilities]
165
173
  end
166
174
 
175
+ def test_provision_resources_with_parameters
176
+ cf_template = temp_file(JSON.dump({'Resources' => {'R1' => {}}}))
177
+ deploy(:application => 'simple', :environment => "production",
178
+ :resources => {
179
+ :template => cf_template,
180
+ :parameters => {'a' => 1}
181
+ })
182
+ assert_equal({'a' => 1 }, @cf_driver.stack_config('simple-production')[:parameters])
183
+ end
184
+
185
+
167
186
  def test_transforms_resource_provsion_output_to_elastic_beanstalk_settings
168
187
  cf_template = temp_file(JSON.dump({
169
188
  'Resources' => {'R1' => {}},
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.8
4
+ version: 0.0.9
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-06-17 00:00:00.000000000 Z
13
+ date: 2013-07-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -59,6 +59,7 @@ files:
59
59
  - Rakefile
60
60
  - eb_deployer.gemspec
61
61
  - lib/eb_deployer.rb
62
+ - lib/eb_deployer/application.rb
62
63
  - lib/eb_deployer/beanstalk.rb
63
64
  - lib/eb_deployer/cloud_formation_driver.rb
64
65
  - lib/eb_deployer/cloud_formation_provisioner.rb