hako 1.8.4 → 1.9.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
- SHA1:
3
- metadata.gz: 70c493530e6b2a7355d402ae08d9305cbcdc5c89
4
- data.tar.gz: fce07c67ce4a4d0c438b4ea341ae29ac72ccae7d
2
+ SHA256:
3
+ metadata.gz: be60277c499933be1ac03eed32027844eb410bb92d52355984833f16d19ac882
4
+ data.tar.gz: f07f5c690efcc8c81a1610ff9077dcf36f21cb41eb6f6ff07b475083bfbb999d
5
5
  SHA512:
6
- metadata.gz: 2d175b26ce5af0c9bb6b23a1a7c91d61cc44794ee9add9a8efd6a8e9a2a0ee8f8ab21a2572a184632437b1e78e6f2962532628e06af8d9a9778fdb17ddf5784b
7
- data.tar.gz: 0fbfb30c8c28f6e42564765e8b49c81462729399706ba70fe8c60aaa7ac4202ae17703fad572712632f8f0842bc5e06561db50c42c04f4a52c5fb76125659c8a
6
+ metadata.gz: 17b332ddc9a4f4eca98938d7e5fec30898d6b50971f6700bb5e1717a0c211b88d97ed4b5dc9c24a4d75bb4fabc27d5d1ed374b3d51410305b8e184b5250b1a1c
7
+ data.tar.gz: 288283a14dbed0e30066da6b1a7d4fa6568ceda09a4272981304e6b421f91c2fce8d6b67fc535e8440cfccf51852babc71b803a8a21542ed48d2a84b59cb58e1
@@ -1,3 +1,9 @@
1
+ # 1.9.0 (2017-12-06)
2
+ ## New features
3
+ - Add support for awsvpc network mode
4
+ - Add support for Fargate
5
+ - See [examples/hello-fargate.yml](examples/hello-fargate.yml) and [examples/hello-fargate-batch.yml](examples/hello-fargate-batch.yml)
6
+
1
7
  # 1.8.4 (2017-11-24)
2
8
  ## Improvements
3
9
  - Support `linux_parameters` option
@@ -0,0 +1,31 @@
1
+ scheduler:
2
+ type: ecs
3
+ region: us-east-1
4
+ cluster: eagletmt
5
+ # Fargate
6
+ execution_role_arn: arn:aws:iam::012345678901:role/ecsTaskExecutionRole
7
+ cpu: '1024'
8
+ memory: '2048'
9
+ requires_compatibilities: ['FARGATE']
10
+ network_mode: awsvpc
11
+ launch_type: FARGATE
12
+ network_configuration:
13
+ awsvpc_configuration:
14
+ subnets:
15
+ - subnet-XXXXXXXX
16
+ security_groups: []
17
+ assign_public_ip: DISABLED
18
+
19
+ app:
20
+ image: ryotarai/hello-sinatra
21
+ cpu: 1024
22
+ memory: 256
23
+ memory_reservation: 128
24
+ log_configuration:
25
+ log_driver: awslogs
26
+ options:
27
+ awslogs-group: /ecs/hello-fargate-batch
28
+ awslogs-region: us-east-1
29
+ awslogs-stream-prefix: ecs
30
+ scripts:
31
+ - type: create_aws_cloud_watch_logs_log_group
@@ -0,0 +1,68 @@
1
+ scheduler:
2
+ type: ecs
3
+ region: us-east-1
4
+ cluster: eagletmt
5
+ desired_count: 1
6
+ task_role_arn: arn:aws:iam::012345678901:role/EcsDefault
7
+ elb_v2:
8
+ vpc_id: vpc-xxxxxxxx
9
+ health_check_path: /site/sha
10
+ listeners:
11
+ - port: 80
12
+ protocol: HTTP
13
+ - port: 443
14
+ protocol: HTTPS
15
+ certificate_arn: arn:aws:acm:us-east-1:012345678901:certificate/01234567-89ab-cdef-0123-456789abcdef
16
+ subnets:
17
+ - subnet-xxxxxxxx
18
+ - subnet-yyyyyyyy
19
+ security_groups:
20
+ - sg-xxxxxxxx
21
+ load_balancer_attributes:
22
+ access_logs.s3.enabled: 'true'
23
+ access_logs.s3.bucket: hako-access-logs
24
+ access_logs.s3.prefix: hako-hello-fargate
25
+ idle_timeout.timeout_seconds: '5'
26
+ target_group_attributes:
27
+ deregistration_delay.timeout_seconds: '20'
28
+ # Fargate
29
+ execution_role_arn: arn:aws:iam::012345678901:role/ecsTaskExecutionRole
30
+ cpu: '1024'
31
+ memory: '2048'
32
+ requires_compatibilities: ['FARGATE']
33
+ network_mode: awsvpc
34
+ launch_type: FARGATE
35
+ network_configuration:
36
+ awsvpc_configuration:
37
+ subnets:
38
+ - subnet-zzzzzzzz
39
+ - subnet-wwwwwwww
40
+ security_groups:
41
+ - sg-yyyyyyyy
42
+ - sg-zzzzzzzz
43
+ assign_public_ip: DISABLED
44
+ app:
45
+ image: ryotarai/hello-sinatra
46
+ cpu: 128
47
+ memory: 256
48
+ env:
49
+ PORT: '3000'
50
+ MESSAGE: 'Hello, Fargate'
51
+ log_configuration:
52
+ log_driver: awslogs
53
+ options:
54
+ awslogs-group: /ecs/hello-fargate
55
+ awslogs-region: us-east-1
56
+ awslogs-stream-prefix: ecs
57
+ additional_containers:
58
+ front:
59
+ image_tag: hako-nginx
60
+ log_configuration:
61
+ log_driver: awslogs
62
+ options:
63
+ awslogs-group: /ecs/hello-fargate
64
+ awslogs-region: us-east-1
65
+ awslogs-stream-prefix: ecs
66
+ scripts:
67
+ - <<: !include front.yml
68
+ backend_port: 3000
@@ -37,6 +37,11 @@ module Hako
37
37
  if @ecs_elb_options && @ecs_elb_v2_options
38
38
  validation_error!('Cannot specify both elb and elb_v2')
39
39
  end
40
+ @network_mode = options.fetch('network_mode', nil)
41
+ if @network_mode == 'awsvpc' && @ecs_elb_v2_options
42
+ # awsvpc network mode requires ELB target group with target_type=ip
43
+ @ecs_elb_v2_options['target_type'] = 'ip'
44
+ end
40
45
  @dynamic_port_mapping = options.fetch('dynamic_port_mapping', @ecs_elb_options.nil?)
41
46
  if options.key?('autoscaling')
42
47
  @autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), dry_run: @dry_run)
@@ -53,6 +58,24 @@ module Hako
53
58
  end
54
59
  @placement_constraints = options.fetch('placement_constraints', [])
55
60
  @placement_strategy = options.fetch('placement_strategy', [])
61
+ @execution_role_arn = options.fetch('execution_role_arn', nil)
62
+ @cpu = options.fetch('cpu', nil)
63
+ @memory = options.fetch('memory', nil)
64
+ @requires_compatibilities = options.fetch('requires_compatibilities', nil)
65
+ @launch_type = options.fetch('launch_type', nil)
66
+ if options.key?('network_configuration')
67
+ network_configuration = options.fetch('network_configuration')
68
+ if network_configuration.key?('awsvpc_configuration')
69
+ awsvpc_configuration = network_configuration.fetch('awsvpc_configuration')
70
+ @network_configuration = {
71
+ awsvpc_configuration: {
72
+ subnets: awsvpc_configuration.fetch('subnets'),
73
+ security_groups: awsvpc_configuration.fetch('security_groups', nil),
74
+ assign_public_ip: awsvpc_configuration.fetch('assign_public_ip', nil),
75
+ },
76
+ }
77
+ end
78
+ end
56
79
 
57
80
  @started_at = nil
58
81
  @container_instance_arn = nil
@@ -317,7 +340,10 @@ module Hako
317
340
 
318
341
  # @return [Fixnum]
319
342
  def determine_front_port
320
- if @dynamic_port_mapping
343
+ if @network_mode == 'awsvpc'
344
+ # When networkMode=awsvpc, the host ports and container ports in port mappings must match
345
+ return nil
346
+ elsif @dynamic_port_mapping
321
347
  return 0
322
348
  end
323
349
  if @dry_run
@@ -391,7 +417,26 @@ module Hako
391
417
  if desired_definitions.any? { |definition| different_definition?(definition, container_definitions.delete(definition[:name])) }
392
418
  return true
393
419
  end
394
- !container_definitions.empty?
420
+ unless container_definitions.empty?
421
+ return true
422
+ end
423
+ if actual_definition.cpu != @cpu
424
+ return true
425
+ end
426
+ if actual_definition.memory != @memory
427
+ return true
428
+ end
429
+ if actual_definition.network_mode != @network_mode
430
+ return true
431
+ end
432
+ if actual_definition.execution_role_arn != @execution_role_arn
433
+ return true
434
+ end
435
+ if actual_definition.requires_compatibilities != @requires_compatibilities
436
+ return true
437
+ end
438
+
439
+ false
395
440
  end
396
441
 
397
442
  # @param [Hash<String, Hash<String, String>>] actual_volumes
@@ -428,8 +473,13 @@ module Hako
428
473
  new_task_definition = ecs_client.register_task_definition(
429
474
  family: @app_id,
430
475
  task_role_arn: @task_role_arn,
476
+ execution_role_arn: @execution_role_arn,
477
+ network_mode: @network_mode,
431
478
  container_definitions: definitions,
432
479
  volumes: volumes_definition,
480
+ requires_compatibilities: @requires_compatibilities,
481
+ cpu: @cpu,
482
+ memory: @memory,
433
483
  ).task_definition
434
484
  [true, new_task_definition]
435
485
  else
@@ -456,8 +506,13 @@ module Hako
456
506
  new_task_definition = ecs_client.register_task_definition(
457
507
  family: family,
458
508
  task_role_arn: @task_role_arn,
509
+ execution_role_arn: @execution_role_arn,
510
+ network_mode: @network_mode,
459
511
  container_definitions: definitions,
460
512
  volumes: volumes_definition,
513
+ requires_compatibilities: @requires_compatibilities,
514
+ cpu: @cpu,
515
+ memory: @memory,
461
516
  ).task_definition
462
517
  return [true, new_task_definition]
463
518
  else
@@ -543,6 +598,9 @@ module Hako
543
598
  count: 1,
544
599
  placement_constraints: @placement_constraints,
545
600
  started_by: 'hako oneshot',
601
+ launch_type: @launch_type,
602
+ platform_version: @platform_version,
603
+ network_configuration: @network_configuration,
546
604
  )
547
605
  result.failures.each do |failure|
548
606
  Hako.logger.error("#{failure.arn} #{failure.reason}")
@@ -715,6 +773,8 @@ module Hako
715
773
  desired_count: @desired_count,
716
774
  task_definition: task_definition_arn,
717
775
  deployment_configuration: @deployment_configuration,
776
+ platform_version: @platform_version,
777
+ network_configuration: @network_configuration,
718
778
  }
719
779
  if @autoscaling
720
780
  # Keep current desired_count if autoscaling is enabled
@@ -741,6 +801,9 @@ module Hako
741
801
  deployment_configuration: @deployment_configuration,
742
802
  placement_constraints: @placement_constraints,
743
803
  placement_strategy: @placement_strategy,
804
+ launch_type: @launch_type,
805
+ platform_version: @platform_version,
806
+ network_configuration: @network_configuration,
744
807
  }
745
808
  if ecs_elb_client.find_or_create_load_balancer(front_port)
746
809
  ecs_elb_client.modify_attributes
@@ -71,6 +71,7 @@ module Hako
71
71
  protocol: 'HTTP',
72
72
  vpc_id: @elb_v2_config.fetch('vpc_id'),
73
73
  health_check_path: @elb_v2_config.fetch('health_check_path', nil),
74
+ target_type: @elb_v2_config.fetch('target_type', nil),
74
75
  ).target_groups[0]
75
76
  Hako.logger.info "Created target group #{target_group.target_group_arn}"
76
77
  end
@@ -23,6 +23,8 @@ module Hako
23
23
  struct.member(:desired_count, Schema::Integer.new)
24
24
  struct.member(:task_definition, Schema::String.new)
25
25
  struct.member(:deployment_configuration, Schema::WithDefault.new(deployment_configuration_schema, default_configuration))
26
+ struct.member(:platform_version, Schema::String.new)
27
+ struct.member(:network_configuration, Schema::Nullable.new(network_configuration_schema))
26
28
  end
27
29
  end
28
30
 
@@ -33,6 +35,20 @@ module Hako
33
35
  end
34
36
  end
35
37
 
38
+ def network_configuration_schema
39
+ Schema::Structure.new.tap do |struct|
40
+ struct.member(:awsvpc_configuration, awsvpc_configuration_schema)
41
+ end
42
+ end
43
+
44
+ def awsvpc_configuration_schema
45
+ Schema::Structure.new.tap do |struct|
46
+ struct.member(:subnets, Schema::UnorderedArray.new(Schema::String.new))
47
+ struct.member(:security_groups, Schema::UnorderedArray.new(Schema::String.new))
48
+ struct.member(:assign_public_ip, Schema::String.new)
49
+ end
50
+ end
51
+
36
52
  def default_configuration
37
53
  {
38
54
  maximum_percent: 200,
@@ -34,7 +34,6 @@ module Hako
34
34
  'S3_CONFIG_BUCKET' => @s3.bucket,
35
35
  'S3_CONFIG_KEY' => @s3.key(@app.id),
36
36
  )
37
- front.links << link_app
38
37
  end
39
38
 
40
39
  # @param [Hash<String, Container>] containers
@@ -42,8 +41,13 @@ module Hako
42
41
  # @return [nil]
43
42
  def deploy_started(containers, front_port)
44
43
  front = containers.fetch('front')
44
+ if front_port.nil?
45
+ # Links and extraHosts are not supported when networkMode=awsvpc (i.e., --network=container).
46
+ else
47
+ front.links << link_app
48
+ end
45
49
  front.definition['port_mappings'] << port_mapping(front_port)
46
- upload_config(generate_config)
50
+ upload_config(generate_config(backend_host: front_port.nil? ? 'localhost' : 'backend'))
47
51
  Hako.logger.info "Uploaded front configuration to s3://#{@s3.bucket}/#{@s3.key(@app.id)}"
48
52
  end
49
53
 
@@ -67,12 +71,12 @@ module Hako
67
71
  # @param [Fixnum] front_port
68
72
  # @return [Hash]
69
73
  def port_mapping(front_port)
70
- { 'container_port' => 80, 'host_port' => front_port, 'protocol' => 'tcp' }
74
+ { 'container_port' => 80, 'host_port' => front_port || 80, 'protocol' => 'tcp' }
71
75
  end
72
76
 
73
77
  # @return [String]
74
- def generate_config
75
- Generator.new(@options).render
78
+ def generate_config(backend_host:)
79
+ Generator.new(@options, backend_host: backend_host).render
76
80
  end
77
81
 
78
82
  # @return [Hash]
@@ -95,8 +99,9 @@ module Hako
95
99
 
96
100
  class Generator
97
101
  # @param [Hash] options
98
- def initialize(options)
102
+ def initialize(options, backend_host:)
99
103
  @options = options
104
+ @backend_host = backend_host
100
105
  @backend_port = options.fetch('backend_port')
101
106
  end
102
107
 
@@ -109,7 +114,7 @@ module Hako
109
114
 
110
115
  # @return [String]
111
116
  def listen_spec
112
- "backend:#{@backend_port}"
117
+ "#{@backend_host}:#{@backend_port}"
113
118
  end
114
119
 
115
120
  # @return [String]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hako
4
- VERSION = '1.8.4'
4
+ VERSION = '1.9.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.8.4
4
+ version: 1.9.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-11-24 00:00:00.000000000 Z
11
+ date: 2017-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling
@@ -276,6 +276,8 @@ files:
276
276
  - examples/hello-autoscaling.yml
277
277
  - examples/hello-awslogs-driver.yml
278
278
  - examples/hello-cap-add-app.yml
279
+ - examples/hello-fargate-batch.yml
280
+ - examples/hello-fargate.yml
279
281
  - examples/hello-lb-v2.yml
280
282
  - examples/hello-lb.yml
281
283
  - examples/hello-nofront.yml
@@ -346,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
346
348
  version: '0'
347
349
  requirements: []
348
350
  rubyforge_project:
349
- rubygems_version: 2.6.11
351
+ rubygems_version: 2.7.3
350
352
  signing_key:
351
353
  specification_version: 4
352
354
  summary: Deploy Docker container