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 +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile.lock +1 -1
- data/bin/consul.rb +1 -1
- data/bin/merger.rb +3 -3
- data/bin/terminator.rb +23 -8
- data/lib/docker_toolkit/childprocess.rb +50 -45
- data/lib/docker_toolkit/version.rb +1 -1
- data/lib/docker_toolkit/watcher.rb +149 -139
- 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: 230ac560d5572314c74c9bb672fa96705409d5c599c65f25e8ff7085e485e19e
|
4
|
+
data.tar.gz: b85ee60c82658dd39f1be73a4005b478ba3fda5f263ef1d63371eae6aa3292fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4567251c79471403d0093224d99d57d650bbb2cbb2113487c7cc3ad3d127d75fb59c8f00486bdcd72806ee51a3a8e4074bf182828f2ebbd1c1a2c655edd8e814
|
7
|
+
data.tar.gz: 5140b439d81a523f9a50ab538027ecf439f7074f5b89426175c65334d39093005a5f76a5ffce611173bae8d8398f1b91acd264cdcf8181d6de6b1125908608cd
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
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.
|
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.
|
79
|
+
YAML.load(File.read(dirname + '/' + file))
|
80
80
|
else
|
81
|
-
YAML.
|
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.
|
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
|
-
|
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
|
-
|
54
|
-
|
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
|
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
|
33
|
+
raise Error.new("unsupported platform #{platform_name.inspect}")
|
31
34
|
end
|
32
35
|
end
|
33
|
-
|
36
|
+
alias build new
|
34
37
|
|
35
38
|
def logger
|
36
|
-
return @logger if defined?(@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 ==
|
48
|
+
if RUBY_PLATFORM == 'java'
|
46
49
|
:jruby
|
47
|
-
elsif defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
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
|
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
|
-
|
99
|
-
@posix_spawn = bool
|
100
|
-
end
|
101
|
+
attr_writer :posix_spawn
|
101
102
|
|
102
103
|
def os
|
103
|
-
@os ||=
|
104
|
-
require
|
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
|
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
|
-
|
136
|
+
'x86_64'
|
136
137
|
else
|
137
|
-
|
138
|
+
'i386'
|
138
139
|
end
|
139
140
|
when /amd64|x86_64/
|
140
|
-
|
141
|
+
'x86_64'
|
141
142
|
when /ppc|powerpc/
|
142
|
-
|
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
|
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
|
-
|
175
|
+
private
|
175
176
|
|
176
|
-
|
177
|
-
|
177
|
+
def warn_once(msg)
|
178
|
+
@warnings ||= {}
|
178
179
|
|
179
|
-
|
180
|
-
|
181
|
-
|
180
|
+
unless @warnings[msg]
|
181
|
+
@warnings[msg] = true
|
182
|
+
logger.warn msg
|
183
|
+
end
|
182
184
|
end
|
183
|
-
end
|
184
185
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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?
|
@@ -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
|
-
|
22
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
41
|
+
unless @crashed
|
42
|
+
meta = @procs.detect do |meta|
|
43
|
+
meta[:process].crashed?
|
44
|
+
end
|
61
45
|
|
62
|
-
|
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
|
-
|
66
|
-
|
72
|
+
def add(*cmd)
|
73
|
+
process = ChildProcess.build(*cmd)
|
67
74
|
|
68
|
-
|
69
|
-
|
75
|
+
rerr, werr = IO.pipe
|
76
|
+
rout, wout = IO.pipe
|
70
77
|
|
71
|
-
|
72
|
-
|
78
|
+
process.io.stdout = wout
|
79
|
+
process.io.stderr = werr
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
meta = {
|
82
|
+
cmd: cmd,
|
83
|
+
process: process,
|
84
|
+
stdout: rout,
|
85
|
+
stderr: rerr
|
86
|
+
}
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
94
|
-
|
100
|
+
log "Starting #{meta[:cmd]}"
|
101
|
+
meta[:pid] = meta[:process].start.pid
|
95
102
|
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
138
|
+
trap('CLD') do |*_args|
|
139
|
+
unhandled = @procs.reject do |meta|
|
140
|
+
meta[:handled] || !meta[:process].exited?
|
141
|
+
end
|
136
142
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
161
|
+
if !@crashed && meta[:process].crashed?
|
162
|
+
@crashed = true
|
163
|
+
@code = meta[:process].exit_code
|
164
|
+
@who = meta[:cmd]
|
165
|
+
end
|
146
166
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
167
|
+
unless @stopping
|
168
|
+
log 'Try exits gracefully..'
|
169
|
+
stop_all
|
170
|
+
end
|
152
171
|
|
153
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
180
|
-
end
|
187
|
+
@threads.map(&:join)
|
181
188
|
|
189
|
+
@code = [@code || 0, 1].max if @crashed
|
182
190
|
|
183
|
-
|
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.
|
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-
|
12
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: diplomat
|