Class: Broadside::EcsDeploy
- Defined in:
- lib/broadside/ecs/ecs_deploy.rb
Constant Summary collapse
- DEFAULT_CONTAINER_DEFINITION =
{ cpu: 1, essential: true, memory: 1024 }
Instance Attribute Summary
Attributes inherited from Deploy
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #full ⇒ Object
- #rollback(options = {}) ⇒ Object
- #run_commands(commands, options = {}) ⇒ Object
- #scale(options = {}) ⇒ Object
- #short ⇒ Object
Methods inherited from Deploy
Constructor Details
This class inherits a constructor from Broadside::Deploy
Instance Method Details
#bootstrap ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 26 def bootstrap if EcsManager.get_latest_task_definition_arn(family) info "Task definition for #{family} already exists." else raise ConfigurationError, "No :task_definition_config for #{family}" unless @target.task_definition_config raise ConfigurationError, 'Bootstrapping a task_definition requires a :tag for the image' unless @tag info "Creating an initial task definition for '#{family}' from the config..." EcsManager.ecs.register_task_definition( @target.task_definition_config.merge( family: family, container_definitions: [DEFAULT_CONTAINER_DEFINITION.merge(configured_container_definition)] ) ) end run_commands(@target.bootstrap_commands, started_by: 'bootstrap') if EcsManager.service_exists?(cluster, family) info("Service for #{family} already exists.") else raise ConfigurationError, "No :service_config for #{family}" unless @target.service_config info "Service '#{family}' doesn't exist, creating..." EcsManager.create_service(cluster, family, @target.service_config) end end |
#full ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 18 def full info "Running predeploy commands for #{family}..." run_commands(@target.predeploy_commands, started_by: 'predeploy') info 'Predeploy complete.' deploy end |
#rollback(options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 53 def rollback( = {}) count = [:rollback] || 1 info "Rolling back #{count} release(s) for #{family}..." EcsManager.check_service_and_task_definition_state!(@target) begin EcsManager.deregister_last_n_tasks_definitions(family, count) update_service() rescue StandardError error 'Rollback failed to complete!' raise end info 'Rollback complete.' end |
#run_commands(commands, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 75 def run_commands(commands, = {}) return if commands.nil? || commands.empty? update_task_revision begin commands.each do |command| command_name = "'#{command.join(' ')}'" task_arn = EcsManager.run_task(cluster, family, command, ).tasks[0].task_arn info "Launched #{command_name} task #{task_arn}, waiting for completion..." EcsManager.ecs.wait_until(:tasks_stopped, cluster: cluster, tasks: [task_arn]) do |w| w.max_attempts = nil w.delay = Broadside.config.aws.ecs_poll_frequency w.before_attempt do |attempt| info "Attempt #{attempt}: waiting for #{command_name} to complete..." end end exit_status = EcsManager.get_task_exit_status(cluster, task_arn, family) raise EcsError, "#{command_name} failed to start:\n'#{exit_status[:reason]}'" if exit_status[:exit_code].nil? raise EcsError, "#{command_name} nonzero exit code: #{exit_status[:exit_code]}!" unless exit_status[:exit_code].zero? info "#{command_name} task container logs:\n#{get_container_logs(task_arn)}" info "#{command_name} task #{task_arn} complete" end ensure EcsManager.deregister_last_n_tasks_definitions(family, 1) end end |
#scale(options = {}) ⇒ Object
69 70 71 72 73 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 69 def scale( = {}) info "Rescaling #{family} with scale=#{[:scale] || @target.scale}..." update_service() info 'Rescaling complete.' end |
#short ⇒ Object
14 15 16 |
# File 'lib/broadside/ecs/ecs_deploy.rb', line 14 def short deploy end |