Class: Ufo::CLI::Rollback

Inherits:
Base
  • Object
show all
Includes:
Ufo::Concerns
Defined in:
lib/ufo/cli/rollback.rb

Instance Attribute Summary

Attributes inherited from Base

#task_definition

Instance Method Summary collapse

Methods included from Ufo::Concerns

#build, #info, #ps

Methods included from Ufo::Concerns::Names

#names

Methods inherited from Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from AwsServices::Concerns

#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns

Constructor Details

This class inherits a constructor from Ufo::CLI::Base

Instance Method Details

#deployObject



5
6
7
8
9
10
11
# File 'lib/ufo/cli/rollback.rb', line 5

def deploy
  are_you_sure?
  rollback_task_definition = normalize_version(@options[:version])
  logger.info "Rolling back ECS Service to task definition: #{rollback_task_definition}"
  ship = Ship.new(@options.merge(rollback_task_definition: rollback_task_definition, rollback: true, yes: true))
  ship.run
end

#find_sha(task_definition, sha) ⇒ Object



51
52
53
54
# File 'lib/ufo/cli/rollback.rb', line 51

def find_sha(task_definition, sha)
  container = task_definition["container_definitions"].first # assume first
  container["image"].include?(sha)
end

#from_git_sha(sha) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ufo/cli/rollback.rb', line 28

def from_git_sha(sha)
  task_definition = nil
  max_items = 30
  logger.info "Looking for task definition based on the git sha.  Searching most recent #{max_items} task definitions..."
  arns = task_definition_arns(@task_definition.name, max_items)
  arns.each do |arn|
    resp = ecs.describe_task_definition(task_definition: arn)
    found = find_sha(resp.task_definition, sha)
    if found
      task_definition = arn.split('/').last
      break
    end
    print '.'
    @final_newline
  end

  logger.info '' if @final_newline
  unless task_definition
    logger.info "Unable to find a task definition with a image with: #{version}"
  end
  task_definition
end

#normalize_version(version) ⇒ Object

normalizes the task definition if user passes in:

1 => demo-web:1
demo-web:1 => demo-web:1


17
18
19
20
21
22
23
24
25
26
# File 'lib/ufo/cli/rollback.rb', line 17

def normalize_version(version)
  if version =~ /^\d+$/
    "#{@task_definition.name}:#{version}"
  elsif version.include?(':') && !version.include?(":ufo-")
    version
  else # assume git sha
    # org/repo:ufo-2018-06-21T15-03-52-ac60240
    from_git_sha(version)
  end
end