docker_toolkit 0.1.3 → 0.1.4

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: 37e19e4995dbe0cc868b51fdae6fc18b69d26e12c85a68b8364113e19b7efdf8
4
- data.tar.gz: 243fb2286022970786e1cdde0bffafacf35f6d5b9dd33fb9c1f1ea1b433e5626
3
+ metadata.gz: 230ac560d5572314c74c9bb672fa96705409d5c599c65f25e8ff7085e485e19e
4
+ data.tar.gz: b85ee60c82658dd39f1be73a4005b478ba3fda5f263ef1d63371eae6aa3292fb
5
5
  SHA512:
6
- metadata.gz: 0553be938e83e0d9359181234499cf1cb10cf0fe0152eab1d29c8bd33f805810da1a8eb67bc0dd0e302cacd73a1eaa02f023c82827b66cc92efc5f7e21a91d20
7
- data.tar.gz: 38a0e77028d94411d4da7ceccf40a34f8b2fa87f4147842e95cbc0340b211733af572e8e817d8f4ec281557d83f80db5cf53917fd9a2b9837744916bfe61a628
6
+ metadata.gz: 4567251c79471403d0093224d99d57d650bbb2cbb2113487c7cc3ad3d127d75fb59c8f00486bdcd72806ee51a3a8e4074bf182828f2ebbd1c1a2c655edd8e814
7
+ data.tar.gz: 5140b439d81a523f9a50ab538027ecf439f7074f5b89426175c65334d39093005a5f76a5ffce611173bae8d8398f1b91acd264cdcf8181d6de6b1125908608cd
data/.rubocop.yml CHANGED
@@ -3,6 +3,12 @@ AllCops:
3
3
  Exclude:
4
4
  - 'storage/**/*'
5
5
  - 'docker/**/*'
6
+ - 'lib/docker_toolkit/childprocess/**/*'
7
+ - 'lib/docker_toolkit/childprocess,rb'
8
+
9
+
10
+ Security/YAMLLoad:
11
+ Enabled: false
6
12
 
7
13
  Style/AsciiComments:
8
14
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker_toolkit (0.1.3)
4
+ docker_toolkit (0.1.4)
5
5
  diplomat
6
6
  json
7
7
 
data/bin/consul.rb CHANGED
@@ -102,7 +102,7 @@ def dereferenced_value(value)
102
102
  end
103
103
 
104
104
  if config = @opts[:config]
105
- @opts[:config] = YAML.safe_load(config == '-' ? STDIN.read : File.read(config), [], [], true)
105
+ @opts[:config] = YAML.load(config == '-' ? STDIN.read : File.read(config))
106
106
  end
107
107
 
108
108
  if @opts[:init]
data/bin/merger.rb CHANGED
@@ -76,9 +76,9 @@ def process_compose_hash(yml, dirname, parent = {})
76
76
  end
77
77
 
78
78
  tmp = if File.exist?(dirname + '/' + file)
79
- YAML.safe_load(File.read(dirname + '/' + file))
79
+ YAML.load(File.read(dirname + '/' + file))
80
80
  else
81
- YAML.safe_load(File.read(file))
81
+ YAML.load(File.read(file))
82
82
  end
83
83
 
84
84
  begin
@@ -99,7 +99,7 @@ end
99
99
 
100
100
  if File.basename($PROGRAM_NAME) == File.basename(__FILE__)
101
101
  result = ENV['COMPOSE_FILE'].split(':').reduce({}) do |parent, file|
102
- yml = process_compose_hash(YAML.safe_load(File.read(file)), File.dirname(file), parent)
102
+ yml = process_compose_hash(YAML.load(File.read(file)), File.dirname(file), parent)
103
103
  if yml['version'] && parent['version'] && yml['version'] != parent['version']
104
104
  raise "version mismatch: #{file}"
105
105
  end
data/bin/terminator.rb CHANGED
@@ -11,6 +11,13 @@ STDERR.sync = true
11
11
  term_code: 0
12
12
  }
13
13
 
14
+ def log(msg)
15
+ puts "[terminator]: #{msg}"
16
+ end
17
+
18
+ log "started: #{ARGV.inspect}"
19
+
20
+
14
21
  parser = OptionParser.new do |o|
15
22
  o.banner = 'Usage: term.rb [options]'
16
23
 
@@ -33,24 +40,32 @@ parser = OptionParser.new do |o|
33
40
  o.on('--kill', 'SIGKILL self') do
34
41
  @opts[:kill] = true
35
42
  end
36
-
37
43
  end
38
44
  parser.parse!
39
45
 
40
- def log msg
41
- puts "[terminator]: #{msg}"
42
- end
46
+
43
47
 
44
48
 
45
49
  %w[INT TERM].each do |sig|
46
50
  trap(sig) do
51
+ log "signal: #{sig}. exit: #{@opts[:term_code]}"
47
52
  exit(@opts[:term_code])
48
53
  end
49
- end
54
+ end
50
55
 
56
+ log 'sleep...'
51
57
  sleep @opts[:sleep]
52
58
 
53
- ::Process.kill('KILL', $$) if @opts[:kill]
54
- ::Process.kill('TERM', $$) if @opts[:term]
59
+ log 'go'
60
+ if @opts[:kill]
61
+ log 'kill self'
62
+ ::Process.kill('KILL', $PROCESS_ID)
63
+ end
64
+
65
+ if @opts[:term]
66
+ log 'term self'
67
+ ::Process.kill('TERM', $PROCESS_ID)
68
+ end
55
69
 
56
- exit @opts[:code]
70
+ log "normal exit with: #{@opts[:code]}"
71
+ exit @opts[:code]
@@ -2,16 +2,19 @@ require 'docker_toolkit/childprocess/version'
2
2
  require 'docker_toolkit/childprocess/errors'
3
3
  require 'docker_toolkit/childprocess/abstract_process'
4
4
  require 'docker_toolkit/childprocess/abstract_io'
5
- require "fcntl"
5
+ require 'fcntl'
6
6
  require 'logger'
7
7
 
8
8
  module DockerToolkit
9
9
 
10
- module ChildProcess
10
+ module ChildProcess
11
+
12
+
13
+ @posix_spawn = false
14
+
15
+ class << self
11
16
 
12
- @posix_spawn = false
13
17
 
14
- class << self
15
18
  attr_writer :logger
16
19
 
17
20
  def new(*args)
@@ -27,13 +30,13 @@ module ChildProcess
27
30
  when :windows
28
31
  Windows::Process.new(args)
29
32
  else
30
- raise Error, "unsupported platform #{platform_name.inspect}"
33
+ raise Error.new("unsupported platform #{platform_name.inspect}")
31
34
  end
32
35
  end
33
- alias_method :build, :new
36
+ alias build new
34
37
 
35
38
  def logger
36
- return @logger if defined?(@logger) and @logger
39
+ return @logger if defined?(@logger) && @logger
37
40
 
38
41
  @logger = Logger.new($stderr)
39
42
  @logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
@@ -42,9 +45,9 @@ module ChildProcess
42
45
  end
43
46
 
44
47
  def platform
45
- if RUBY_PLATFORM == "java"
48
+ if RUBY_PLATFORM == 'java'
46
49
  :jruby
47
- elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
50
+ elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
48
51
  :ironruby
49
52
  else
50
53
  os
@@ -82,7 +85,7 @@ module ChildProcess
82
85
  raise ChildProcess::MissingPlatformError
83
86
  end
84
87
 
85
- require "childprocess/unix/lib"
88
+ require 'childprocess/unix/lib'
86
89
  require 'childprocess/unix/posix_spawn_process'
87
90
 
88
91
  true
@@ -95,13 +98,11 @@ module ChildProcess
95
98
  # Set this to true to enable experimental use of posix_spawn.
96
99
  #
97
100
 
98
- def posix_spawn=(bool)
99
- @posix_spawn = bool
100
- end
101
+ attr_writer :posix_spawn
101
102
 
102
103
  def os
103
- @os ||= (
104
- require "rbconfig"
104
+ @os ||= begin
105
+ require 'rbconfig'
105
106
  host_os = RbConfig::CONFIG['host_os'].downcase
106
107
 
107
108
  case host_os
@@ -120,30 +121,30 @@ module ChildProcess
120
121
  when /aix/
121
122
  :aix
122
123
  else
123
- raise Error, "unknown os: #{host_os.inspect}"
124
+ raise Error.new("unknown os: #{host_os.inspect}")
124
125
  end
125
- )
126
+ end
126
127
  end
127
128
 
128
129
  def arch
129
- @arch ||= (
130
+ @arch ||= begin
130
131
  host_cpu = RbConfig::CONFIG['host_cpu'].downcase
131
132
  case host_cpu
132
133
  when /i[3456]86/
133
134
  if workaround_older_macosx_misreported_cpu?
134
135
  # Workaround case: older 64-bit Darwin Rubies misreported as i686
135
- "x86_64"
136
+ 'x86_64'
136
137
  else
137
- "i386"
138
+ 'i386'
138
139
  end
139
140
  when /amd64|x86_64/
140
- "x86_64"
141
+ 'x86_64'
141
142
  when /ppc|powerpc/
142
- "powerpc"
143
+ 'powerpc'
143
144
  else
144
145
  host_cpu
145
146
  end
146
- )
147
+ end
147
148
  end
148
149
 
149
150
  #
@@ -167,38 +168,42 @@ module ChildProcess
167
168
  elsif windows?
168
169
  Windows::Lib.dont_inherit file
169
170
  else
170
- raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
171
+ raise Error.new("not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}")
171
172
  end
172
173
  end
173
174
 
174
- private
175
+ private
175
176
 
176
- def warn_once(msg)
177
- @warnings ||= {}
177
+ def warn_once(msg)
178
+ @warnings ||= {}
178
179
 
179
- unless @warnings[msg]
180
- @warnings[msg] = true
181
- logger.warn msg
180
+ unless @warnings[msg]
181
+ @warnings[msg] = true
182
+ logger.warn msg
183
+ end
182
184
  end
183
- end
184
185
 
185
- # Workaround: detect the situation that an older Darwin Ruby is actually
186
- # 64-bit, but is misreporting cpu as i686, which would imply 32-bit.
187
- #
188
- # @return [Boolean] `true` if:
189
- # (a) on Mac OS X
190
- # (b) actually running in 64-bit mode
191
- def workaround_older_macosx_misreported_cpu?
192
- os == :macosx && is_64_bit?
193
- end
186
+ # Workaround: detect the situation that an older Darwin Ruby is actually
187
+ # 64-bit, but is misreporting cpu as i686, which would imply 32-bit.
188
+ #
189
+ # @return [Boolean] `true` if:
190
+ # (a) on Mac OS X
191
+ # (b) actually running in 64-bit mode
192
+ def workaround_older_macosx_misreported_cpu?
193
+ os == :macosx && is_64_bit?
194
+ end
195
+
196
+ # @return [Boolean] `true` if this Ruby represents `1` in 64 bits (8 bytes).
197
+ def is_64_bit?
198
+ 1.size == 8
199
+ end
200
+
201
+
202
+ end # class << self
194
203
 
195
- # @return [Boolean] `true` if this Ruby represents `1` in 64 bits (8 bytes).
196
- def is_64_bit?
197
- 1.size == 8
198
- end
199
204
 
200
- end # class << self
201
205
  end # ChildProcess
206
+
202
207
  end # DockerToolkit
203
208
 
204
209
  require 'jruby' if DockerToolkit::ChildProcess.jruby?
@@ -1,5 +1,5 @@
1
1
  module DockerToolkit
2
2
 
3
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.1.4'.freeze
4
4
 
5
5
  end
@@ -3,186 +3,196 @@ require 'English'
3
3
 
4
4
  module DockerToolkit
5
5
 
6
- class Watcher
7
- def initialize
8
- @lock = Mutex.new
9
-
10
- @procs = []
11
- @code = 0
12
- @crashed = false
13
- @threads = []
14
- @who = nil
15
- @stopping = false
16
- end
6
+ class Watcher
17
7
 
18
- def stop_all
19
- @stopping = true
20
8
 
21
- terminating = @procs.reject do |meta|
22
- meta[:handled] || meta[:process].exited?
23
- end
24
-
25
- terminating.each do |meta|
26
- ::Process.kill 'TERM', meta[:process].pid
27
- end
9
+ def initialize
10
+ @lock = Mutex.new
28
11
 
29
- terminating.each do |meta|
30
- begin
31
- meta[:process].poll_for_exit(10)
32
- rescue ChildProcess::TimeoutError
33
- meta[:process].stop(1)
34
- meta[:stdout].close
35
- meta[:stderr].close
12
+ @procs = []
13
+ @code = 0
14
+ @crashed = false
15
+ @threads = []
16
+ @who = nil
17
+ @stopping = false
36
18
  end
37
- end
38
19
 
39
- if !@crashed
40
- meta = @procs.detect do |meta|
41
- meta[:process].crashed?
20
+ def stop_all
21
+ @stopping = true
22
+
23
+ terminating = @procs.reject do |meta|
24
+ meta[:handled] || meta[:process].exited?
42
25
  end
43
26
 
44
- if meta
45
- @crashed = true
46
- @code = meta[:process].exit_code
47
- @who = meta[:cmd]
27
+ terminating.each do |meta|
28
+ ::Process.kill 'TERM', meta[:process].pid
48
29
  end
49
- end
50
30
 
51
- @procs.each do |meta|
52
- meta[:stdout].close rescue nil
53
- meta[:stderr].close rescue nil
54
- end
31
+ terminating.each do |meta|
32
+ begin
33
+ meta[:process].poll_for_exit(10)
34
+ rescue ChildProcess::TimeoutError
35
+ meta[:process].stop(1)
36
+ meta[:stdout].close
37
+ meta[:stderr].close
38
+ end
39
+ end
55
40
 
56
- Thread.new do
57
- sleep 2
58
- @threads.each(&:terminate)
59
- end
60
-
41
+ unless @crashed
42
+ meta = @procs.detect do |meta|
43
+ meta[:process].crashed?
44
+ end
61
45
 
62
- end
46
+ if meta
47
+ @crashed = true
48
+ @code = meta[:process].exit_code
49
+ @who = meta[:cmd]
50
+ end
51
+ end
63
52
 
53
+ @procs.each do |meta|
54
+ begin
55
+ meta[:stdout].close
56
+ rescue StandardError
57
+ nil
58
+ end
59
+ begin
60
+ meta[:stderr].close
61
+ rescue StandardError
62
+ nil
63
+ end
64
+ end
65
+
66
+ Thread.new do
67
+ sleep 2
68
+ @threads.each(&:terminate)
69
+ end
70
+ end
64
71
 
65
- def add *cmd
66
- process = ChildProcess.build(*cmd)
72
+ def add(*cmd)
73
+ process = ChildProcess.build(*cmd)
67
74
 
68
- rerr, werr = IO.pipe
69
- rout, wout = IO.pipe
75
+ rerr, werr = IO.pipe
76
+ rout, wout = IO.pipe
70
77
 
71
- process.io.stdout = wout
72
- process.io.stderr = werr
78
+ process.io.stdout = wout
79
+ process.io.stderr = werr
73
80
 
74
- meta = {
75
- cmd: cmd,
76
- process: process,
77
- stdout: rout,
78
- stderr: rerr
79
- }
81
+ meta = {
82
+ cmd: cmd,
83
+ process: process,
84
+ stdout: rout,
85
+ stderr: rerr
86
+ }
80
87
 
81
- @threads << Thread.new(meta[:stdout], STDOUT) do |io, out|
82
- loop do
83
- break unless synchro_readline(io, out)
88
+ @threads << Thread.new(meta[:stdout], STDOUT) do |io, out|
89
+ loop do
90
+ break unless synchro_readline(io, out)
91
+ end
84
92
  end
85
- end
86
93
 
87
- @threads << Thread.new(meta[:stderr], STDERR) do |io, out|
88
- loop do
89
- break unless synchro_readline(io, out)
94
+ @threads << Thread.new(meta[:stderr], STDERR) do |io, out|
95
+ loop do
96
+ break unless synchro_readline(io, out)
97
+ end
90
98
  end
91
- end
92
99
 
93
- log "Starting #{meta[:cmd]}"
94
- meta[:pid] = meta[:process].start.pid
100
+ log "Starting #{meta[:cmd]}"
101
+ meta[:pid] = meta[:process].start.pid
95
102
 
96
- @procs.push(meta)
97
- meta
98
- end
99
-
100
- def synchro_readline io, out
101
- str = io.gets
102
- @lock.synchronize{out.puts str}
103
- true
104
- rescue => e
105
- false
106
- end
103
+ @procs.push(meta)
104
+ meta
105
+ end
107
106
 
108
- def log msg
109
- puts "[watcher]: #{msg}"
110
- end
107
+ def synchro_readline(io, out)
108
+ str = io.gets
109
+ @lock.synchronize{ out.puts str }
110
+ true
111
+ rescue StandardError => e
112
+ false
113
+ end
111
114
 
112
- def error msg
113
- STDERR.puts "[watcher]: Error: #{msg}"
114
- end
115
+ def log(msg)
116
+ puts "[watcher]: #{msg}"
117
+ end
115
118
 
119
+ def error(msg)
120
+ STDERR.puts "[watcher]: Error: #{msg}"
121
+ end
116
122
 
117
- def exec &block
118
- %w[EXIT QUIT].each do |sig|
119
- trap(sig) do
120
- stop_all
123
+ def exec
124
+ %w[EXIT QUIT].each do |sig|
125
+ trap(sig) do
126
+ stop_all
127
+ end
121
128
  end
122
- end
123
129
 
124
130
 
125
- %w[INT TERM].each do |sig|
126
- trap(sig) do
127
- log "Catch #{sig}: try exits gracefully.."
128
- stop_all
131
+ %w[INT TERM].each do |sig|
132
+ trap(sig) do
133
+ log "Catch #{sig}: try exits gracefully.."
134
+ stop_all
135
+ end
129
136
  end
130
- end
131
137
 
132
- trap("CLD") do |*args|
133
- unhandled = @procs.reject do |meta|
134
- meta[:handled] || !meta[:process].exited?
135
- end
138
+ trap('CLD') do |*_args|
139
+ unhandled = @procs.reject do |meta|
140
+ meta[:handled] || !meta[:process].exited?
141
+ end
136
142
 
137
- unhandled.any? do |meta|
138
- log "Child finished"
139
- log " Process[#{meta[:pid]}]: #{meta[:cmd]}"
140
- log " status: #{meta[:process].crashed? ? 'crashed' : 'exited'}"
141
- log " code: #{meta[:process].exit_code}"
143
+ unhandled.any? do |meta|
144
+ log 'Child finished'
145
+ log " Process[#{meta[:pid]}]: #{meta[:cmd]}"
146
+ log " status: #{meta[:process].crashed? ? 'crashed' : 'exited'}"
147
+ log " code: #{meta[:process].exit_code}"
148
+
149
+ meta[:handled] = true
150
+ begin
151
+ meta[:stdout].close
152
+ rescue StandardError
153
+ IOError
154
+ end
155
+ begin
156
+ meta[:stderr].close
157
+ rescue StandardError
158
+ IOError
159
+ end
142
160
 
143
- meta[:handled] = true
144
- meta[:stdout].close
145
- meta[:stderr].close
161
+ if !@crashed && meta[:process].crashed?
162
+ @crashed = true
163
+ @code = meta[:process].exit_code
164
+ @who = meta[:cmd]
165
+ end
146
166
 
147
- if !@crashed && meta[:process].crashed?
148
- @crashed = true
149
- @code = meta[:process].exit_code
150
- @who = meta[:cmd]
151
- end
167
+ unless @stopping
168
+ log 'Try exits gracefully..'
169
+ stop_all
170
+ end
152
171
 
153
- if !@stopping
154
- log "Try exits gracefully.."
155
- stop_all
172
+ true
156
173
  end
157
-
158
- true
159
- end
160
- end
161
-
162
- begin
163
- yield(self)
164
- rescue => e
165
- @crashed = true
166
- @code = 1
167
- error e.inspect
168
- error e.backtrace.last(20).join("\n")
169
- log "Try exits gracefully.."
170
- stop_all
171
- end
174
+ end
172
175
 
173
- @threads.map(&:join)
174
-
175
- if @crashed
176
- @code = [@code || 0, 1].max
177
- end
176
+ begin
177
+ yield(self)
178
+ rescue StandardError => e
179
+ @crashed = true
180
+ @code = 1
181
+ error e.inspect
182
+ error e.backtrace.last(20).join("\n")
183
+ log 'Try exits gracefully..'
184
+ stop_all
185
+ end
178
186
 
179
- exit(@code || 0)
180
- end
187
+ @threads.map(&:join)
181
188
 
189
+ @code = [@code || 0, 1].max if @crashed
182
190
 
183
- end
191
+ exit(@code || 0)
192
+ end
184
193
 
185
- end
186
194
 
187
195
 
196
+ end
188
197
 
198
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Godko Ivan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-10 00:00:00.000000000 Z
12
+ date: 2018-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: diplomat