dpl 1.6.6.travis.500.1 → 1.6.6.travis.507.1

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODE2ZDFjNTMwOGZjODFiNzAyZTU3NDNiODU4MTRlZmQ0ZjZhNWM2Yw==
4
+ NDNhZmZlMWU4NzBiOTJiODg4YjM0NGVhY2M3NjQ3OGU1YjhlZTVhZQ==
5
5
  data.tar.gz: !binary |-
6
- Mjk2OTI4YjQzM2E5NDI2ZTA5ZWZkYWYwM2I4ZDYzOGNiODhlMzQ3Mg==
6
+ MTc4NGMzNWNlNDZlYzUwMjdkMTUzZDAxYjM3YmU2MmE1ZWUzMDRjMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODkxZTU4YjU4NGM3NjQxZmZiYTU4MGM3MWRhNDdjN2Y0MDllMzljOGY1NWU2
10
- ZWM3YWI2MGZhNzYyMzU2NTVjNTNlNzNmMDJlNTU5ODk4ZTQxNGZkYTIyZGE4
11
- MGE2Y2ViNmE3Y2VkMzFkZmM1MWRkNTgyOWNiYWY1YmI2ZDlhNTA=
9
+ ODhjYTZkOWM5M2VlODBhZTRmYzE5MmJiNTMwOWY3ZGRmOWM1NWNiNjA0ZjA5
10
+ NTMxYTgyMTk0MWEwNzMzODRlY2QyODAwZTcwZGM1NjFlMGJkZWYxZmFhOWQ5
11
+ NzA4ZjJlNjhjNTEyZWJlMDNmOGVhYmEzNTAyZmU1NzAyNjZkNTM=
12
12
  data.tar.gz: !binary |-
13
- YzkwMmJkMmVjMGRkZjg1N2I3MmMzYTkxYmQ1ZTFiNzIwZjJlNzUwZjZiMjA4
14
- OWVjZjc5MjE0OTgwYmQyODVmZjlhZGU2MTE1YThjNTUzZTlkMWU0ZWE0ZDU1
15
- M2Q1NzAxZWY5OWQzNzcwYzY5ZDA4YWNlZGQxMGFhZjVmNjVmYTg=
13
+ ODUzOTVlYzU0NWU4ZTY5Y2ExZmQ3MzIyODc0M2MwN2Y1NTNmYWQ1N2MwNTVm
14
+ ZjFhZGNjNGNjMmIyMzE2N2NiNTNiYmE4MThiZTZmMzNiYmI0YmRjZDhkZjZk
15
+ MGM2NDljZjI3NDJlNjUzYWFjYWIwMDRlNzE5YTk4NzkxMDYxZDA=
data/Gemfile CHANGED
@@ -45,3 +45,8 @@ end
45
45
  group :gae do
46
46
  gem 'rubyzip'
47
47
  end
48
+
49
+ group :elastic_beanstalk do
50
+ gem 'rubyzip'
51
+ gem 'aws-sdk'
52
+ end
data/README.md CHANGED
@@ -26,6 +26,7 @@ Dpl supports the following providers:
26
26
  * [Hackage](#hackage)
27
27
  * [Deis](#deis)
28
28
  * [Google Cloud Storage](#google-cloud-storage)
29
+ * [Elastic Beanstalk](#elastic-beanstalk)
29
30
 
30
31
  ## Installation:
31
32
 
@@ -358,3 +359,17 @@ For accounts using two factor authentication, you have to use an oauth token as
358
359
  dpl --provider=gcs --access-key-id=<access-key-id> --secret-access-key=<secret-access-key> --bucket=<bucket> --acl=public-read
359
360
  dpl --provider=gcs --access-key-id=<access-key-id> --secret-access-key=<secret-access-key> --bucket=<bucket> --detect-encoding --cache_control=max-age=99999
360
361
  dpl --provider=gcs --access-key-id=<access-key-id> --secret-access-key=<secret-access-key> --bucket=<bucket> --local-dir=BUILD --upload-dir=BUILDS
362
+
363
+ ### Elastic Beanstalk:
364
+
365
+ #### Options:
366
+
367
+ * **access-key-id**: AWS Access Key ID. Can be obtained from [here](https://console.aws.amazon.com/iam/home?#security_credential).
368
+ * **secret-access-key**: AWS Secret Key. Can be obtained from [here](https://console.aws.amazon.com/iam/home?#security_credential).
369
+ * **region**: AWS Region the Elastic Beanstalk app is running in. Defaults to 'us-east-1'. Please be aware that this must match the region of the elastic beanstalk app.
370
+ * **app**: Elastic Beanstalk application name.
371
+ * **env**: Elastic Beanstalk environment name which will be updated.
372
+
373
+ #### Examples:
374
+
375
+ dpl --provider=elasticbeanstalk --access-key-id=<access-key-id> --secret-access-key="<secret-access-key>" --app="example-app-name" --env="example-app-environment" --region="us-west-2"
data/lib/dpl/provider.rb CHANGED
@@ -28,6 +28,7 @@ module DPL
28
28
  autoload :Deis, 'dpl/provider/deis'
29
29
  autoload :GCS, 'dpl/provider/gcs'
30
30
  autoload :GAE, 'dpl/provider/gae'
31
+ autoload :ElasticBeanstalk, 'dpl/provider/elastic_beanstalk'
31
32
 
32
33
  def self.new(context, options)
33
34
  return super if self < Provider
@@ -124,6 +125,10 @@ module DPL
124
125
  @sha ||= ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
125
126
  end
126
127
 
128
+ def commit_msg
129
+ @commit_msg ||= %x{git log #{sha} -n 1 --pretty=%B}.strip
130
+ end
131
+
127
132
  def cleanup
128
133
  return if options[:skip_cleanup]
129
134
  context.shell "mv .dpl ~/dpl"
@@ -0,0 +1,115 @@
1
+ require 'aws-sdk'
2
+ require 'zip'
3
+
4
+ module DPL
5
+ class Provider
6
+ class ElasticBeanstalk < Provider
7
+ experimental 'AWS Elastic Beanstalk'
8
+
9
+ DEFAULT_REGION = 'us-east-1'
10
+
11
+ def needs_key?
12
+ false
13
+ end
14
+
15
+ def check_auth
16
+ AWS.config(access_key_id: option(:access_key_id), secret_access_key: option(:secret_access_key), region: region)
17
+ end
18
+
19
+ def check_app
20
+ end
21
+
22
+ def push_app
23
+ create_bucket unless bucket_exists?
24
+ zip_file = create_zip
25
+ s3_object = upload(archive_name, zip_file)
26
+ sleep 5 #s3 eventual consistency
27
+ version = create_app_version(s3_object)
28
+ update_app(version)
29
+ end
30
+
31
+ private
32
+
33
+ def app_name
34
+ option(:app)
35
+ end
36
+
37
+ def env_name
38
+ option(:env)
39
+ end
40
+
41
+ def version_label
42
+ "travis-#{sha}-#{Time.now.to_i}"
43
+ end
44
+
45
+ def archive_name
46
+ "#{version_label}.zip"
47
+ end
48
+
49
+ def region
50
+ option(:region) || DEFAULT_REGION
51
+ end
52
+
53
+ def bucket_name
54
+ "travis-elasticbeanstalk-builds-#{region}"
55
+ end
56
+
57
+ def s3
58
+ @s3 ||= AWS::S3.new
59
+ end
60
+
61
+ def eb
62
+ @eb ||= AWS::ElasticBeanstalk.new.client
63
+ end
64
+
65
+ def bucket_exists?
66
+ s3.buckets.map(&:name).include? bucket_name
67
+ end
68
+
69
+ def create_bucket
70
+ s3.buckets.create(bucket_name)
71
+ end
72
+
73
+ def create_zip
74
+ directory = Dir.pwd
75
+ zipfile_name = File.join(directory, archive_name)
76
+
77
+ Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
78
+ Dir[File.join(directory, '**', '**')].each do |file|
79
+ relative_archive_path = File.join(directory, '/')
80
+ zipfile.add(file.sub(relative_archive_path, ''), file)
81
+ end
82
+ end
83
+ zipfile_name
84
+ end
85
+
86
+ def upload(key, file)
87
+ obj = s3.buckets[bucket_name].objects[key]
88
+ obj.write(Pathname.new(file))
89
+ obj
90
+ end
91
+
92
+ def create_app_version(s3_object)
93
+ options = {
94
+ :application_name => app_name,
95
+ :version_label => version_label,
96
+ :description => commit_msg,
97
+ :source_bundle => {
98
+ :s3_bucket => bucket_name,
99
+ :s3_key => s3_object.key
100
+ },
101
+ :auto_create_application => false
102
+ }
103
+ eb.create_application_version(options)
104
+ end
105
+
106
+ def update_app(version)
107
+ options = {
108
+ :environment_name => env_name,
109
+ :version_label => version[:application_version][:version_label]
110
+ }
111
+ eb.update_environment(options)
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'aws-sdk'
3
+ require 'dpl/provider'
4
+ require 'dpl/provider/elastic_beanstalk'
5
+
6
+ describe DPL::Provider::ElasticBeanstalk do
7
+
8
+ before (:each) do
9
+ AWS.stub!
10
+ end
11
+
12
+ let(:access_key_id) { 'qwertyuiopasdfghjklz' }
13
+ let(:secret_access_key) { 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz' }
14
+ let(:region) { 'us-west-2' }
15
+ let(:app) { 'example-app' }
16
+ let(:env) { 'live' }
17
+
18
+ subject :provider do
19
+ described_class.new(DummyContext.new, :access_key_id => access_key_id, :secret_access_key => secret_access_key, :region => region, :app => app, :env => env)
20
+ end
21
+
22
+ describe "#check_auth" do
23
+ example do
24
+ expect(AWS).to receive(:config).with(access_key_id: access_key_id, secret_access_key: secret_access_key, region: region)
25
+ provider.check_auth
26
+ end
27
+ end
28
+
29
+ describe "#push_app" do
30
+
31
+ let(:bucket_name) { "travis-elasticbeanstalk-builds-#{region}" }
32
+ let(:s3_object) { Object.new }
33
+ let(:app_version) { Object.new }
34
+
35
+ let(:bucket) { Struct.new(:name) }
36
+ let(:s3) { Struct.new(:buckets) }
37
+
38
+ example 'bucket exists already' do
39
+ s3_mock = s3.new([bucket.new(bucket_name)])
40
+ expect(provider).to receive(:s3).and_return(s3_mock)
41
+ expect(provider).not_to receive(:create_bucket)
42
+ expect(provider).to receive(:create_zip).and_return('/path/to/file.zip')
43
+ expect(provider).to receive(:archive_name).and_return('file.zip')
44
+ expect(provider).to receive(:upload).with('file.zip', '/path/to/file.zip').and_return(s3_object)
45
+ expect(provider).to receive(:sleep).with(5)
46
+ expect(provider).to receive(:create_app_version).with(s3_object).and_return(app_version)
47
+ expect(provider).to receive(:update_app).with(app_version)
48
+
49
+ provider.push_app
50
+ end
51
+
52
+ example 'bucket doesnt exist yet' do
53
+ s3_mock = s3.new([])
54
+ expect(provider).to receive(:s3).and_return(s3_mock)
55
+ expect(provider).to receive(:create_bucket)
56
+ expect(provider).to receive(:create_zip).and_return('/path/to/file.zip')
57
+ expect(provider).to receive(:archive_name).and_return('file.zip')
58
+ expect(provider).to receive(:upload).with('file.zip', '/path/to/file.zip').and_return(s3_object)
59
+ expect(provider).to receive(:sleep).with(5)
60
+ expect(provider).to receive(:create_app_version).with(s3_object).and_return(app_version)
61
+ expect(provider).to receive(:update_app).with(app_version)
62
+
63
+ provider.push_app
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6.travis.500.1
4
+ version: 1.6.6.travis.507.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -107,6 +107,7 @@ files:
107
107
  - lib/dpl/provider/deis.rb
108
108
  - lib/dpl/provider/divshot.rb
109
109
  - lib/dpl/provider/dot_cloud.rb
110
+ - lib/dpl/provider/elastic_beanstalk.rb
110
111
  - lib/dpl/provider/engine_yard.rb
111
112
  - lib/dpl/provider/gae.rb
112
113
  - lib/dpl/provider/gcs.rb
@@ -138,6 +139,7 @@ files:
138
139
  - spec/provider/deis_spec.rb
139
140
  - spec/provider/divshot_spec.rb
140
141
  - spec/provider/dotcloud_spec.rb
142
+ - spec/provider/elastic_beanstalk_spec.rb
141
143
  - spec/provider/gae_spec.rb
142
144
  - spec/provider/gcs_spec.rb
143
145
  - spec/provider/hackage_spec.rb