hako 2.11.1 → 2.12.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/.travis.yml +4 -2
- data/CHANGELOG.md +10 -0
- data/lib/hako/cli.rb +7 -1
- data/lib/hako/commander.rb +3 -2
- data/lib/hako/schedulers/ecs.rb +71 -24
- data/lib/hako/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3778068a414fb367352ba788d4d957e863848258766bbc59efc5cf6a7b5344b5
|
4
|
+
data.tar.gz: c9e21cd8877bd3445739d328551fb85b28457e19fb12ff770ac53b604ab021be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d4beb5835cb3efe38fdfae553b50ebfd254fff8df7c454a8087105158dbfb5b655e83472e47c27934d365146d0b4d34fd4babefa850963f06ec6c50319ac66
|
7
|
+
data.tar.gz: ab158b547e18cb9a6231ee3726d5ba99934847f53699ef57cacc4779bc3551b2b1dfe51951d986904871b35286d7cc468f2cc683b6f5d3e15d7961b867395cd8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 2.12.0 (2019-09-09)
|
2
|
+
## New features
|
3
|
+
- Support more overrides options for `hako oneshot`
|
4
|
+
- `--app-cpu`, `--app-memory` and `--app-memory-reservation` are added
|
5
|
+
|
6
|
+
## Bug fixes
|
7
|
+
- Show `--health-*` options in dry-run
|
8
|
+
|
9
|
+
## Bug fixes
|
10
|
+
|
1
11
|
# 2.11.1 (2019-05-17)
|
2
12
|
## Bug fixes
|
3
13
|
- Fix comparison of `system_controls` parameter
|
data/lib/hako/cli.rb
CHANGED
@@ -147,6 +147,8 @@ module Hako
|
|
147
147
|
end
|
148
148
|
|
149
149
|
class Oneshot
|
150
|
+
Overrides = Struct.new(:app_cpu, :app_memory, :app_memory_reservation)
|
151
|
+
|
150
152
|
def run(argv)
|
151
153
|
parse!(argv)
|
152
154
|
require 'hako/application'
|
@@ -162,7 +164,7 @@ module Hako
|
|
162
164
|
else
|
163
165
|
{}
|
164
166
|
end
|
165
|
-
Commander.new(Application.new(@definition_path, options)).oneshot(@argv, tag: @tag, containers: @containers, env: @env, dry_run: @dry_run, no_wait: @no_wait)
|
167
|
+
Commander.new(Application.new(@definition_path, options)).oneshot(@argv, tag: @tag, containers: @containers, env: @env, dry_run: @dry_run, no_wait: @no_wait, overrides: @overrides)
|
166
168
|
end
|
167
169
|
|
168
170
|
def parse!(argv)
|
@@ -171,6 +173,7 @@ module Hako
|
|
171
173
|
@env = {}
|
172
174
|
@verbose = false
|
173
175
|
@no_wait = false
|
176
|
+
@overrides = Overrides.new
|
174
177
|
parser.parse!(argv)
|
175
178
|
@definition_path = argv.shift
|
176
179
|
@argv = argv
|
@@ -194,6 +197,9 @@ module Hako
|
|
194
197
|
k, v = arg.split('=', 2)
|
195
198
|
@env[k] = v
|
196
199
|
end
|
200
|
+
opts.on('--app-cpu=VAL', Integer, 'Override the default cpu for the app container') { |v| @overrides.app_cpu = v }
|
201
|
+
opts.on('--app-memory=VAL', Integer, 'Override the default memory for the app container') { |v| @overrides.app_memory = v }
|
202
|
+
opts.on('--app-memory-reservation=VAL', Integer, 'Override the default memory reservation for the app container') { |v| @overrides.app_memory_reservation = v }
|
197
203
|
end
|
198
204
|
end
|
199
205
|
end
|
data/lib/hako/commander.rb
CHANGED
@@ -46,8 +46,9 @@ module Hako
|
|
46
46
|
# @param [Hash<String, String>] env
|
47
47
|
# @param [Boolean] dry_run
|
48
48
|
# @param [Boolean] no_wait
|
49
|
+
# @param [Hako::CLI::Oneshot::Overrides, nil] overrides
|
49
50
|
# @return [nil]
|
50
|
-
def oneshot(commands, tag:, containers:, env: {}, dry_run: false, no_wait: false)
|
51
|
+
def oneshot(commands, tag:, containers:, env: {}, dry_run: false, no_wait: false, overrides: nil)
|
51
52
|
containers = load_containers(tag, dry_run: dry_run, with: containers)
|
52
53
|
scripts = @app.definition.fetch('scripts', []).map { |config| load_script(config, dry_run: dry_run) }
|
53
54
|
volumes = @app.definition.fetch('volumes', {})
|
@@ -55,7 +56,7 @@ module Hako
|
|
55
56
|
|
56
57
|
scripts.each { |script| script.oneshot_starting(containers) }
|
57
58
|
exit_code = with_oneshot_signal_handlers(scheduler) do
|
58
|
-
scheduler.oneshot(containers, commands, env, no_wait: no_wait)
|
59
|
+
scheduler.oneshot(containers, commands, env, no_wait: no_wait, overrides: overrides)
|
59
60
|
end
|
60
61
|
scripts.each { |script| script.oneshot_finished(containers) }
|
61
62
|
exit exit_code
|
data/lib/hako/schedulers/ecs.rb
CHANGED
@@ -198,8 +198,9 @@ module Hako
|
|
198
198
|
# @param [Array<String>] commands
|
199
199
|
# @param [Hash<String, String>] env
|
200
200
|
# @param [Boolean] no_wait
|
201
|
+
# @param [Hako::CLI::Oneshot::Overrides, nil] overrides
|
201
202
|
# @return [Integer] Returns exit code
|
202
|
-
def oneshot(containers, commands, env, no_wait: false)
|
203
|
+
def oneshot(containers, commands, env, no_wait: false, overrides: nil)
|
203
204
|
definitions = create_definitions(containers)
|
204
205
|
|
205
206
|
if @dry_run
|
@@ -210,7 +211,7 @@ module Hako
|
|
210
211
|
if d[:name] == 'app'
|
211
212
|
d[:command] = commands
|
212
213
|
end
|
213
|
-
print_definition_in_cli_format(d, additional_env: env)
|
214
|
+
print_definition_in_cli_format(d, additional_env: env, overrides: overrides)
|
214
215
|
check_secrets(d)
|
215
216
|
end
|
216
217
|
0
|
@@ -221,7 +222,7 @@ module Hako
|
|
221
222
|
else
|
222
223
|
Hako.logger.info "Task definition isn't changed: #{task_definition.task_definition_arn}"
|
223
224
|
end
|
224
|
-
@task = run_task(task_definition, commands, env)
|
225
|
+
@task = run_task(task_definition, commands, env, overrides)
|
225
226
|
Hako.logger.info "Started task: #{@task.task_arn}"
|
226
227
|
@scripts.each { |script| script.oneshot_started(self) }
|
227
228
|
if no_wait
|
@@ -658,21 +659,13 @@ module Hako
|
|
658
659
|
# @param [Aws::ECS::Types::TaskDefinition] task_definition
|
659
660
|
# @param [Array<String>] commands
|
660
661
|
# @param [Hash<String, String>] env
|
662
|
+
# @param [Hako::CLI::Oneshot::Overrides] overrides
|
661
663
|
# @return [Aws::ECS::Types::Task]
|
662
|
-
def run_task(task_definition, commands, env)
|
663
|
-
environment = env.map { |k, v| { name: k, value: v } }
|
664
|
+
def run_task(task_definition, commands, env, overrides)
|
664
665
|
result = ecs_client.run_task(
|
665
666
|
cluster: @cluster,
|
666
667
|
task_definition: task_definition.task_definition_arn,
|
667
|
-
overrides:
|
668
|
-
container_overrides: [
|
669
|
-
{
|
670
|
-
name: 'app',
|
671
|
-
command: commands,
|
672
|
-
environment: environment,
|
673
|
-
},
|
674
|
-
],
|
675
|
-
},
|
668
|
+
overrides: overrides_option(commands, env, overrides),
|
676
669
|
count: 1,
|
677
670
|
placement_constraints: @placement_constraints,
|
678
671
|
started_by: 'hako oneshot',
|
@@ -702,6 +695,25 @@ module Hako
|
|
702
695
|
end
|
703
696
|
end
|
704
697
|
|
698
|
+
# @param [Array<String>] commands
|
699
|
+
# @param [Hash<String, String>] env
|
700
|
+
# @param [Hako::CLI::Oneshot::Overrides, nil] overrides
|
701
|
+
# @doc https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerOverride.html
|
702
|
+
def overrides_option(commands, env, overrides)
|
703
|
+
{
|
704
|
+
container_overrides: [
|
705
|
+
{
|
706
|
+
name: 'app',
|
707
|
+
cpu: overrides&.app_cpu,
|
708
|
+
memory: overrides&.app_memory,
|
709
|
+
memory_reservation: overrides&.app_memory_reservation,
|
710
|
+
command: commands,
|
711
|
+
environment: env.map { |k, v| { name: k, value: v } },
|
712
|
+
},
|
713
|
+
],
|
714
|
+
}
|
715
|
+
end
|
716
|
+
|
705
717
|
# @return [Fixnum]
|
706
718
|
def wait_for_oneshot_finish
|
707
719
|
containers = wait_for_task(@task)
|
@@ -1154,17 +1166,33 @@ module Hako
|
|
1154
1166
|
|
1155
1167
|
# @param [Hash] definition
|
1156
1168
|
# @param [Hash<String, String>] additional_env
|
1169
|
+
# @param [Hako::CLI::Oneshot::Overrides, nil] overrides
|
1157
1170
|
# @return [nil]
|
1158
|
-
def print_definition_in_cli_format(definition, additional_env: {})
|
1171
|
+
def print_definition_in_cli_format(definition, additional_env: {}, overrides: nil)
|
1159
1172
|
cmd = %w[docker run]
|
1160
1173
|
cmd << '--name' << definition.fetch(:name)
|
1161
|
-
|
1162
|
-
if definition
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1174
|
+
|
1175
|
+
if overrides && definition.fetch(:name) == 'app'
|
1176
|
+
cpu = overrides.app_cpu || definition.fetch(:cpu)
|
1177
|
+
cmd << '--cpu-shares' << cpu
|
1178
|
+
memory = overrides.app_memory || definition[:memory]
|
1179
|
+
if memory
|
1180
|
+
cmd << '--memory' << "#{memory}M"
|
1181
|
+
end
|
1182
|
+
memory_reservation = overrides.app_memory_reservation || definition[:memory_reservation]
|
1183
|
+
if memory_reservation
|
1184
|
+
cmd << '--memory-reservation' << "#{memory_reservation}M"
|
1185
|
+
end
|
1186
|
+
else
|
1187
|
+
cmd << '--cpu-shares' << definition.fetch(:cpu)
|
1188
|
+
if definition[:memory]
|
1189
|
+
cmd << '--memory' << "#{definition[:memory]}M"
|
1190
|
+
end
|
1191
|
+
if definition[:memory_reservation]
|
1192
|
+
cmd << '--memory-reservation' << "#{definition[:memory_reservation]}M"
|
1193
|
+
end
|
1167
1194
|
end
|
1195
|
+
|
1168
1196
|
definition.fetch(:links).each do |link|
|
1169
1197
|
cmd << '--link' << link
|
1170
1198
|
end
|
@@ -1227,9 +1255,6 @@ module Hako
|
|
1227
1255
|
cmd << '--tmpfs' << "#{tmpfs[:container_path]}:#{options.join(',')}"
|
1228
1256
|
end
|
1229
1257
|
end
|
1230
|
-
definition.fetch(:volumes_from).each do |volumes_from|
|
1231
|
-
p volumes_from
|
1232
|
-
end
|
1233
1258
|
if definition[:user]
|
1234
1259
|
cmd << '--user' << definition[:user]
|
1235
1260
|
end
|
@@ -1247,6 +1272,28 @@ module Hako
|
|
1247
1272
|
cmd << '--sysctl' << "#{system_control.fetch(:namespace)}=#{system_control.fetch(:value)}"
|
1248
1273
|
end
|
1249
1274
|
end
|
1275
|
+
if definition[:health_check]
|
1276
|
+
if definition[:health_check][:command]
|
1277
|
+
health_check_command_type = definition[:health_check][:command][0]
|
1278
|
+
case health_check_command_type
|
1279
|
+
when 'NONE'
|
1280
|
+
cmd << '--no-healthcheck'
|
1281
|
+
when 'CMD', 'CMD-SHELL'
|
1282
|
+
health_check_command = definition[:health_check][:command][1..-1].join(' ')
|
1283
|
+
cmd << '--health-cmd' << health_check_command.inspect
|
1284
|
+
else
|
1285
|
+
raise "Health check command type #{health_check_command_type} is not supported. CMD, CMD-SHELL and NONE are supported."
|
1286
|
+
end
|
1287
|
+
end
|
1288
|
+
if definition[:health_check][:retries]
|
1289
|
+
cmd << '--health-retries' << definition[:health_check][:retries]
|
1290
|
+
end
|
1291
|
+
%i[interval timeout start_period].each do |property|
|
1292
|
+
if definition[:health_check][property]
|
1293
|
+
cmd << "--health-#{property}" << "#{definition[:health_check][property]}s"
|
1294
|
+
end
|
1295
|
+
end
|
1296
|
+
end
|
1250
1297
|
|
1251
1298
|
cmd << "\\\n "
|
1252
1299
|
definition.fetch(:environment).each do |env|
|
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: 2.
|
4
|
+
version: 2.12.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-
|
11
|
+
date: 2019-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-applicationautoscaling
|