hako 0.20.1 → 0.20.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: a138ad34e8358e637424783db88022f2b3018fdd
4
- data.tar.gz: 26643b7c4701669d9014cc15e0c9efaa6c6d4911
3
+ metadata.gz: b994047cb6fcb14d8748fe5966480737e35d29ac
4
+ data.tar.gz: 71d27d9b3e3e36d2b623a73452d06e9ef12e36a5
5
5
  SHA512:
6
- metadata.gz: 6ac024fb63476147ae026c12af7a60af5677e7c2978c5d7a42051fccd34e6a09da751ead807072f4ddf3891271e69849ea33187b01da86a9d88abb89dc5f3daa
7
- data.tar.gz: 933b38fb37e3d364a835285903b470656e7fecbb6ea5d9dc7cb36807a93fe8350ec56e1243e142a4c1c54c2951adce03710c1216ed0a93f7f66860c06e5aa303
6
+ metadata.gz: bb8cdd9a3ed51cce575782d30811bd78858e4cde9f00d7cd56fe0ee66246e490e1d386c47a217457221339b31c98f8370154b7e05e9e3412b0538398d8e6c5b9
7
+ data.tar.gz: caa93254187ecec7f652a3d80a0d0b3cfbfac0b9e8079b86559e6db4b89503e5ea5b09612356de174f0891c40d4364e621ed159f4fdcfa274c36d2c43b419d7c
@@ -0,0 +1,16 @@
1
+ scheduler:
2
+ type: ecs
3
+ region: ap-northeast-1
4
+ cluster: eagletmt
5
+ desired_count: 1
6
+ app:
7
+ image: busybox
8
+ memory: 128
9
+ cpu: 256
10
+ command: ['echo', 'hello awslogs']
11
+ log_configuration:
12
+ log_driver: awslogs
13
+ options:
14
+ awslogs-group: my-logs
15
+ awslogs-region: ap-northeast-1
16
+ awslogs-stream-prefix: example
data/examples/hello.yml CHANGED
@@ -6,6 +6,9 @@ scheduler:
6
6
  task_role_arn: arn:aws:iam::012345678901:role/HelloRole
7
7
  # dynamic_port_mapping is enabled by default with no ELB option
8
8
  # dynamic_port_mapping: false
9
+ deployment_configuration:
10
+ maximum_percent: 200
11
+ minimum_healthy_percent: 50
9
12
  app:
10
13
  image: ryotarai/hello-sinatra
11
14
  memory: 128
@@ -63,6 +63,17 @@ module Hako
63
63
  end
64
64
  end
65
65
 
66
+ # @return [Hash, nil]
67
+ def log_configuration
68
+ if @definition.key?('log_configuration')
69
+ conf = @definition['log_configuration']
70
+ {
71
+ log_driver: conf.fetch('log_driver'),
72
+ options: conf.fetch('options'),
73
+ }
74
+ end
75
+ end
76
+
66
77
  private
67
78
 
68
79
  PROVIDERS_KEY = '$providers'
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ require 'hako/env_provider'
3
+ require 'yaml'
4
+
5
+ module Hako
6
+ module EnvProviders
7
+ class Yaml < EnvProvider
8
+ # @param [Pathname] root_path
9
+ # @param [Hash<String, Object>] options
10
+ def initialize(root_path, options)
11
+ unless options['path']
12
+ validation_error!('path must be set')
13
+ end
14
+
15
+ @yaml = YAML.load_file root_path.join(options['path'])
16
+
17
+ unless @yaml.is_a?(Hash)
18
+ validation_error!('Env yaml root must be Hash')
19
+ end
20
+
21
+ @options = options
22
+ end
23
+
24
+ # @param [Array<String>] variables
25
+ # @return [Hash<String, String>]
26
+ def ask(variables)
27
+ env = {}
28
+ read_from_yaml do |key, val|
29
+ if variables.include?(key)
30
+ env[key] = val
31
+ end
32
+ end
33
+ env
34
+ end
35
+
36
+ private
37
+
38
+ # @yieldparam [String] key
39
+ # @yieldparam [String] val
40
+ def read_from_yaml(&block)
41
+ flatten(@yaml).each(&block)
42
+ end
43
+
44
+ # @param [Object] obj
45
+ # @param [String] root
46
+ # @param [Hash<String,String>] acc
47
+ # @return [Hash<String, String>]
48
+ def flatten(obj, root = nil, acc = {})
49
+ case obj
50
+ when Array
51
+ ary_sep = @options.fetch('ary_sep', ',')
52
+ acc[root] = obj.join(ary_sep)
53
+ when Hash
54
+ obj.each do |key, value|
55
+ key_sep = @options.fetch('key_sep', '.')
56
+ new_root = [root, key].reject(&:nil?).join(key_sep)
57
+ flatten(value, new_root, acc)
58
+ end
59
+ else
60
+ acc[root] = obj.to_s
61
+ end
62
+
63
+ acc
64
+ end
65
+ end
66
+ end
67
+ end
@@ -35,9 +35,14 @@ module Hako
35
35
  if options.key?('autoscaling')
36
36
  @autoscaling = EcsAutoscaling.new(options.fetch('autoscaling'), dry_run: @dry_run)
37
37
  end
38
+ @autoscaling_group_for_oneshot = options.fetch('autoscaling_group_for_oneshot', nil)
39
+ @deployment_configuration = {}
40
+ %i[maximum_percent minimum_healthy_percent].each do |key|
41
+ @deployment_configuration[key] = options.dig('deployment_configuration', key.to_s)
42
+ end
43
+
38
44
  @started_at = nil
39
45
  @container_instance_arn = nil
40
- @autoscaling_group_for_oneshot = options.fetch('autoscaling_group_for_oneshot', nil)
41
46
  end
42
47
 
43
48
  # @param [Hash<String, Container>] containers
@@ -239,9 +244,9 @@ module Hako
239
244
  service = describe_service
240
245
  if service
241
246
  if @dry_run
242
- Hako.logger.info("ecs_client.update_service(cluster: #{@cluster}, service: #{@app_id}, desired_count: 0)")
247
+ Hako.logger.info("ecs_client.update_service(cluster: #{service.cluster_arn}, service: #{service.service_arn}, desired_count: 0)")
243
248
  else
244
- ecs_client.update_service(cluster: @cluster, service: @app_id, desired_count: 0)
249
+ ecs_client.update_service(cluster: service.cluster_arn, service: service.service_arn, desired_count: 0)
245
250
  Hako.logger.info("#{service.service_arn} is stopped")
246
251
  end
247
252
  else
@@ -453,6 +458,7 @@ module Hako
453
458
  command: container.command,
454
459
  volumes_from: container.volumes_from,
455
460
  user: container.user,
461
+ log_configuration: container.log_configuration,
456
462
  }
457
463
  end
458
464
 
@@ -580,6 +586,7 @@ module Hako
580
586
  task_definition: task_definition_arn,
581
587
  desired_count: @desired_count,
582
588
  role: @role,
589
+ deployment_configuration: @deployment_configuration,
583
590
  }
584
591
  if ecs_elb_client.find_or_create_load_balancer(front_port)
585
592
  params[:load_balancers] = [
@@ -593,6 +600,7 @@ module Hako
593
600
  service: @app_id,
594
601
  desired_count: @desired_count,
595
602
  task_definition: task_definition_arn,
603
+ deployment_configuration: @deployment_configuration,
596
604
  }
597
605
  if @autoscaling
598
606
  # Keep current desired_count if autoscaling is enabled
@@ -617,6 +625,11 @@ module Hako
617
625
  return true
618
626
  end
619
627
  end
628
+ params[:deployment_configuration].each do |key, val|
629
+ if val && val != service.deployment_configuration.public_send(key)
630
+ return true
631
+ end
632
+ end
620
633
  false
621
634
  end
622
635
 
@@ -7,7 +7,7 @@ module Hako
7
7
  @expected_container = expected_container
8
8
  end
9
9
 
10
- CONTAINER_KEYS = %i[image cpu memory memory_reservation links docker_labels user].freeze
10
+ CONTAINER_KEYS = %i[image cpu memory memory_reservation links docker_labels user log_configuration].freeze
11
11
  PORT_MAPPING_KEYS = %i[container_port host_port protocol].freeze
12
12
  ENVIRONMENT_KEYS = %i[name value].freeze
13
13
  MOUNT_POINT_KEYS = %i[source_volume container_path read_only].freeze
data/lib/hako/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hako
3
- VERSION = '0.20.1'
3
+ VERSION = '0.20.2'
4
4
  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: 0.20.1
4
+ version: 0.20.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: 2016-09-12 00:00:00.000000000 Z
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -116,6 +116,7 @@ files:
116
116
  - examples/front.yml
117
117
  - examples/hello-autoscaling-group.yml
118
118
  - examples/hello-autoscaling.yml
119
+ - examples/hello-awslogs-driver.yml
119
120
  - examples/hello-lb-v2.yml
120
121
  - examples/hello-lb.yml
121
122
  - examples/hello.env
@@ -133,6 +134,7 @@ files:
133
134
  - lib/hako/env_provider.rb
134
135
  - lib/hako/env_providers.rb
135
136
  - lib/hako/env_providers/file.rb
137
+ - lib/hako/env_providers/yaml.rb
136
138
  - lib/hako/error.rb
137
139
  - lib/hako/loader.rb
138
140
  - lib/hako/scheduler.rb