hako 1.2.1 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54859bce2bfc4f5a8b7d4fa55afb605119aa3a80
4
- data.tar.gz: b9f1cdd54ccd8a09a68407dfa89237d8a245d3d7
3
+ metadata.gz: d2aaacf745660c3193a66d0527ff2ec56dac915b
4
+ data.tar.gz: 3110462e23bdaf2318eb964735405e38bdcd1176
5
5
  SHA512:
6
- metadata.gz: d719c61cfa81b858b45cd17a0c1b31d166f3daf6010a588f33715d369dbaac87638515e5b3dd1f39ec1d0922bac09a4c1d8222bb2e70c908c6316f021397a10a
7
- data.tar.gz: 90497feaab9dcd664fb4dbce60269b19530fbb526e64861ba10fcdc9afcbfc11373476f592318f51f7acb1b795776b29b5aacd198ed63bc5edefcec127cb191b
6
+ metadata.gz: 0e2f3a18e41a7cf61b25feea55feaa258d0365759d6cd24adaeb01b0b78c67cddbf6a1f94158cc2234b384506f612ed0b0645921331ccc5304ef51b8ab6ca7a0
7
+ data.tar.gz: d36842d199259f48306ba64fef90db984d84909971f2599e11429d2f95e6d6be511b8d6629b099cc2e825cd482f3830dfa79f6295b2a56da0017765250e63487
@@ -1,3 +1,9 @@
1
+ # 1.3.0 (2017-05-15)
2
+ ## New features
3
+ - Add `oneshot_notification_prefix` option
4
+ - This is **experimental** , so might be reverted in near version.
5
+ - This option enables S3 polling instead of ECS polling.
6
+
1
7
  # 1.2.1 (2017-05-11)
2
8
  ## Bug fixes
3
9
  - Retry DescribeTasks when rate limited
@@ -38,6 +38,7 @@ module Hako
38
38
  @autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), dry_run: @dry_run)
39
39
  end
40
40
  @autoscaling_group_for_oneshot = options.fetch('autoscaling_group_for_oneshot', nil)
41
+ @oneshot_notification_prefix = options.fetch('oneshot_notification_prefix', nil)
41
42
  @deployment_configuration = {}
42
43
  %i[maximum_percent minimum_healthy_percent].each do |key|
43
44
  @deployment_configuration[key] = options.dig('deployment_configuration', key.to_s)
@@ -541,11 +542,21 @@ module Hako
541
542
  exit_code
542
543
  end
543
544
 
545
+ # @param [Aws::ECS::Types::Task] task
546
+ # @return [Hash<String, Aws::ECS::Types::Container>]
547
+ def wait_for_task(task)
548
+ if @oneshot_notification_prefix
549
+ poll_task_status_from_s3(task)
550
+ else
551
+ poll_task_status_from_ecs(task)
552
+ end
553
+ end
554
+
544
555
  MIN_WAIT_TASK_INTERVAL = 1
545
556
  MAX_WAIT_TASK_INTERVAL = 120
546
557
  # @param [Aws::ECS::Types::Task] task
547
- # @return [nil]
548
- def wait_for_task(task)
558
+ # @return [Hash<String, Aws::ECS::Types::Container>]
559
+ def poll_task_status_from_ecs(task)
549
560
  task_arn = task.task_arn
550
561
  interval = 1
551
562
  loop do
@@ -591,6 +602,55 @@ module Hako
591
602
  end
592
603
  end
593
604
 
605
+ # @param [Aws::ECS::Types::Task] task
606
+ # @return [Hash<String, Aws::ECS::Types::Container>]
607
+ # Experimental: Get stopped container status from S3.
608
+ # The advantage is scalability; ecs:DescribeTasks is heavily
609
+ # rate-limited, but s3:GetObject is much more scalable.
610
+ # The JSON is supposed to be stored from Amazon ECS Event Stream.
611
+ # http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch_event_stream.html
612
+ def poll_task_status_from_s3(task)
613
+ s3 = Aws::S3::Client.new
614
+ task_arn = task.task_arn
615
+ uri = URI.parse(@oneshot_notification_prefix)
616
+ prefix = uri.path.sub(%r{\A/}, '')
617
+ started_key = "#{prefix}/#{task_arn}/started.json"
618
+ stopped_key = "#{prefix}/#{task_arn}/stopped.json"
619
+
620
+ loop do
621
+ unless @started_at
622
+ begin
623
+ object = s3.get_object(bucket: uri.host, key: started_key)
624
+ rescue Aws::S3::Errors::NoSuchKey
625
+ Hako.logger.debug(" s3://#{uri.host}/#{started_key} doesn't exist")
626
+ else
627
+ json = JSON.parse(object.body.read)
628
+ @started_at = Time.parse(json['detail']['startedAt'])
629
+ if @started_at
630
+ Hako.logger.info "Started at #{@started_at}"
631
+ end
632
+ end
633
+ end
634
+
635
+ begin
636
+ object = s3.get_object(bucket: uri.host, key: stopped_key)
637
+ rescue Aws::S3::Errors::NoSuchKey
638
+ Hako.logger.debug(" s3://#{uri.host}/#{stopped_key} doesn't exist")
639
+ else
640
+ json = JSON.parse(object.body.read)
641
+ task = Aws::Json::Parser.new(Aws::ECS::Client.api.operation('describe_tasks').output.shape.member(:tasks).shape.member).parse(json['detail'].to_json)
642
+ Hako.logger.info "Stopped at #{task.stopped_at} (reason: #{task.stopped_reason})"
643
+ containers = {}
644
+ task.containers.each do |c|
645
+ containers[c.name] = c
646
+ end
647
+ return containers
648
+ end
649
+
650
+ sleep 1
651
+ end
652
+ end
653
+
594
654
  # @param [String] container_instance_arn
595
655
  # @return [nil]
596
656
  def report_container_instance(container_instance_arn)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hako
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hako
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk