Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/broadside/ecs/ecs_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def update_service(options = {})
desired_count: scale,
service: family,
task_definition: task_definition_arn
}.deep_merge(@target.service_config || {}))
}.deep_merge(@target.service_config_for_update || {}))

unless update_service_response.successful?
raise EcsError, "Failed to update service:\n#{update_service_response.pretty_inspect}"
Expand Down
12 changes: 12 additions & 0 deletions lib/broadside/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class Target
record.errors.add(attr, 'is not an array of strings') unless val.is_a?(Array) && val.all? { |v| v.is_a?(String) }
end

CREATE_ONLY_SERVICE_ATTRIBUTES = %i(
client_token
load_balancers
placement_constraints
placement_strategy
role
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

).freeze

def initialize(name, options = {})
@name = name

Expand Down Expand Up @@ -93,5 +101,9 @@ def to_h
Cluster: @cluster
}
end

def service_config_for_update
service_config.try(:except, *CREATE_ONLY_SERVICE_ATTRIBUTES)
end
end
end
2 changes: 1 addition & 1 deletion lib/broadside/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Broadside
VERSION = '3.0.4'.freeze
VERSION = '3.0.5'.freeze
end
39 changes: 36 additions & 3 deletions spec/broadside/ecs/ecs_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@
let(:desired_count) { 4 }
let(:cpu) { 1 }
let(:memory) { 2000 }
let(:service_config) do
let(:base_service_config) do
{
desired_count: desired_count,
deployment_configuration: {
minimum_healthy_percent: 40,
}
}
end
let(:service_config_with_load_balancers) do
base_service_config.merge(
role: 'ecsServiceRole',
load_balancers: [
{
container_name: 'test-container',
container_port: 8080,
load_balancer_name: 'test-container-elb'
}
]
)
end
let(:service_config) { base_service_config }

describe '#bootstrap' do
it 'fails without task_definition_config' do
Expand All @@ -40,7 +53,7 @@
end
end

context 'with an existing service' do
shared_examples 'correctly-behaving bootstrap' do
include_context 'with a running service'

it 'succeeds' do
Expand All @@ -57,6 +70,16 @@
end
end
end

context 'with an existing service' do
it_behaves_like 'correctly-behaving bootstrap'
end

context 'with an existing task definition that has create-only parameters' do
let(:service_config) { service_config_with_load_balancers }

it_behaves_like 'correctly-behaving bootstrap'
end
end
end

Expand All @@ -72,7 +95,7 @@
expect { deploy.short }.to raise_error(/No task definition for/)
end

context 'with an existing task definition' do
shared_examples 'correctly-behaving deploy' do
include_context 'with a task_definition'

it 'short deploy does not fail' do
Expand Down Expand Up @@ -142,6 +165,16 @@
expect(api_request_methods.include?(:update_service)).to be true
end
end

context 'with an existing task definition' do
it_behaves_like 'correctly-behaving deploy'
end

context 'with an existing task definition that has create-only parameters' do
let(:service_config) { service_config_with_load_balancers }

it_behaves_like 'correctly-behaving deploy'
end
end
end

Expand Down
66 changes: 48 additions & 18 deletions spec/broadside/target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
describe Broadside::Target do
include_context 'deploy configuration'

describe '#initialize' do
let(:all_possible_options) do
{
bootstrap_commands: [],
cluster: 'some-cluster',
command: %w(some command),
docker_image: 'lumoslabs/hello',
env_file: '.env.test',
predeploy_commands: [],
scale: 9000,
service_config: {},
tag: 'latest',
task_definition_config: {}
}
end
let(:target) { described_class.new(test_target_name, all_possible_options) }
let(:base_possible_options) do
{
bootstrap_commands: [],
cluster: 'some-cluster',
command: %w(some command),
docker_image: 'lumoslabs/hello',
env_file: '.env.test',
predeploy_commands: [],
scale: 9000,
service_config: {},
tag: 'latest',
task_definition_config: {}
}
end
let(:all_possible_options) { base_possible_options }
let(:all_possible_options_with_create_only_service_options) { base_possible_options }
let(:target) { described_class.new(test_target_name, all_possible_options) }

describe '#initialize' do
it 'should initialize without erroring using all possible options' do
expect { target }.to_not raise_error
end
Expand All @@ -46,7 +48,7 @@

it_behaves_like 'valid_configuration?', true, env_files: nil
it_behaves_like 'valid_configuration?', true, env_files: 'file'
it_behaves_like 'valid_configuration?', true, env_files: ['file', 'file2']
it_behaves_like 'valid_configuration?', true, env_files: %w(file file2)

it_behaves_like 'valid_configuration?', true, command: nil
it_behaves_like 'valid_configuration?', true, command: %w(do something)
Expand Down Expand Up @@ -76,7 +78,7 @@
let(:expected_env_vars) do
[
{ 'name' => 'TEST_KEY1', 'value' => 'TEST_VALUE1' },
{ 'name' => 'TEST_KEY2', 'value' => 'TEST_VALUE2'}
{ 'name' => 'TEST_KEY2', 'value' => 'TEST_VALUE2' }
]
end

Expand All @@ -96,4 +98,32 @@
it_behaves_like 'successfully loaded env_files'
end
end

describe '#service_config_for_update' do
context 'with no service config' do
it 'does not raise an error' do
expect { target }.to_not raise_error
end
end

shared_examples 'accessor for update-safe service config parameters' do
it 'does not raise an error' do
expect { target }.to_not raise_error
end

it 'returns the basic serivce config parameters' do
expect(target.service_config).to eq(base_possible_options[:service_config])
end
end

context 'with a normal service config' do
it_behaves_like 'accessor for update-safe service config parameters'
end

context 'with a service config containing create-only parameters' do
let(:all_possible_options) { all_possible_options_with_create_only_service_options }

it_behaves_like 'accessor for update-safe service config parameters'
end
end
end