wrapbox 0.3.0 → 0.4.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
2
  SHA1:
3
- metadata.gz: 8118b81067d91ea3535d8c3c5ca1ba55c412d345
4
- data.tar.gz: 33fb0eb243ff53a6bc6ec7c5147a69ea3bbbc206
3
+ metadata.gz: 67a6e2d03ab3ecd91eb20638f7ea5faa3b42e6e9
4
+ data.tar.gz: d64a6d52580d830f3c48dad77885fb1d344baaa9
5
5
  SHA512:
6
- metadata.gz: 5e9a9730bca6b1dddbe9a8c21a2660645dc0d3f6f3c71a74c24e175930a6bd01544e2f2b2efd6d04fc0b14bdbeeded4a4d5ad7abe38e37c4c5abe83593c1a37c
7
- data.tar.gz: 74c5c6831768ed37e5107903426131a4158220b808b39fae6d08b74df14dcfcc2f9bd495ec1ce3f6157a66ee5602f08a5161e0c73b6535f1cefdf4ebbf14a388
6
+ metadata.gz: dc8c3a0b68c1d636a501cf205fa41741c526b1c432d2e2e09875b181a4bf3e3b3d8e2ff754ef341f7fcf6d98426a1a187eafdcca8d6c03241ecc7f531625d982
7
+ data.tar.gz: 800d8fedf7f5d0aea0850b3d5158699d0107ccfda0eb2f00319e331af2e38d48ba0e18a274bca0c08f6f008cda1761d2cfb70e018bd40342c912ce70043cb9bd
data/README.md CHANGED
@@ -85,6 +85,17 @@ Wrapbox.run_cmd(["ls ."], environments: [{name: "RAILS_ENV", value: "development
85
85
  | additional_container_definitions | Container definitions for sub containers |
86
86
  | task_role_arn | see. http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html |
87
87
 
88
+ `WRAPBOX_CMD_INDEX` environment variable is available in `run_cmd` and you can distinguish logs from each command like below:
89
+
90
+ ```
91
+ log_configuration:
92
+ log_driver: syslog
93
+ options:
94
+ syslog-address: "tcp://192.168.0.42:123"
95
+ env: WRAPBOX_CMD_INDEX
96
+ tag: wrapbox-{{ printf "%03s" (.ExtraAttributes nil).WRAPBOX_CMD_INDEX }}
97
+ ```
98
+
88
99
  ### for docker
89
100
  | name | desc |
90
101
  | -------------------- | ----------------------------------------------------------- |
@@ -35,9 +35,10 @@ module Wrapbox
35
35
 
36
36
  environments = extract_environments(environments)
37
37
 
38
- ths = cmds.map do |cmd|
39
- Thread.new(cmd) do |c|
40
- exec_docker(definition: definition, cmd: c.split(/\s+/), environments: environments)
38
+ ths = cmds.map.with_index do |cmd, idx|
39
+ Thread.new(cmd, idx) do |c, i|
40
+ envs = environments + ["WRAPBOX_CMD_INDEX=#{idx}"]
41
+ exec_docker(definition: definition, cmd: c.split(/\s+/), environments: envs)
41
42
  end
42
43
  end
43
44
  ths.each(&:join)
@@ -4,6 +4,7 @@ require "thor"
4
4
  require "yaml"
5
5
  require "active_support/core_ext/hash"
6
6
  require "logger"
7
+ require "pp"
7
8
 
8
9
  require "wrapbox/config_repository"
9
10
  require "wrapbox/version"
@@ -76,14 +77,15 @@ module Wrapbox
76
77
 
77
78
  def run_cmd(cmds, container_definition_overrides: {}, **parameters)
78
79
  task_definition = register_task_definition(container_definition_overrides)
79
- parameter = Parameter.new(**parameters)
80
80
 
81
- ths = cmds.map do |cmd|
82
- Thread.new(cmd) do |c|
81
+ ths = cmds.map.with_index do |cmd, idx|
82
+ Thread.new(cmd, idx) do |c, i|
83
+ Thread.current[:cmd_index] = i
84
+ envs = (parameters[:environments] || []) + [{name: "WRAPBOX_CMD_INDEX", value: i.to_s}]
83
85
  run_task(
84
86
  task_definition.task_definition_arn, nil, nil, nil,
85
87
  c.split(/\s+/),
86
- parameter
88
+ Parameter.new(**parameters.merge(environments: envs))
87
89
  )
88
90
  end
89
91
  end
@@ -111,7 +113,7 @@ module Wrapbox
111
113
  task_status = fetch_task_status(cl, task.task_arn)
112
114
 
113
115
  # If exit_code is nil, Container is force killed or ECS failed to launch Container by Irregular situation
114
- error_message = "Container #{task_definition_name} is failed. task=#{task.task_arn}, exit_code=#{task_status[:exit_code]}, reason=#{task_status[:stopped_reason]}"
116
+ error_message = build_error_message(task_definition_name, task.task_arn, task_status)
115
117
  raise ContainerAbnormalEnd, error_message unless task_status[:exit_code]
116
118
  raise ExecutionFailure, error_message unless task_status[:exit_code] == 0
117
119
 
@@ -142,8 +144,10 @@ module Wrapbox
142
144
  current_retry_interval = parameter.retry_interval
143
145
 
144
146
  begin
147
+ run_task_options = build_run_task_options(task_definition_arn, class_name, method_name, args, command, cl, parameter.environments, parameter.task_role_arn)
148
+ @logger.debug("Task Options: #{run_task_options}")
145
149
  task = client
146
- .run_task(build_run_task_options(task_definition_arn, class_name, method_name, args, command, cl, parameter.environments, parameter.task_role_arn))
150
+ .run_task(run_task_options)
147
151
  .tasks[0]
148
152
 
149
153
  raise LackResource unless task # this case is almost lack of container resource.
@@ -194,7 +198,8 @@ module Wrapbox
194
198
  end
195
199
  rescue LaunchFailure
196
200
  if launch_try_count >= parameter.launch_retry
197
- raise
201
+ task_status = fetch_task_status(cl, task.task_arn)
202
+ raise LaunchFailure, build_error_message(task_definition_name, task.task_arn, task_status)
198
203
  else
199
204
  launch_try_count += 1
200
205
  @logger.debug("Retry Create Task after #{current_retry_interval} sec")
@@ -236,8 +241,13 @@ module Wrapbox
236
241
 
237
242
  def fetch_task_status(cluster, task_arn)
238
243
  task = client.describe_tasks(cluster: cluster, tasks: [task_arn]).tasks[0]
239
- container = task.containers.find { |c| c.name = task_definition_name }
240
- {last_status: task.last_status, exit_code: container.exit_code, stopped_reason: task.stopped_reason}
244
+ container = task.containers.find { |c| c.name == task_definition_name }
245
+ {
246
+ last_status: task.last_status,
247
+ exit_code: container.exit_code,
248
+ stopped_reason: task.stopped_reason,
249
+ container_stopped_reason: container.reason
250
+ }
241
251
  end
242
252
 
243
253
  def register_task_definition(container_definition_overrides)
@@ -337,6 +347,13 @@ module Wrapbox
337
347
  }
338
348
  end
339
349
 
350
+ def build_error_message(task_definition_name, task_arn, task_status)
351
+ error_message = "Container #{task_definition_name} is failed. task=#{task_arn}, "
352
+ error_message << "cmd_index=#{Thread.current[:cmd_index]}, " if Thread.current[:cmd_index]
353
+ error_message << "exit_code=#{task_status[:exit_code]}, task_stopped_reason=#{task_status[:stopped_reason]}, container_stopped_reason=#{task_status[:container_stopped_reason]}"
354
+ error_message
355
+ end
356
+
340
357
  class Cli < Thor
341
358
  namespace :ecs
342
359
 
@@ -360,6 +377,7 @@ module Wrapbox
360
377
  {name: k, value: v}
361
378
  end
362
379
  run_options = {
380
+ cluster: options[:cluster],
363
381
  task_role_arn: options[:task_role_arn],
364
382
  timeout: options[:timeout],
365
383
  launch_timeout: options[:launch_timeout],
@@ -1,3 +1,3 @@
1
1
  module Wrapbox
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrapbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-19 00:00:00.000000000 Z
11
+ date: 2017-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubyforge_project:
215
- rubygems_version: 2.6.8
215
+ rubygems_version: 2.6.11
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Ruby method runner on AWS ECS