Skip to content

Commit

Permalink
Merge 1fedb47 into 08f8845
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Aug 21, 2019
2 parents 08f8845 + 1fedb47 commit 43e3f67
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 327 deletions.
3 changes: 2 additions & 1 deletion lib/dpl/providers/codedeploy.rb
Expand Up @@ -11,7 +11,8 @@ class Codedeploy < Provider
tbd
str

gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-codedeploy', '~> 1.0'
gem 'aws-sdk-s3', '~> 1.0'

env :aws
config '~/.aws/credentials', '~/.aws/config', prefix: 'aws'
Expand Down
7 changes: 4 additions & 3 deletions lib/dpl/providers/elasticbeanstalk.rb
Expand Up @@ -9,7 +9,8 @@ class Elasticbeanstalk < Provider
tbd
str

gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-elasticbeanstalk', '~> 1.0'
gem 'aws-sdk-s3', '~> 1.0'
gem 'rubyzip', '~> 1.2.2', require: 'zip'
gem 'pathspec', '~> 0.2.1', require: 'pathspec'

Expand Down Expand Up @@ -126,8 +127,8 @@ def wait_until_deployed
def check_deployment(msgs)
sleep 5
events.each do |event|
msg = "#{event[:event_date]} [#{event[:severity]}] #{event[:message]}"
error "Deployment failed: #{msg}" if event[:severity] == 'ERROR'
msg = "#{event.event_date} [#{event.severity}] #{event.message}"
error "Deployment failed: #{msg}" if event.severity == 'ERROR'
info msg unless msgs.include?(msg)
msgs << msg
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dpl/providers/lambda.rb
Expand Up @@ -11,7 +11,7 @@ class Lambda < Provider
tbd
str

gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-lambda', '~> 1.0'
gem 'rubyzip', '~> 1.2.2', require: 'zip'

env :aws
Expand Down
2 changes: 1 addition & 1 deletion lib/dpl/providers/opsworks.rb
Expand Up @@ -9,7 +9,7 @@ class Opsworks < Provider
tbd
str

gem 'aws-sdk', '~> 2.0'
gem 'aws-sdk-opsworks', '~> 1.0'

env :aws
config '~/.aws/credentials', '~/.aws/config', prefix: 'aws'
Expand Down
4 changes: 2 additions & 2 deletions lib/dpl/providers/s3.rb
Expand Up @@ -14,7 +14,7 @@ class S3 < Provider
tbd
str

gem 'aws-sdk', '~> 2.0', require: ['aws-sdk', 'dpl/support/aws_sdk_patch']
gem 'aws-sdk-s3', '~> 1.0'
gem 'mime-types', '~> 3.2.2'

env :aws
Expand Down Expand Up @@ -57,7 +57,7 @@ class S3 < Provider
def setup
@cwd = Dir.pwd
Dir.chdir(local_dir)
Aws.eager_autoload!(services: ['S3'])
# Aws.eager_autoload!(services: ['S3'])
end

def login
Expand Down
48 changes: 18 additions & 30 deletions spec/dpl/providers/codedeploy_spec.rb
@@ -1,43 +1,31 @@
describe Dpl::Providers::Codedeploy do
let(:args) { |e| %w(--access_key_id access_key_id --secret_access_key secret_access_key --application app) + args_from_description(e) }
let(:requests) { Hash.new { |hash, key| hash[key] = [] } }
include Support::Matchers::Aws

env TRAVIS_BUILD_NUMBER: 1
let(:args) { |e| %w(--access_key_id access_key_id --secret_access_key secret_access_key --application app) + args_from_description(e) }
let(:client) { Aws::CodeDeploy::Client.new(stub_responses: responses[:eb]) }
let(:s3) { Aws::S3::Client.new(stub_responses: true) }

before do
Aws.config[:s3] = {
stub_responses: {
get_object: ->(ctx) {
requests[:buckets] << ctx.http_request
{ deployment_id: 'deployment_id' }
}
}
}
Aws.config[:codedeploy] = {
stub_responses: {
create_deployment: ->(ctx) {
requests[:create_deployment] << ctx.http_request
{ deployment_id: 'deployment_id' }
let(:responses) do
{
eb: {
create_deployment: {
deployment_id: 'deployment_id'
},
get_deployment: ->(ctx) {
requests[:get_deployment] << ctx.http_request
{ deployment_info: { status: 'Succeeded' } }
get_deployment: {
deployment_info: { status: 'Succeeded' }
}
}
}
end

matcher :create_deployment do |params = {}|
match do |*|
next false unless request = requests[:create_deployment][0]
body = symbolize(JSON.parse(request.body.read))
params.all? { |key, value| body[key] == value }
end
end
let(:github_revision) { { revisionType: 'GitHub', gitHubLocation: { repository: 'dpl', commitId: 'sha' } } }
let(:s3_revision) { { revisionType: 'S3', s3Location: { bucket: 'bucket', bundleType: 'zip', version: 'ObjectVersionId', eTag: 'ETag' } } }

matcher :get_deployment do |*|
match { |*| requests[:get_deployment].any? }
end
env TRAVIS_BUILD_NUMBER: 1

before { allow(Aws::CodeDeploy::Client).to receive(:new).and_return(client) }
before { allow(Aws::S3::Client).to receive(:new).and_return(s3) }
before { |c| subject.run unless c.example_group.metadata[:run].is_a?(FalseClass) }

let(:github_revision) { { revisionType: 'GitHub', gitHubLocation: { repository: 'dpl', commitId: 'sha' } } }
let(:s3_revision) { { revisionType: 'S3', s3Location: { bucket: 'bucket', bundleType: 'zip', version: 'ObjectVersionId', eTag: 'ETag' } } }
Expand Down
90 changes: 36 additions & 54 deletions spec/dpl/providers/elasticbeanstalk_spec.rb
@@ -1,74 +1,56 @@
describe Dpl::Providers::Elasticbeanstalk do
include Support::Matchers::Aws

let(:args) { |e| required + args_from_description(e) }
let(:required) { %w(--access_key_id id --secret_access_key key --env env --bucket bucket) }
let(:requests) { Hash.new { |hash, key| hash[key] = [] } }
let(:events) { [] }

matcher :create_app_version do |opts = {}|
match do |*|
next false unless requests[:create_application_version].any?
next true unless opts[:with]
body = requests[:create_application_version][0].body.read
opts[:with].is_a?(Regexp) ? body =~ opts[:with] : body.include?(opts[:with])
end
end

matcher :update_environment do
match do
requests[:update_environment].any?
end
end
let(:client) { Aws::ElasticBeanstalk::Client.new(stub_responses: responses) }
let(:s3) { Aws::S3::Client.new(stub_responses: true) }
let(:events) { [] }

before do
Aws.config[:s3] = {
stub_responses: {
}
}
Aws.config[:elasticbeanstalk] = {
stub_responses: {
create_application_version: ->(ctx) {
requests[:create_application_version] << ctx.http_request
{
application_version: {
version_label: 'label'
}
}
},
update_environment: ->(ctx) {
requests[:update_environment] << ctx.http_request
},
describe_environments: {
environments: [
status: 'Ready'
]
},
describe_events: {
events: events
let(:responses) do
{
create_application_version: {
application_version: {
version_label: 'label'
}
},
update_environment: {
},
describe_environments: {
environments: [
status: 'Ready'
]
},
describe_events: {
events: events
}
}
end

after { Aws.config.clear }

file 'one'
file 'two'

before { allow(Aws::ElasticBeanstalk::Client).to receive(:new).and_return(client) }
before { allow(Aws::S3::Client).to receive(:new).and_return(s3) }
before { |c| subject.run unless c.example_group.metadata[:run].is_a?(FalseClass) }

describe 'by default' do
before { subject.run }
it { should have_zipped "travis-sha-#{now.to_i}.zip", %w(one two) }
it { should have_run '[info] Using Access Key: i*******************' }
it { should create_app_version with: 'ApplicationName=dpl' }
it { should create_app_version with: 'Description=commit%20msg' }
it { should create_app_version with: 'S3Bucket=bucket' }
it { should create_app_version with: /S3Key=travis-sha-.*.zip/ }
it { should create_app_version with: /VersionLabel=travis-sha.*/ }
it { should create_app_version 'ApplicationName=dpl' }
it { should create_app_version 'Description=commit%20msg' }
it { should create_app_version 'S3Bucket=bucket' }
it { should create_app_version /S3Key=travis-sha-.*.zip/ }
it { should create_app_version /VersionLabel=travis-sha.*/ }
it { should update_environment }
end

describe 'given --bucket_path one/two' do
before { subject.run }
it { should create_app_version with: /S3Key=one%2Ftwo%2Ftravis-sha-.*.zip/ }
it { should create_app_version /S3Key=one%2Ftwo%2Ftravis-sha-.*.zip/ }
end

describe 'given --only_create_app_version' do
Expand All @@ -80,21 +62,21 @@
describe 'given --zip_file other.zip' do
before { subject.run }
it { expect(File.exist?('other.zip')).to be true }
it { should create_app_version with: /S3Key=travis-sha-.*.zip/ }
it { should create_app_version /S3Key=travis-sha-.*.zip/ }
end

describe 'given --wait_until_deployed' do
describe 'given --wait_until_deployed', run: false do
let(:events) { [event_date: Time.now, severity: 'ERROR', message: 'msg'] }
it { expect { subject.run }.to raise_error /Deployment failed/ }
end

describe 'with an .ebignore file' do
describe 'with an .ebignore file', run: false do
file '.ebignore', "*\n!one"
before { subject.run }
it { should have_zipped "travis-sha-#{now.to_i}.zip", %w(one) }
end

describe 'with ~/.aws/credentials' do
describe 'with ~/.aws/credentials', run: false do
let(:args) { |e| %w(--env env --bucket_name bucket) }

file '~/.aws/credentials', <<-str.sub(/^\s*/, '')
Expand All @@ -107,7 +89,7 @@
it { should have_run '[info] Using Access Key: ac******************' }
end

describe 'with ~/.aws/config' do
describe 'with ~/.aws/config', run: false do
let(:args) { |e| %w(--access_key_id id --secret_access_key secret) }

file '~/.aws/config', <<-str.sub(/^\s*/, '')
Expand All @@ -117,6 +99,6 @@
str

before { subject.run }
it { should create_app_version with: 'S3Bucket=bucket' }
it { should create_app_version 'S3Bucket=bucket' }
end
end

0 comments on commit 43e3f67

Please sign in to comment.