Class: Ufo::Rollback
Instance Method Summary collapse
- #deploy ⇒ Object
- #find_sha(task_definition, sha) ⇒ Object
- #from_git_sha(sha) ⇒ Object
-
#normalize_version(version) ⇒ Object
normalizes the task definition if user passes in: 1 => demo-web:1 demo-web:1 => demo-web:1.
Methods inherited from Base
#full_service, #info, #initialize, #no_service_message, #switch_current
Methods included from Stack::Helper
#adjust_stack_name, #cfn, #find_stack, #status
Methods included from Util
#default_cluster, #display_params, #execute, #pretty_time, #settings, #task_definition_arns, #user_params
Methods included from AwsService
#cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb
Constructor Details
This class inherits a constructor from Ufo::Base
Instance Method Details
#deploy ⇒ Object
3 4 5 6 7 8 |
# File 'lib/ufo/rollback.rb', line 3 def deploy task_definition = normalize_version(@options[:version]) puts "Rolling back ECS service to task definition #{task_definition}" ship = Ship.new(@service, @options.merge(task_definition: task_definition)) ship.deploy end |
#find_sha(task_definition, sha) ⇒ Object
48 49 50 51 |
# File 'lib/ufo/rollback.rb', line 48 def find_sha(task_definition, sha) container = task_definition["container_definitions"].first # assume first container["image"].include?(sha) end |
#from_git_sha(sha) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ufo/rollback.rb', line 25 def from_git_sha(sha) task_definition = nil max_items = 30 puts "Looking for task definition based on the git sha. Searching most recent #{max_items} task definitions..." arns = task_definition_arns(@service, 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 puts '' if @final_newline unless task_definition puts "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
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ufo/rollback.rb', line 14 def normalize_version(version) if version =~ /^\d+$/ "#{@service}:#{version}" elsif version.include?(':') && !version.include?(":ufo-") version else # assume git sha # tongueroo/demo-ufo:ufo-2018-06-21T15-03-52-ac60240 from_git_sha(version) end end |