hako 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eeaab8400e80caccbf550eed190e25ca59d729f04f450c0fa3c34596036a0af
4
- data.tar.gz: '039cc2afb69aacceaa40976bb74dca8be034dc4e4780423c4a5d30040f17775f'
3
+ metadata.gz: 8da04c31fe7625fb6d07dc567a54ecd07100fc84b434bd390137ab5801a41bdb
4
+ data.tar.gz: aae515841f829f80332241e8187973a2f38fa79ae51ce217a92a2cac911970e2
5
5
  SHA512:
6
- metadata.gz: 84b31ceebf0c3bc2cc3262b8b977d092269b527c6d33c1082ee01715514e61c8e439a1c78390e96590cf5d8777a44e120d631bd269269c3219c0b7818109f5d2
7
- data.tar.gz: 136f00906ce0b1e94a67d4fe6a0919efecae7744a402fba58f0cbd4ff86f9dd6f8187a6bdd68ca52002f000c998efd87404dcf5536918360fac047a5d900db47
6
+ metadata.gz: 9383d706cc18370a6878d3206ce526cd0c99ec93c636fbc0c15ab8bb34360537785f9e97a96a8298c85cdd595d18b7af351cf323c57b4a0371de30662f18bbea
7
+ data.tar.gz: 12bb5b4c2ed31c2dfdf6453a2a188ab3f046833aa26f26072a273d17eac95b2aff72dfe92d130bffcc9d55396738d1c6defd7a024ea5ee23f3ea9ca0f87930f2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 2.9.0 (2019-04-03)
2
+ ## New features
3
+ - Add `remove_starting` method to Hako::Script which is called when `hako remove` starts
4
+ - Support sharing load balancers
5
+ - When `elb_v2` field has `load_balancer_name` but doesn't have `target_group_name`, hako will manage only the target group and doesn't touch the load balancer.
6
+ - This is useful when one load balancer is shared with multiple target groups and some of them is deployed by hako.
7
+ - See [examples/hello-shared-alb.jsonnet](examples/hello-shared-alb.jsonnet)
8
+
9
+ ## Changes
10
+ - When `load_balancer_name` is specified and `target_group_name` is not, the default `target_group_name` is changed from `load_balancer_name` to `hako-#{app_id}`.
11
+ - If you use `load_balancer_name` field only, you must specify `target_group_name` field too.
12
+
1
13
  # 2.8.0 (2019-03-17)
2
14
  ## New features
3
15
  - Add `deploy_failed` method to Hako::Script which is called when `hako deploy` fails
@@ -0,0 +1,50 @@
1
+ {
2
+ scheduler: {
3
+ type: 'ecs',
4
+ region: 'ap-northeast-1',
5
+ cluster: 'eagletmt',
6
+ desired_count: 2,
7
+ role: 'ecsServiceRole',
8
+ elb_v2: {
9
+ // Use existing load balancer
10
+ load_balancer_name: 'hello-shared-alb',
11
+ // VPC id where the target group is located
12
+ vpc_id: 'vpc-WWWWWWWW',
13
+ // Health check path of the target group
14
+ health_check_path: '/site/sha',
15
+ target_group_attributes: {
16
+ // http://docs.aws.amazon.com/en_us/elasticloadbalancing/latest/application/load-balancer-target-groups.html#target-group-attributes
17
+ 'deregistration_delay.timeout_seconds': '20',
18
+ },
19
+ },
20
+ },
21
+ app: {
22
+ image: 'ryotarai/hello-sinatra',
23
+ memory: 128,
24
+ cpu: 256,
25
+ env: {
26
+ PORT: '3000',
27
+ },
28
+ secrets: [{
29
+ name: 'MESSAGE',
30
+ value_from: 'arn:aws:ssm:ap-northeast-1:012345678901:parameter/hako/hello-shared-alb/secret-message',
31
+ }],
32
+ },
33
+ sidecars: {
34
+ front: {
35
+ image_tag: 'hako-nginx',
36
+ memory: 32,
37
+ cpu: 32,
38
+ },
39
+ },
40
+ scripts: [
41
+ (import 'front.libsonnet') + {
42
+ backend_port: 3000,
43
+ locations: {
44
+ '/': {
45
+ allow_only_from: ['10.0.0.0/24'],
46
+ },
47
+ },
48
+ },
49
+ ],
50
+ }
@@ -70,6 +70,7 @@ module Hako
70
70
  # @return [nil]
71
71
  def remove(dry_run:)
72
72
  scripts = @app.definition.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
73
+ scripts.each(&:remove_starting)
73
74
  load_scheduler(@app.definition['scheduler'], scripts, dry_run: dry_run).remove
74
75
  scripts.each(&:after_remove)
75
76
  end
@@ -103,6 +103,7 @@ module Hako
103
103
  validation_error!('desired_count must be set')
104
104
  end
105
105
  front_port = determine_front_port
106
+ ecs_elb_client.find_or_create_load_balancer(front_port)
106
107
  @scripts.each { |script| script.deploy_started(containers, front_port) }
107
108
  definitions = create_definitions(containers)
108
109
 
@@ -886,7 +887,6 @@ module Hako
886
887
  params[:desired_count] = 0
887
888
  end
888
889
  if ecs_elb_client.find_or_create_load_balancer(front_port)
889
- ecs_elb_client.modify_attributes
890
890
  params[:load_balancers] = [ecs_elb_client.load_balancer_params_for_service]
891
891
  end
892
892
  if @service_discovery
@@ -51,7 +51,7 @@ module Hako
51
51
  end
52
52
 
53
53
  load_balancer = describe_load_balancer
54
- unless load_balancer
54
+ if !load_balancer_given? && !load_balancer
55
55
  tags = @elb_v2_config.fetch('tags', {}).map { |k, v| { key: k, value: v.to_s } }
56
56
 
57
57
  elb_type = @elb_v2_config.fetch('type', nil)
@@ -78,7 +78,7 @@ module Hako
78
78
  end
79
79
 
80
80
  target_group = describe_target_group
81
- unless target_group
81
+ if !target_group_given? && !target_group
82
82
  elb_type = @elb_v2_config.fetch('type', nil)
83
83
  target_group = if elb_type == 'network'
84
84
  elb_client.create_target_group(
@@ -102,23 +102,25 @@ module Hako
102
102
  Hako.logger.info "Created target group #{target_group.target_group_arn}"
103
103
  end
104
104
 
105
- listener_ports = elb_client.describe_listeners(load_balancer_arn: load_balancer.load_balancer_arn).flat_map { |page| page.listeners.map(&:port) }
106
- @elb_v2_config.fetch('listeners').each do |l|
107
- params = {
108
- load_balancer_arn: load_balancer.load_balancer_arn,
109
- protocol: l.fetch('protocol'),
110
- port: l.fetch('port'),
111
- ssl_policy: l['ssl_policy'],
112
- default_actions: [{ type: 'forward', target_group_arn: target_group.target_group_arn }],
113
- }
114
- certificate_arn = l.fetch('certificate_arn', nil)
115
- if certificate_arn
116
- params[:certificates] = [{ certificate_arn: certificate_arn }]
117
- end
105
+ unless load_balancer_given?
106
+ listener_ports = elb_client.describe_listeners(load_balancer_arn: load_balancer.load_balancer_arn).flat_map { |page| page.listeners.map(&:port) }
107
+ @elb_v2_config.fetch('listeners').each do |l|
108
+ params = {
109
+ load_balancer_arn: load_balancer.load_balancer_arn,
110
+ protocol: l.fetch('protocol'),
111
+ port: l.fetch('port'),
112
+ ssl_policy: l['ssl_policy'],
113
+ default_actions: [{ type: 'forward', target_group_arn: target_group.target_group_arn }],
114
+ }
115
+ certificate_arn = l.fetch('certificate_arn', nil)
116
+ if certificate_arn
117
+ params[:certificates] = [{ certificate_arn: certificate_arn }]
118
+ end
118
119
 
119
- unless listener_ports.include?(params[:port])
120
- listener = elb_client.create_listener(params).listeners[0]
121
- Hako.logger.info("Created listener #{listener.listener_arn}")
120
+ unless listener_ports.include?(params[:port])
121
+ listener = elb_client.create_listener(params).listeners[0]
122
+ Hako.logger.info("Created listener #{listener.listener_arn}")
123
+ end
122
124
  end
123
125
  end
124
126
 
@@ -131,58 +133,63 @@ module Hako
131
133
  return nil
132
134
  end
133
135
 
134
- load_balancer = describe_load_balancer
135
- subnets = @elb_v2_config.fetch('subnets').sort
136
- if load_balancer && subnets != load_balancer.availability_zones.map(&:subnet_id).sort
137
- if @dry_run
138
- Hako.logger.info("elb_client.set_subnets(load_balancer_arn: #{load_balancer.load_balancer_arn}, subnets: #{subnets}) (dry-run)")
139
- else
140
- Hako.logger.info("Updating ELBv2 subnets to #{subnets}")
141
- elb_client.set_subnets(load_balancer_arn: load_balancer.load_balancer_arn, subnets: subnets)
136
+ unless load_balancer_given?
137
+ load_balancer = describe_load_balancer
138
+ subnets = @elb_v2_config.fetch('subnets').sort
139
+ if load_balancer && subnets != load_balancer.availability_zones.map(&:subnet_id).sort
140
+ if @dry_run
141
+ Hako.logger.info("elb_client.set_subnets(load_balancer_arn: #{load_balancer.load_balancer_arn}, subnets: #{subnets}) (dry-run)")
142
+ else
143
+ Hako.logger.info("Updating ELBv2 subnets to #{subnets}")
144
+ elb_client.set_subnets(load_balancer_arn: load_balancer.load_balancer_arn, subnets: subnets)
145
+ end
142
146
  end
143
- end
144
147
 
145
- new_listeners = @elb_v2_config.fetch('listeners')
146
- if load_balancer
147
- current_listeners = elb_client.describe_listeners(load_balancer_arn: load_balancer.load_balancer_arn).listeners
148
- new_listeners.each do |new_listener|
149
- current_listener = current_listeners.find { |l| l.port == new_listener['port'] }
150
- if current_listener && new_listener['ssl_policy'] && new_listener['ssl_policy'] != current_listener.ssl_policy
151
- if @dry_run
152
- Hako.logger.info("elb_client.modify_listener(listener_arn: #{current_listener.listener_arn}, ssl_policy: #{new_listener['ssl_policy']}) (dry-run)")
153
- else
154
- Hako.logger.info("Updating ELBv2 listener #{new_listener['port']} ssl_policy to #{new_listener['ssl_policy']}")
155
- elb_client.modify_listener(listener_arn: current_listener.listener_arn, ssl_policy: new_listener['ssl_policy'])
148
+ new_listeners = @elb_v2_config.fetch('listeners')
149
+ if load_balancer
150
+ current_listeners = elb_client.describe_listeners(load_balancer_arn: load_balancer.load_balancer_arn).listeners
151
+ new_listeners.each do |new_listener|
152
+ current_listener = current_listeners.find { |l| l.port == new_listener['port'] }
153
+ if current_listener && new_listener['ssl_policy'] && new_listener['ssl_policy'] != current_listener.ssl_policy
154
+ if @dry_run
155
+ Hako.logger.info("elb_client.modify_listener(listener_arn: #{current_listener.listener_arn}, ssl_policy: #{new_listener['ssl_policy']}) (dry-run)")
156
+ else
157
+ Hako.logger.info("Updating ELBv2 listener #{new_listener['port']} ssl_policy to #{new_listener['ssl_policy']}")
158
+ elb_client.modify_listener(listener_arn: current_listener.listener_arn, ssl_policy: new_listener['ssl_policy'])
159
+ end
156
160
  end
157
161
  end
158
162
  end
159
- end
160
163
 
161
- if @elb_v2_config.key?('load_balancer_attributes')
162
- attributes = @elb_v2_config.fetch('load_balancer_attributes').map { |key, value| { key: key, value: value } }
163
- if @dry_run
164
- if load_balancer
165
- Hako.logger.info("elb_client.modify_load_balancer_attributes(load_balancer_arn: #{load_balancer.load_balancer_arn}, attributes: #{attributes.inspect}) (dry-run)")
164
+ if @elb_v2_config.key?('load_balancer_attributes')
165
+ attributes = @elb_v2_config.fetch('load_balancer_attributes').map { |key, value| { key: key, value: value } }
166
+ if @dry_run
167
+ if load_balancer
168
+ Hako.logger.info("elb_client.modify_load_balancer_attributes(load_balancer_arn: #{load_balancer.load_balancer_arn}, attributes: #{attributes.inspect}) (dry-run)")
169
+ else
170
+ Hako.logger.info("elb_client.modify_load_balancer_attributes(load_balancer_arn: unknown, attributes: #{attributes.inspect}) (dry-run)")
171
+ end
166
172
  else
167
- Hako.logger.info("elb_client.modify_load_balancer_attributes(load_balancer_arn: unknown, attributes: #{attributes.inspect}) (dry-run)")
173
+ Hako.logger.info("Updating ELBv2 attributes to #{attributes.inspect}")
174
+ elb_client.modify_load_balancer_attributes(load_balancer_arn: load_balancer.load_balancer_arn, attributes: attributes)
168
175
  end
169
- else
170
- Hako.logger.info("Updating ELBv2 attributes to #{attributes.inspect}")
171
- elb_client.modify_load_balancer_attributes(load_balancer_arn: load_balancer.load_balancer_arn, attributes: attributes)
172
176
  end
173
177
  end
174
- if @elb_v2_config.key?('target_group_attributes')
175
- target_group = describe_target_group
176
- attributes = @elb_v2_config.fetch('target_group_attributes').map { |key, value| { key: key, value: value } }
177
- if @dry_run
178
- if target_group
179
- Hako.logger.info("elb_client.modify_target_group_attributes(target_group_arn: #{target_group.target_group_arn}, attributes: #{attributes.inspect}) (dry-run)")
178
+
179
+ unless target_group_given?
180
+ if @elb_v2_config.key?('target_group_attributes')
181
+ target_group = describe_target_group
182
+ attributes = @elb_v2_config.fetch('target_group_attributes').map { |key, value| { key: key, value: value } }
183
+ if @dry_run
184
+ if target_group
185
+ Hako.logger.info("elb_client.modify_target_group_attributes(target_group_arn: #{target_group.target_group_arn}, attributes: #{attributes.inspect}) (dry-run)")
186
+ else
187
+ Hako.logger.info("elb_client.modify_target_group_attributes(target_group_arn: unknown, attributes: #{attributes.inspect}) (dry-run)")
188
+ end
180
189
  else
181
- Hako.logger.info("elb_client.modify_target_group_attributes(target_group_arn: unknown, attributes: #{attributes.inspect}) (dry-run)")
190
+ Hako.logger.info("Updating target group attributes to #{attributes.inspect}")
191
+ elb_client.modify_target_group_attributes(target_group_arn: target_group.target_group_arn, attributes: attributes)
182
192
  end
183
- else
184
- Hako.logger.info("Updating target group attributes to #{attributes.inspect}")
185
- elb_client.modify_target_group_attributes(target_group_arn: target_group.target_group_arn, attributes: attributes)
186
193
  end
187
194
  end
188
195
  nil
@@ -194,39 +201,43 @@ module Hako
194
201
  return false
195
202
  end
196
203
 
197
- load_balancer = describe_load_balancer
198
- if load_balancer
199
- if @dry_run
200
- Hako.logger.info("elb_client.delete_load_balancer(load_balancer_arn: #{load_balancer.load_balancer_arn})")
204
+ unless load_balancer_given?
205
+ load_balancer = describe_load_balancer
206
+ if load_balancer
207
+ if @dry_run
208
+ Hako.logger.info("elb_client.delete_load_balancer(load_balancer_arn: #{load_balancer.load_balancer_arn})")
209
+ else
210
+ elb_client.delete_load_balancer(load_balancer_arn: load_balancer.load_balancer_arn)
211
+ Hako.logger.info "Deleted ELBv2 #{load_balancer.load_balancer_arn}"
212
+ end
201
213
  else
202
- elb_client.delete_load_balancer(load_balancer_arn: load_balancer.load_balancer_arn)
203
- Hako.logger.info "Deleted ELBv2 #{load_balancer.load_balancer_arn}"
214
+ Hako.logger.info "ELBv2 #{elb_name} doesn't exist"
204
215
  end
205
- else
206
- Hako.logger.info "ELBv2 #{elb_name} doesn't exist"
207
216
  end
208
217
 
209
- target_group = describe_target_group
210
- if target_group
211
- if @dry_run
212
- Hako.logger.info("elb_client.delete_target_group(target_group_arn: #{target_group.target_group_arn})")
213
- else
214
- deleted = false
215
- 30.times do
216
- begin
217
- elb_client.delete_target_group(target_group_arn: target_group.target_group_arn)
218
- deleted = true
219
- break
220
- rescue Aws::ElasticLoadBalancingV2::Errors::ResourceInUse => e
221
- Hako.logger.warn("#{e.class}: #{e.message}")
218
+ unless target_group_given?
219
+ target_group = describe_target_group
220
+ if target_group
221
+ if @dry_run
222
+ Hako.logger.info("elb_client.delete_target_group(target_group_arn: #{target_group.target_group_arn})")
223
+ else
224
+ deleted = false
225
+ 30.times do
226
+ begin
227
+ elb_client.delete_target_group(target_group_arn: target_group.target_group_arn)
228
+ deleted = true
229
+ break
230
+ rescue Aws::ElasticLoadBalancingV2::Errors::ResourceInUse => e
231
+ Hako.logger.warn("#{e.class}: #{e.message}")
232
+ end
233
+ sleep 1
234
+ end
235
+ unless deleted
236
+ raise Error.new("Cannot delete target group #{target_group.target_group_arn}")
222
237
  end
223
- sleep 1
224
- end
225
- unless deleted
226
- raise Error.new("Cannot delete target group #{target_group.target_group_arn}")
227
- end
228
238
 
229
- Hako.logger.info "Deleted target group #{target_group.target_group_arn}"
239
+ Hako.logger.info "Deleted target group #{target_group.target_group_arn}"
240
+ end
230
241
  end
231
242
  end
232
243
  end
@@ -236,9 +247,19 @@ module Hako
236
247
  @elb_v2_config.fetch('load_balancer_name', "hako-#{@app_id}")
237
248
  end
238
249
 
250
+ # @return [Boolean]
251
+ def load_balancer_given?
252
+ @elb_v2_config.key?('load_balancer_name')
253
+ end
254
+
239
255
  # @return [String]
240
256
  def target_group_name
241
- @elb_v2_config.fetch('target_group_name', elb_name)
257
+ @elb_v2_config.fetch('target_group_name', "hako-#{@app_id}")
258
+ end
259
+
260
+ # @return [Boolean]
261
+ def target_group_given?
262
+ @elb_v2_config.key?('target_group_name')
242
263
  end
243
264
 
244
265
  # @return [Hash]
data/lib/hako/script.rb CHANGED
@@ -44,6 +44,8 @@ module Hako
44
44
  # @param [Hash<String, Container>] _containers
45
45
  def oneshot_finished(_containers); end
46
46
 
47
+ def remove_starting; end
48
+
47
49
  def after_remove; end
48
50
 
49
51
  private
data/lib/hako/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hako
4
- VERSION = '2.8.0'
4
+ VERSION = '2.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: 2.8.0
4
+ version: 2.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: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-applicationautoscaling
@@ -327,6 +327,7 @@ files:
327
327
  - examples/hello-nofront.jsonnet
328
328
  - examples/hello-privileged-app.jsonnet
329
329
  - examples/hello-service-discovery.jsonnet
330
+ - examples/hello-shared-alb.jsonnet
330
331
  - examples/hello.env
331
332
  - examples/hello.jsonnet
332
333
  - examples/put-ecs-container-status-to-s3/index.js