hako 1.3.1 → 1.3.2

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: be720c4761b90dbbae3c8d302cbe3c50421c915a
4
- data.tar.gz: 40a6297d8e167ea157cb3080749d56c70ab9cbe0
3
+ metadata.gz: 1c3cbac9e99948d6066a1298afe5ca3076760291
4
+ data.tar.gz: b0839a1b24e6999fb06bdd966d91361920a62410
5
5
  SHA512:
6
- metadata.gz: b5f6863cebd0493b0d47a72bc82296490195446aa8a8fd74a2f401f0b67046aa472f14266928ceba3e71694da7aa8a5050d4e6bfa81399cdb44a552c5600e2e4
7
- data.tar.gz: 13e21ae6fa1ae860a5598f8abe5910b5b8e759889ec9a439f9984b79d407588c4b43719a51f90b09eb2bd1530913f1993fb206e54bad07d172330b18c240fc7b
6
+ metadata.gz: b37865f52d9b2c08d2892659d1cfe7b0706f08ba62e8ec44102e27a347b91ce334d1dfeafe5583c0dc3169848c3180ae291c2efa0cb0bbf95a6afd29f0905a47
7
+ data.tar.gz: aca7ab571e6f2a6d3d584f303430a17eaf2d5c435e67ec08912512a0e991465cdc2188b62f1bac0dc8b00954295accdfb15d8ec6d05dc0bf60475bddb5dc6470
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.3.2 (2017-05-23)
2
+ ## Bug fixes
3
+ - Pass placement_configurations in oneshot mode
4
+ - Symbolize port_mapping keys to compare definitions correctly
5
+
6
+ ## Improvements
7
+ - Reduce the number of DescribeTaskDefinition calls
8
+
1
9
  # 1.3.1 (2017-05-16)
2
10
  ## Bug fixes
3
11
  - Retry DescribeAutoScalingGroups when rate limited
@@ -25,7 +25,6 @@ module Hako
25
25
  memory
26
26
  memory_reservation
27
27
  links
28
- port_mappings
29
28
  command
30
29
  user
31
30
  privileged
@@ -44,6 +43,17 @@ module Hako
44
43
  @expanded_env ||= expand_env(@definition.fetch('env'))
45
44
  end
46
45
 
46
+ # @return [Array<Hash>]
47
+ def port_mappings
48
+ @definition['port_mappings'].map do |port_mapping|
49
+ {
50
+ container_port: port_mapping.fetch('container_port'),
51
+ host_port: port_mapping.fetch('host_port'),
52
+ protocol: port_mapping.fetch('protocol', 'tcp'),
53
+ }
54
+ end
55
+ end
56
+
47
57
  # @return [Array<Hash>]
48
58
  def mount_points
49
59
  @definition['mount_points'].map do |mount_point|
@@ -69,13 +69,11 @@ module Hako
69
69
  end
70
70
  else
71
71
  current_service = describe_service
72
- task_definition = register_task_definition(definitions)
73
- task_definition_changed = task_definition != :noop
72
+ task_definition_changed, task_definition = register_task_definition(definitions)
74
73
  if task_definition_changed
75
74
  Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
76
75
  else
77
- Hako.logger.info "Task definition isn't changed"
78
- task_definition = ecs_client.describe_task_definition(task_definition: @app_id).task_definition
76
+ Hako.logger.info "Task definition isn't changed: #{task_definition.task_definition_arn}"
79
77
  end
80
78
  unless current_service
81
79
  current_service = create_initial_service(task_definition.task_definition_arn, front_port)
@@ -151,12 +149,11 @@ module Hako
151
149
  end
152
150
  0
153
151
  else
154
- task_definition = register_task_definition_for_oneshot(definitions)
155
- if task_definition == :noop
156
- Hako.logger.info "Task definition isn't changed"
157
- task_definition = ecs_client.describe_task_definition(task_definition: "#{@app_id}-oneshot").task_definition
158
- else
152
+ updated, task_definition = register_task_definition_for_oneshot(definitions)
153
+ if updated
159
154
  Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
155
+ else
156
+ Hako.logger.info "Task definition isn't changed: #{task_definition.task_definition_arn}"
160
157
  end
161
158
  @task = run_task(task_definition, commands, env)
162
159
  Hako.logger.info "Started task: #{@task.task_arn}"
@@ -353,26 +350,25 @@ module Hako
353
350
  end
354
351
  end
355
352
 
356
- # @param [String] family
357
- # @param [Array<Hash>] definitions
358
- # @return [Boolean]
359
- def task_definition_changed?(family, definitions)
353
+ # @param [Array<Hash>] desired_definitions
354
+ # @param [Aws::ECS::Types::TaskDefinition] actual_definition
355
+ # @return [Array<Boolean]
356
+ def task_definition_changed?(desired_definitions, actual_definition)
360
357
  if @force
361
358
  return true
362
359
  end
363
- task_definition = ecs_client.describe_task_definition(task_definition: family).task_definition
364
360
  container_definitions = {}
365
- task_definition.container_definitions.each do |c|
361
+ actual_definition.container_definitions.each do |c|
366
362
  container_definitions[c.name] = c
367
363
  end
368
364
 
369
- if task_definition.task_role_arn != @task_role_arn
365
+ if actual_definition.task_role_arn != @task_role_arn
370
366
  return true
371
367
  end
372
- if different_volumes?(task_definition.volumes)
368
+ if different_volumes?(actual_definition.volumes)
373
369
  return true
374
370
  end
375
- if definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) }
371
+ if desired_definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) }
376
372
  return true
377
373
  end
378
374
  !container_definitions.empty?
@@ -408,17 +404,19 @@ module Hako
408
404
  end
409
405
 
410
406
  # @param [Array<Hash>] definitions
411
- # @return [Aws::ECS::Types::TaskDefinition, Symbol]
407
+ # @return [Array<Boolean, Aws::ECS::Types::TaskDefinition>]
412
408
  def register_task_definition(definitions)
413
- if task_definition_changed?(@app_id, definitions)
414
- ecs_client.register_task_definition(
409
+ current_task_definition = ecs_client.describe_task_definition(task_definition: @app_id).task_definition
410
+ if task_definition_changed?(definitions, current_task_definition)
411
+ new_task_definition = ecs_client.register_task_definition(
415
412
  family: @app_id,
416
413
  task_role_arn: @task_role_arn,
417
414
  container_definitions: definitions,
418
415
  volumes: volumes_definition,
419
416
  ).task_definition
417
+ [true, new_task_definition]
420
418
  else
421
- :noop
419
+ [false, current_task_definition]
422
420
  end
423
421
  end
424
422
 
@@ -431,18 +429,20 @@ module Hako
431
429
  end
432
430
 
433
431
  # @param [Array<Hash>] definitions
434
- # @return [Aws::ECS::Types::TaskDefinition, Symbol]
432
+ # @return [Array<Boolean, Aws::ECS::Types::TaskDefinition]
435
433
  def register_task_definition_for_oneshot(definitions)
436
434
  family = "#{@app_id}-oneshot"
437
- if task_definition_changed?(family, definitions)
438
- ecs_client.register_task_definition(
439
- family: "#{@app_id}-oneshot",
435
+ current_task_definition = ecs_client.describe_task_definition(task_definition: family).task_definition
436
+ if task_definition_changed?(definitions, current_task_definition)
437
+ new_task_definition = ecs_client.register_task_definition(
438
+ family: family,
440
439
  task_role_arn: @task_role_arn,
441
440
  container_definitions: definitions,
442
441
  volumes: volumes_definition,
443
442
  ).task_definition
443
+ [true, new_task_definition]
444
444
  else
445
- :noop
445
+ [false, current_task_definition]
446
446
  end
447
447
  end
448
448
 
@@ -500,6 +500,7 @@ module Hako
500
500
  ],
501
501
  },
502
502
  count: 1,
503
+ placement_constraints: @placement_constraints,
503
504
  started_by: 'hako oneshot',
504
505
  )
505
506
  result.failures.each do |failure|
@@ -898,7 +899,7 @@ module Hako
898
899
  cmd << '--link' << link
899
900
  end
900
901
  definition.fetch(:port_mappings).each do |port_mapping|
901
- cmd << '--publish' << "#{port_mapping.fetch('host_port')}:#{port_mapping.fetch('container_port')}"
902
+ cmd << '--publish' << "#{port_mapping.fetch(:host_port)}:#{port_mapping.fetch(:container_port)}"
902
903
  end
903
904
  definition.fetch(:docker_labels).each do |key, val|
904
905
  if key != 'cc.wanko.hako.version'
data/lib/hako/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hako
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.2'
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.3.1
4
+ version: 1.3.2
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-16 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk