hako 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/hako/commander.rb +29 -1
 - data/lib/hako/schedulers/ecs.rb +38 -25
 - data/lib/hako/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 872f90813b982a8a19c5b4cf901aa06eb401216b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 02e799d33ceaa061a85578b48929b2eaa4c0922c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f6089d93829d5c5866857bb10104a5a145801efd7ca3672aec0e6e58704d735416404a435b780d0f5d897a0c838de545c3ea051e060584f5a4db8a28d0aeb824
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 50227fd8d3abfff03896b85fbb96a9deb9c53246e26c05724d9e0bc01d30cb53c70b1d3667ef782751b80da7003381ce738fa3f63cc5b8dab6c45e8acf3937a6
         
     | 
    
        data/lib/hako/commander.rb
    CHANGED
    
    | 
         @@ -27,7 +27,9 @@ module Hako 
     | 
|
| 
       27 
27 
     | 
    
         
             
                def oneshot(commands, tag:, containers:, env: {})
         
     | 
| 
       28 
28 
     | 
    
         
             
                  containers = load_containers(tag, dry_run: false, with: containers)
         
     | 
| 
       29 
29 
     | 
    
         
             
                  scheduler = load_scheduler(@app.yaml['scheduler'])
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 30 
     | 
    
         
            +
                  with_oneshot_signal_handlers(scheduler) do
         
     | 
| 
      
 31 
     | 
    
         
            +
                    exit scheduler.oneshot(containers, commands, env)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
       31 
33 
     | 
    
         
             
                end
         
     | 
| 
       32 
34 
     | 
    
         | 
| 
       33 
35 
     | 
    
         
             
                def status
         
     | 
| 
         @@ -42,6 +44,32 @@ module Hako 
     | 
|
| 
       42 
44 
     | 
    
         | 
| 
       43 
45 
     | 
    
         
             
                private
         
     | 
| 
       44 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                TRAP_SIGNALS = %i[INT TERM].freeze
         
     | 
| 
      
 48 
     | 
    
         
            +
                class SignalTrapped < StandardError; end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def with_oneshot_signal_handlers(scheduler, &block)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  old_handlers = {}
         
     | 
| 
      
 52 
     | 
    
         
            +
                  trapped = false
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 55 
     | 
    
         
            +
                    TRAP_SIGNALS.each do |sig|
         
     | 
| 
      
 56 
     | 
    
         
            +
                      old_handlers[sig] = Signal.trap(sig) { raise SignalTrapped }
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    block.call
         
     | 
| 
      
 59 
     | 
    
         
            +
                  rescue SignalTrapped
         
     | 
| 
      
 60 
     | 
    
         
            +
                    trapped = true
         
     | 
| 
      
 61 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 62 
     | 
    
         
            +
                    old_handlers.each do |sig, command|
         
     | 
| 
      
 63 
     | 
    
         
            +
                      Signal.trap(sig, command)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  if trapped
         
     | 
| 
      
 68 
     | 
    
         
            +
                    scheduler.stop_oneshot
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                  nil
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       45 
73 
     | 
    
         
             
                def load_containers(tag, dry_run:, with: nil)
         
     | 
| 
       46 
74 
     | 
    
         
             
                  app = AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: dry_run)
         
     | 
| 
       47 
75 
     | 
    
         
             
                  front = load_front(@app.yaml['front'], dry_run: dry_run)
         
     | 
    
        data/lib/hako/schedulers/ecs.rb
    CHANGED
    
    | 
         @@ -22,6 +22,8 @@ module Hako 
     | 
|
| 
       22 
22 
     | 
    
         
             
                    @ec2 = Aws::EC2::Client.new(region: region)
         
     | 
| 
       23 
23 
     | 
    
         
             
                    @force = force
         
     | 
| 
       24 
24 
     | 
    
         
             
                    @dry_run = dry_run
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @started_at = nil
         
     | 
| 
      
 26 
     | 
    
         
            +
                    @container_instance_arn = nil
         
     | 
| 
       25 
27 
     | 
    
         
             
                  end
         
     | 
| 
       26 
28 
     | 
    
         | 
| 
       27 
29 
     | 
    
         
             
                  def deploy(containers)
         
     | 
| 
         @@ -67,22 +69,17 @@ module Hako 
     | 
|
| 
       67 
69 
     | 
    
         
             
                    else
         
     | 
| 
       68 
70 
     | 
    
         
             
                      Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
         
     | 
| 
       69 
71 
     | 
    
         
             
                    end
         
     | 
| 
       70 
     | 
    
         
            -
                    task = run_task(task_definition, commands, env)
         
     | 
| 
       71 
     | 
    
         
            -
                    Hako.logger.info "Started task: #{task.task_arn}"
         
     | 
| 
       72 
     | 
    
         
            -
                     
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                       
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                        if name == 'app'
         
     | 
| 
       81 
     | 
    
         
            -
                          exit_code = container.exit_code
         
     | 
| 
       82 
     | 
    
         
            -
                        end
         
     | 
| 
       83 
     | 
    
         
            -
                      end
         
     | 
| 
      
 72 
     | 
    
         
            +
                    @task = run_task(task_definition, commands, env)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    Hako.logger.info "Started task: #{@task.task_arn}"
         
     | 
| 
      
 74 
     | 
    
         
            +
                    wait_for_oneshot_finish
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  def stop_oneshot
         
     | 
| 
      
 78 
     | 
    
         
            +
                    if @task
         
     | 
| 
      
 79 
     | 
    
         
            +
                      Hako.logger.warn "Stopping #{@task.task_arn}"
         
     | 
| 
      
 80 
     | 
    
         
            +
                      @ecs.stop_task(cluster: @cluster, task: @task.task_arn, reason: 'Stopped by hako stop_oneshot')
         
     | 
| 
      
 81 
     | 
    
         
            +
                      wait_for_oneshot_finish
         
     | 
| 
       84 
82 
     | 
    
         
             
                    end
         
     | 
| 
       85 
     | 
    
         
            -
                    exit_code
         
     | 
| 
       86 
83 
     | 
    
         
             
                  end
         
     | 
| 
       87 
84 
     | 
    
         | 
| 
       88 
85 
     | 
    
         
             
                  def status
         
     | 
| 
         @@ -313,27 +310,43 @@ module Hako 
     | 
|
| 
       313 
310 
     | 
    
         
             
                    ).tasks[0]
         
     | 
| 
       314 
311 
     | 
    
         
             
                  end
         
     | 
| 
       315 
312 
     | 
    
         | 
| 
      
 313 
     | 
    
         
            +
                  def wait_for_oneshot_finish
         
     | 
| 
      
 314 
     | 
    
         
            +
                    containers = wait_for_task(@task)
         
     | 
| 
      
 315 
     | 
    
         
            +
                    @task = nil
         
     | 
| 
      
 316 
     | 
    
         
            +
                    Hako.logger.info 'Oneshot task finished'
         
     | 
| 
      
 317 
     | 
    
         
            +
                    exit_code = 127
         
     | 
| 
      
 318 
     | 
    
         
            +
                    containers.each do |name, container|
         
     | 
| 
      
 319 
     | 
    
         
            +
                      if container.exit_code.nil?
         
     | 
| 
      
 320 
     | 
    
         
            +
                        Hako.logger.info "#{name} has stopped without exit_code: reason=#{container.reason}"
         
     | 
| 
      
 321 
     | 
    
         
            +
                      else
         
     | 
| 
      
 322 
     | 
    
         
            +
                        Hako.logger.info "#{name} has stopped with exit_code=#{container.exit_code}"
         
     | 
| 
      
 323 
     | 
    
         
            +
                        if name == 'app'
         
     | 
| 
      
 324 
     | 
    
         
            +
                          exit_code = container.exit_code
         
     | 
| 
      
 325 
     | 
    
         
            +
                        end
         
     | 
| 
      
 326 
     | 
    
         
            +
                      end
         
     | 
| 
      
 327 
     | 
    
         
            +
                    end
         
     | 
| 
      
 328 
     | 
    
         
            +
                    exit_code
         
     | 
| 
      
 329 
     | 
    
         
            +
                  end
         
     | 
| 
      
 330 
     | 
    
         
            +
             
     | 
| 
       316 
331 
     | 
    
         
             
                  def wait_for_task(task)
         
     | 
| 
       317 
332 
     | 
    
         
             
                    task_arn = task.task_arn
         
     | 
| 
       318 
     | 
    
         
            -
                    container_instance_arn = nil
         
     | 
| 
       319 
     | 
    
         
            -
                    started_at = nil
         
     | 
| 
       320 
333 
     | 
    
         
             
                    loop do
         
     | 
| 
       321 
334 
     | 
    
         
             
                      task = @ecs.describe_tasks(cluster: @cluster, tasks: [task_arn]).tasks[0]
         
     | 
| 
       322 
     | 
    
         
            -
                      if container_instance_arn != task.container_instance_arn
         
     | 
| 
       323 
     | 
    
         
            -
                        container_instance_arn = task.container_instance_arn
         
     | 
| 
       324 
     | 
    
         
            -
                        report_container_instance(container_instance_arn)
         
     | 
| 
      
 335 
     | 
    
         
            +
                      if @container_instance_arn != task.container_instance_arn
         
     | 
| 
      
 336 
     | 
    
         
            +
                        @container_instance_arn = task.container_instance_arn
         
     | 
| 
      
 337 
     | 
    
         
            +
                        report_container_instance(@container_instance_arn)
         
     | 
| 
       325 
338 
     | 
    
         
             
                      end
         
     | 
| 
       326 
     | 
    
         
            -
                      unless started_at
         
     | 
| 
       327 
     | 
    
         
            -
                        started_at = task.started_at
         
     | 
| 
       328 
     | 
    
         
            -
                        if started_at
         
     | 
| 
       329 
     | 
    
         
            -
                          Hako.logger.info "Started at #{started_at}"
         
     | 
| 
      
 339 
     | 
    
         
            +
                      unless @started_at
         
     | 
| 
      
 340 
     | 
    
         
            +
                        @started_at = task.started_at
         
     | 
| 
      
 341 
     | 
    
         
            +
                        if @started_at
         
     | 
| 
      
 342 
     | 
    
         
            +
                          Hako.logger.info "Started at #{@started_at}"
         
     | 
| 
       330 
343 
     | 
    
         
             
                        end
         
     | 
| 
       331 
344 
     | 
    
         
             
                      end
         
     | 
| 
       332 
345 
     | 
    
         | 
| 
       333 
346 
     | 
    
         
             
                      Hako.logger.debug "  status #{task.last_status}"
         
     | 
| 
       334 
347 
     | 
    
         | 
| 
       335 
348 
     | 
    
         
             
                      if task.last_status == 'STOPPED'
         
     | 
| 
       336 
     | 
    
         
            -
                        Hako.logger.info "Stopped at #{task.stopped_at}"
         
     | 
| 
      
 349 
     | 
    
         
            +
                        Hako.logger.info "Stopped at #{task.stopped_at} (reason: #{task.stopped_reason})"
         
     | 
| 
       337 
350 
     | 
    
         
             
                        containers = {}
         
     | 
| 
       338 
351 
     | 
    
         
             
                        task.containers.each do |c|
         
     | 
| 
       339 
352 
     | 
    
         
             
                          containers[c.name] = c
         
     | 
    
        data/lib/hako/version.rb
    CHANGED