hako 0.7.4 → 0.8.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 +4 -4
- data/lib/hako.rb +3 -1
- data/lib/hako/cli.rb +25 -1
- data/lib/hako/commander.rb +12 -4
- data/lib/hako/schedulers/ecs.rb +55 -45
- data/lib/hako/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09a67f10cb41c44240b92e06db1fe5f13184e78a
|
4
|
+
data.tar.gz: 12debcaa9ddb9719d8b41ce5fb0511957918dcd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94cc6eba550cde280f0e4f234d6dc4f9147e7a2fd7677edc25e7febd640688f462e127e103dc7139eb582b4a88bae8a87cf4c254f39c808db3ccdce99489e3da
|
7
|
+
data.tar.gz: 178293b2984bf77e788f07793a748c5688e1b2dcc7570d9614662cbcb0664b8c7e44bd629794872bdbcdf33f10a1aeb76da13eff41c76b8545b06b97455f8e7c
|
data/lib/hako.rb
CHANGED
data/lib/hako/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'hako'
|
2
3
|
require 'thor'
|
3
4
|
|
4
5
|
module Hako
|
@@ -7,18 +8,31 @@ module Hako
|
|
7
8
|
option :force, aliases: %w[-f], type: :boolean, default: false, desc: 'Run deployment even if nothing is changed'
|
8
9
|
option :tag, aliases: %w[-t], type: :string, default: 'latest', desc: 'Specify tag (default: latest)'
|
9
10
|
option :dry_run, aliases: %w[-n], type: :boolean, default: false, desc: 'Enable dry-run mode'
|
11
|
+
option :verbose, aliases: %w[-v], type: :boolean, default: false, desc: 'Enable verbose logging'
|
10
12
|
def deploy(yaml_path)
|
11
13
|
require 'hako/application'
|
12
14
|
require 'hako/commander'
|
15
|
+
|
16
|
+
if options[:verbose]
|
17
|
+
Hako.logger.level = Logger::DEBUG
|
18
|
+
end
|
19
|
+
|
13
20
|
Commander.new(Application.new(yaml_path)).deploy(force: options[:force], tag: options[:tag], dry_run: options[:dry_run])
|
14
21
|
end
|
15
22
|
|
16
23
|
desc 'oneshot FILE COMMAND ARG...', 'Run oneshot task'
|
17
24
|
option :tag, aliases: %w[-t], type: :string, default: 'latest', desc: 'Specify tag (default: latest)'
|
25
|
+
option :containers, aliases: %w[-c], type: :string, default: '', banner: 'NAME1,NAME2', desc: 'Comma-separated additional container names to start with the app container (default: "")'
|
26
|
+
option :verbose, aliases: %w[-v], type: :boolean, default: false, desc: 'Enable verbose logging'
|
18
27
|
def oneshot(yaml_path, command, *args)
|
19
28
|
require 'hako/application'
|
20
29
|
require 'hako/commander'
|
21
|
-
|
30
|
+
|
31
|
+
if options[:verbose]
|
32
|
+
Hako.logger.level = Logger::DEBUG
|
33
|
+
end
|
34
|
+
|
35
|
+
Commander.new(Application.new(yaml_path)).oneshot([command, *args], tag: options[:tag], containers: options[:containers].split(','))
|
22
36
|
end
|
23
37
|
|
24
38
|
desc 'show-yaml FILE', 'Show expanded YAML'
|
@@ -40,5 +54,15 @@ module Hako
|
|
40
54
|
require 'hako/commander'
|
41
55
|
Commander.new(Application.new(yaml_path)).remove
|
42
56
|
end
|
57
|
+
|
58
|
+
desc 'version', 'Show version'
|
59
|
+
option :numeric, type: :boolean, default: false, desc: 'Show numeric only'
|
60
|
+
def version
|
61
|
+
if options[:numeric]
|
62
|
+
say VERSION
|
63
|
+
else
|
64
|
+
say "hako v#{VERSION}"
|
65
|
+
end
|
66
|
+
end
|
43
67
|
end
|
44
68
|
end
|
data/lib/hako/commander.rb
CHANGED
@@ -24,10 +24,10 @@ module Hako
|
|
24
24
|
scripts.each { |script| script.after_deploy(containers) }
|
25
25
|
end
|
26
26
|
|
27
|
-
def oneshot(commands, tag:
|
28
|
-
|
27
|
+
def oneshot(commands, tag:, containers:)
|
28
|
+
containers = load_containers(tag, dry_run: false, with: containers)
|
29
29
|
scheduler = load_scheduler(@app.yaml['scheduler'])
|
30
|
-
exit scheduler.oneshot(
|
30
|
+
exit scheduler.oneshot(containers, commands)
|
31
31
|
end
|
32
32
|
|
33
33
|
def status
|
@@ -42,7 +42,7 @@ module Hako
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
def load_containers(tag, dry_run:)
|
45
|
+
def load_containers(tag, dry_run:, with: nil)
|
46
46
|
app = AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: dry_run)
|
47
47
|
front = load_front(@app.yaml['front'], dry_run: dry_run)
|
48
48
|
|
@@ -50,6 +50,14 @@ module Hako
|
|
50
50
|
@app.yaml.fetch('additional_containers', {}).each do |name, container|
|
51
51
|
containers[name] = Container.new(@app, container, dry_run: dry_run)
|
52
52
|
end
|
53
|
+
if with
|
54
|
+
keys = ['app'] + with
|
55
|
+
containers.keys.each do |key|
|
56
|
+
unless keys.include?(key)
|
57
|
+
containers.delete(key)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
53
61
|
containers
|
54
62
|
end
|
55
63
|
|
data/lib/hako/schedulers/ecs.rb
CHANGED
@@ -42,7 +42,7 @@ module Hako
|
|
42
42
|
else
|
43
43
|
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
44
44
|
upload_front_config(@app_id, front, app.port)
|
45
|
-
Hako.logger.
|
45
|
+
Hako.logger.debug "Uploaded front configuration to s3://#{front.s3.bucket}/#{front.s3.key(@app_id)}"
|
46
46
|
end
|
47
47
|
service = create_or_update_service(task_definition.task_definition_arn, front_port)
|
48
48
|
if service == :noop
|
@@ -55,10 +55,19 @@ module Hako
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def oneshot(
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def oneshot(containers, commands)
|
59
|
+
definitions = create_definitions(containers, -1)
|
60
|
+
definitions.each do |definition|
|
61
|
+
definition.delete(:essential)
|
62
|
+
end
|
63
|
+
task_definition = register_task_definition_for_oneshot(definitions)
|
64
|
+
if task_definition == :noop
|
65
|
+
Hako.logger.info "Task definition isn't changed"
|
66
|
+
task_definition = @ecs.describe_task_definition(task_definition: "#{@app_id}-oneshot").task_definition
|
67
|
+
else
|
68
|
+
Hako.logger.info "Registered task definition: #{task_definition.task_definition_arn}"
|
69
|
+
end
|
70
|
+
task = run_task(task_definition, commands)
|
62
71
|
Hako.logger.info "Started task: #{task.task_arn}"
|
63
72
|
exit_code = wait_for_task(task)
|
64
73
|
Hako.logger.info 'Oneshot task finished'
|
@@ -152,24 +161,28 @@ module Hako
|
|
152
161
|
if service
|
153
162
|
find_front_port(service)
|
154
163
|
else
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
+
new_front_port
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def new_front_port
|
169
|
+
max_port = -1
|
170
|
+
@ecs.list_services(cluster: @cluster).each do |page|
|
171
|
+
unless page.service_arns.empty?
|
172
|
+
@ecs.describe_services(cluster: @cluster, services: page.service_arns).services.each do |s|
|
173
|
+
if s.status != 'INACTIVE'
|
174
|
+
port = find_front_port(s)
|
175
|
+
if port
|
176
|
+
max_port = [max_port, port].max
|
164
177
|
end
|
165
178
|
end
|
166
179
|
end
|
167
180
|
end
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
181
|
+
end
|
182
|
+
if max_port == -1
|
183
|
+
DEFAULT_FRONT_PORT
|
184
|
+
else
|
185
|
+
max_port + 1
|
173
186
|
end
|
174
187
|
end
|
175
188
|
|
@@ -184,11 +197,11 @@ module Hako
|
|
184
197
|
end
|
185
198
|
end
|
186
199
|
|
187
|
-
def task_definition_changed?(definitions)
|
200
|
+
def task_definition_changed?(family, definitions)
|
188
201
|
if @force
|
189
202
|
return true
|
190
203
|
end
|
191
|
-
task_definition = @ecs.describe_task_definition(task_definition:
|
204
|
+
task_definition = @ecs.describe_task_definition(task_definition: family).task_definition
|
192
205
|
container_definitions = {}
|
193
206
|
task_definition.container_definitions.each do |c|
|
194
207
|
container_definitions[c.name] = c
|
@@ -207,7 +220,7 @@ module Hako
|
|
207
220
|
end
|
208
221
|
|
209
222
|
def register_task_definition(definitions)
|
210
|
-
if task_definition_changed?(definitions)
|
223
|
+
if task_definition_changed?(@app_id, definitions)
|
211
224
|
@ecs.register_task_definition(
|
212
225
|
family: @app_id,
|
213
226
|
container_definitions: definitions,
|
@@ -228,21 +241,16 @@ module Hako
|
|
228
241
|
end
|
229
242
|
end
|
230
243
|
|
231
|
-
def register_task_definition_for_oneshot(
|
232
|
-
@
|
233
|
-
|
234
|
-
|
235
|
-
{
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
port_mappings: [],
|
242
|
-
environment: [],
|
243
|
-
},
|
244
|
-
],
|
245
|
-
).task_definition
|
244
|
+
def register_task_definition_for_oneshot(definitions)
|
245
|
+
family = "#{@app_id}-oneshot"
|
246
|
+
if task_definition_changed?(family, definitions)
|
247
|
+
@ecs.register_task_definition(
|
248
|
+
family: "#{@app_id}-oneshot",
|
249
|
+
container_definitions: definitions,
|
250
|
+
).task_definition
|
251
|
+
else
|
252
|
+
:noop
|
253
|
+
end
|
246
254
|
end
|
247
255
|
|
248
256
|
def front_container(front, front_port)
|
@@ -275,17 +283,15 @@ module Hako
|
|
275
283
|
}
|
276
284
|
end
|
277
285
|
|
278
|
-
def run_task(task_definition,
|
279
|
-
environment = env.map { |k, v| { name: k, value: v } }
|
286
|
+
def run_task(task_definition, commands)
|
280
287
|
@ecs.run_task(
|
281
288
|
cluster: @cluster,
|
282
289
|
task_definition: task_definition.task_definition_arn,
|
283
290
|
overrides: {
|
284
291
|
container_overrides: [
|
285
292
|
{
|
286
|
-
name: '
|
293
|
+
name: 'app',
|
287
294
|
command: commands,
|
288
|
-
environment: environment,
|
289
295
|
},
|
290
296
|
],
|
291
297
|
},
|
@@ -311,13 +317,17 @@ module Hako
|
|
311
317
|
end
|
312
318
|
end
|
313
319
|
|
314
|
-
Hako.logger.
|
320
|
+
Hako.logger.debug " status #{task.last_status}"
|
315
321
|
|
316
322
|
if task.last_status == 'STOPPED'
|
317
323
|
Hako.logger.info "Stopped at #{task.stopped_at}"
|
318
|
-
|
319
|
-
|
320
|
-
|
324
|
+
containers = {}
|
325
|
+
task.containers.each do |c|
|
326
|
+
containers[c.name] = c
|
327
|
+
end
|
328
|
+
app = containers.fetch('app')
|
329
|
+
Hako.logger.info "Exit code is #{app.exit_code}"
|
330
|
+
return app.exit_code
|
321
331
|
end
|
322
332
|
sleep 1
|
323
333
|
end
|
data/lib/hako/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.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: 2016-02-
|
11
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|