Class: Ufo::Ship
Instance Method Summary collapse
- #deploy ⇒ Object
- #deploy_stack ⇒ Object
- #ecs_clusters ⇒ Object
- #ensure_cluster_exist ⇒ Object
- #ensure_log_group_exist ⇒ Object
-
#initialize(service, options = {}) ⇒ Ship
constructor
A new instance of Ship.
- #show_aws_cli_command(action, params) ⇒ Object
-
#stop_old_tasks ⇒ Object
Start a thread that will poll for ecs deployments and kill of tasks in old deployments.
Methods inherited from Base
#info, #no_service_message, #switch_current
Methods included from Ufo::Stack::Helper
#adjust_stack_name, #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
#initialize(service, options = {}) ⇒ Ship
Returns a new instance of Ship.
9 10 11 12 |
# File 'lib/ufo/ship.rb', line 9 def initialize(service, ={}) super @task_definition = [:task_definition] end |
Instance Method Details
#deploy ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ufo/ship.rb', line 14 def deploy = "Deploying #{@service}..." unless [:mute] if [:noop] puts "NOOP: #{message}" return else puts .green end end ensure_log_group_exist ensure_cluster_exist stop_old_tasks if [:stop_old_tasks] success = deploy_stack return if [:mute] || ![:wait] if success puts "Software shipped!" else puts "Software fail to ship." end end |
#deploy_stack ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/ufo/ship.rb', line 59 def deploy_stack = .merge( service: @service, task_definition: @task_definition, ) stack = Stack.new() stack.deploy end |
#ecs_clusters ⇒ Object
101 102 103 |
# File 'lib/ufo/ship.rb', line 101 def ecs_clusters ecs.describe_clusters(clusters: [@cluster]).clusters end |
#ensure_cluster_exist ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ufo/ship.rb', line 85 def ensure_cluster_exist cluster = ecs_clusters.first unless cluster && cluster.status == "ACTIVE" = "#{@cluster} cluster created." if [:noop] = "NOOP #{message}" else ecs.create_cluster(cluster_name: @cluster) # TODO: Add Waiter logic, sometimes the cluster does not exist by the time # we create the service end puts unless [:mute] end end |
#ensure_log_group_exist ⇒ Object
55 56 57 |
# File 'lib/ufo/ship.rb', line 55 def ensure_log_group_exist LogGroup.new(@task_definition, ).create end |
#show_aws_cli_command(action, params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ufo/ship.rb', line 68 def show_aws_cli_command(action, params) puts "Equivalent aws cli command:" # Use .ufo/data instead of .ufo/output because output files all get looped # through as part of `ufo tasks register` rel_path = ".ufo/data/#{action}-params.json" output_path = "#{Ufo.root}/#{rel_path}" FileUtils.rm_f(output_path) # Thanks: https://www.mnishiguchi.com/2017/11/29/rails-hash-camelize-and-underscore-keys/ params = params.deep_transform_keys { |key| key.to_s.camelize(:lower) } json = JSON.pretty_generate(params) IO.write(output_path, json) file_path = "file://#{rel_path}" puts " aws ecs #{action}-service --cli-input-json #{file_path}".colorize(:green) end |
#stop_old_tasks ⇒ Object
Start a thread that will poll for ecs deployments and kill of tasks in old deployments. This must be done in a thread because the stack update process is blocking.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ufo/ship.rb', line 41 def stop_old_tasks # only works when deployment is blocking return unless [:wait] Thread.new do stop = Ufo::Stop.new(@service, .merge(mute: true)) while true stop.log "checking for old tasks and waiting for 10 seconds" stop.run sleep 10 end end end |