class ECSHelper::Command::Deploy

Constants

DEFAULT_TIMEOUT
STEP

Attributes

new_task_definition[RW]
repositories[RW]
service[RW]
task_definition[RW]

Public Instance Methods

cmd_option_parser() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 8
def cmd_option_parser
  options = {}
  parser = ::OptionParser.new do |opts|
    opts.banner = "Usage: ecs_helper deploy [options]"
    opts.on("-p VALUE", "--project VALUE", "Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") { |p| options[:project] = processEqual(p) }
    opts.on("-a VALUE", "--application VALUE", "Set application name, if not specified will look at ENV['APPLICATION'], will be used to detect service and task definition") { |a| options[:application] = processEqual(a) }
    opts.on("-e VALUE", "--environment VALUE", "Set environment, if not specified will look at ENV['ENVIRONMENT'], it there is empty will try to detect based on the branch") { |e| options[:environment] = processEqual(e) }
    opts.on("-v VALUE", "--version VALUE", "Set version which will be applied to all containers in the task if tag is present in the repo") { |t| options[:version] = processEqual(t) }
    opts.on("-cl VALUE", "--cluster VALUE", "Set cluster name, could be autodetected if project and environment are specified") { |c| options[:cluster] = processEqual(c) }
    opts.on("-s VALUE", "--service VALUE", "Set service, could be autodetected if application and environment are specified") { |s| options[:service] = processEqual(s) }
    opts.on("-t VALUE", "--timeout VALUE", "Set timeout how long to wait until deployment finished") { |t| options[:timeout] = processEqual(t) }
  end
  [parser, options]
end
run() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 23
def run
  task_definition_helper = ECSHelper::TaskDefinitionHelper.new(helper, service)
  service_task_definition = task_definition_helper.service_task_definition
  new_task_definition_hash = task_definition_helper.new_task_definition_hash
  new_task_definition = task_definition_helper.register_task_definition(new_task_definition_hash)
  log("Command", type)
  log("Options", options)
  log("Environment", environment)
  log("Cluster", cluster_arn)
  log("Service", service_arn)
  log("Version", version)
  log("Service task definition", service_task_definition.task_definition_arn)
  log("Containers", task_definition_helper.pretty_container_definitions)
  log("New task definition", new_task_definition.task_definition_arn)
  update_service(new_task_definition.task_definition_arn, service_task_definition.task_definition_arn) && log("Update service", "Service task definition was updated")
  log("Waiting for deployment...")
  wait_for_deployment && log("Success", "Application was succesfully deployed", :cyan)
end
update_service(task_definition_arn, old_task_definition_arn) click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 42
def update_service(task_definition_arn, old_task_definition_arn)
  helper.update_service(cluster_arn, service_arn, task_definition_arn)
  helper.client.deregister_task_definition(task_definition: old_task_definition_arn)
end
wait_for_deployment(time = 0) click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 47
def wait_for_deployment(time = 0)
  return true if service.deployments.count == 1
  error("Deployment timeout (#{timeout})") if time > timeout
  sleep STEP
  wait_for_deployment(time + STEP)
end

Private Instance Methods

cluster_arn() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 60
def cluster_arn
  helper.current_cluster
end
environment() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 56
def environment
  helper.environment
end
service_arn() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 64
def service_arn
  helper.current_service
end
timeout() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 72
def timeout
  options[:timeout] || DEFAULT_TIMEOUT
end
version() click to toggle source
# File lib/ecs_helper/command/deploy.rb, line 68
def version
  options[:version] || helper.version
end