Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the task definition when running bootstrap #42

Merged
merged 5 commits into from
Jan 9, 2017
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.4.0
= [#42](https://github.com/lumoslabs/broadside/pull/42/files): Update the task definition when running bootstrap

# 1.3.0
- [#41](https://github.com/lumoslabs/broadside/pull/41/files): Introduce the concept of bootstrap commands, which are designed to be run when setting up a new server or environment.

Expand Down
4 changes: 4 additions & 0 deletions bin/broadside
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ end

desc 'Bootstrap your service and task definition from the configured definition.'
command :bootstrap do |b|
subcmd.desc 'Docker tag for application container'
subcmd.arg_name 'TAG'
subcmd.flag [:tag]

add_shared_deploy_configs(b)
end

Expand Down
13 changes: 12 additions & 1 deletion lib/broadside/deploy/ecs_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def deploy
def bootstrap
if EcsManager.get_latest_task_definition_arn(family)
info("Task definition for #{family} already exists.")
run_bootstrap_commands
else
unless @deploy_config.task_definition_config
raise ArgumentError, "No first task definition and no :task_definition_config in '#{family}' configuration"
Expand All @@ -61,6 +62,8 @@ def bootstrap
container_definitions: [DEFAULT_CONTAINER_DEFINITION.merge(container_definition)]
)
)

run_bootstrap_commands
end

if EcsManager.service_exists?(config.ecs.cluster, family)
Expand All @@ -73,8 +76,16 @@ def bootstrap
info "Service '#{family}' doesn't exist, creating..."
EcsManager.create_service(config.ecs.cluster, family, @deploy_config.service_config)
end
end

@deploy_config.bootstrap_commands.each { |command| run_command(command) }
def run_bootstrap_commands
update_task_revision

begin
@deploy_config.bootstrap_commands.each { |command| run_command(command) }
ensure
EcsManager.deregister_last_n_tasks_definitions(family, 1)
end
end

def rollback(count = @deploy_config.rollback)
Expand Down
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 = '1.3.0'
VERSION = '1.4.0'
end
47 changes: 26 additions & 21 deletions spec/broadside/deploy/ecs_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,43 @@
expect { deploy.bootstrap }.to raise_error(//)
end

it 'fails without service_config' do
deploy.deploy_config.task_definition_config = task_definition_config

expect { deploy.bootstrap }.to raise_error(/Service doesn't exist and no :service_config/)
end

context 'with an existing task definition and service' do
context 'with an existing task definition' do
before(:each) do
ecs_stub.stub_responses(:list_task_definitions, stub_task_definition_response)
ecs_stub.stub_responses(:describe_task_definition, stub_describe_task_definition_response)
ecs_stub.stub_responses(:describe_services, stub_service_response)
end

it 'succeeds' do
deploy.deploy_config.service_config = service_config
it 'fails without service_config' do
deploy.deploy_config.task_definition_config = task_definition_config

expect { deploy.bootstrap }.to_not raise_error
expect { deploy.bootstrap }.to raise_error(/Service doesn't exist and no :service_config/)
end

context 'and some configured bootstrap commands' do
before do
Broadside.configure do |config|
config.deploy.targets[task_name.to_sym][:bootstrap_commands] = [
%w(foo bar baz)
]
end
context 'with an existing service' do
before(:each) do
ecs_stub.stub_responses(:describe_services, stub_service_response)
end

it 'succeeds' do
deploy.deploy_config.service_config = service_config
deploy.deploy_config.task_definition_config = task_definition_config

expect { deploy.bootstrap }.to_not raise_error
end

it 'runs bootstrap commands' do
expect(deploy).to receive(:run_command).with(%w(foo bar baz))
deploy.bootstrap
context 'and some configured bootstrap commands' do
before do
Broadside.configure do |config|
config.deploy.targets[task_name.to_sym][:bootstrap_commands] = [
%w(foo bar baz)
]
end
end

it 'runs bootstrap commands' do
expect(deploy).to receive(:run_command).with(%w(foo bar baz))
deploy.bootstrap
end
end
end
end
Expand Down