docker_toolkit 0.1.25 → 0.2.0

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: 44fc48c8b8bf21989b9be9bb59601c1f53a81db9c33bb1948f80c6b9583b77f6
4
- data.tar.gz: c6f049c3a6dbc2a550608b1b82d1446a83c9edfff9b0a603e7c7a53b74ce3869
3
+ metadata.gz: c8561f65ea626741850e599d9d29cb4f5cb8c24e87ef146d07a834f2bcf4d13a
4
+ data.tar.gz: 3a89ccb8404355d91a3070213b3dd1ba66e92f04351cdd0e84d4202877a56640
5
5
  SHA512:
6
- metadata.gz: 0604dac84255d0d23836b7d9dac8687fe462f88948b6434de96febc0dd098c045bba1a1c7a2accff90a10c9fd6f832b7c1dbe3fbeaca4d58764c2825d2994a62
7
- data.tar.gz: 63209b9d5b7cd31a5c03cce3e946ff0596dd1c796d5684f189ec5c1d04280ae700888713d59d65ab7f41bfa00d4d1f212c886c5a74b5a364257df59655bbbbe1
6
+ metadata.gz: 560591c6ddb48aa696cf9e0157d73c0248b9abbb2e347b31c6af45781ea29cf58de26462cc94dbb636a4d769fad1c8819076c374f52216565c13cb0601d75c9a
7
+ data.tar.gz: f7c50dbf342b5e7a6ca14c1f46656028475106d03d9e29bcec72a3797e5e84e5f4db1d0fc081a0f7d64f224261d94fd236c3507186dd8d3ba5cc1819b18b6647
@@ -1,23 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- docker_toolkit (0.1.25)
5
- diplomat
6
- dotenv
7
- json
4
+ docker_toolkit (0.2.0)
5
+ aggkit
8
6
 
9
7
  GEM
10
8
  remote: https://rubygems.org/
11
9
  specs:
10
+ aggkit (0.4.0.9107)
11
+ diplomat
12
+ dotenv
13
+ json
14
+ tty-tree
12
15
  awesome_print (1.8.0)
13
16
  diff-lcs (1.3)
14
- diplomat (2.0.2)
17
+ diplomat (2.0.5)
15
18
  faraday (~> 0.9)
16
- json
17
- dotenv (2.5.0)
18
- faraday (0.15.3)
19
+ dotenv (2.7.1)
20
+ faraday (0.15.4)
19
21
  multipart-post (>= 1.2, < 3)
20
- json (2.1.0)
22
+ json (2.2.0)
21
23
  multipart-post (2.0.0)
22
24
  rake (10.5.0)
23
25
  rspec (3.8.0)
@@ -36,6 +38,7 @@ GEM
36
38
  rspec-core (> 3.3)
37
39
  rspec-set (0.1.3)
38
40
  rspec-support (3.8.0)
41
+ tty-tree (0.2.0)
39
42
 
40
43
  PLATFORMS
41
44
  ruby
@@ -101,9 +101,9 @@ if @opts[:db]
101
101
  @pg[:db] = "-d #{@opts[:db]}"
102
102
  @pg[:user] = "-U #{@opts[:user]}" if @opts[:user]
103
103
  @pg[:pass] = if @opts[:pass] && !@opts[:pass].empty?
104
- "-W #{@opts[:pass]}"
104
+ "PGPASSWORD=#{@opts[:pass]}"
105
105
  else
106
- '-w'
106
+ ''
107
107
  end
108
108
 
109
109
  @pg[:host] = "-h #{@opts[:host]}" if @opts[:host]
@@ -181,7 +181,7 @@ end
181
181
  def wait_for_db
182
182
  log("Waiting for DB: pg://#{@opts[:user]}:#{@opts[:pass]}@#{@opts[:host]}:#{@opts[:port]}/#{@opts[:db]}...")
183
183
  ret = wait_for @opts[:timeout] do
184
- cmd = "psql -lqt #{@pg[:user]} #{@pg[:pass]} #{@pg[:host]} #{@pg[:port]} #{@pg[:db]} 2>/dev/null | cut -d \\| -f 1 | grep -qw #{@opts[:db]} > /dev/null 2>&1"
184
+ cmd = "#{@pg[:pass]} psql -lqt #{@pg[:user]} #{@pg[:host]} #{@pg[:port]} #{@pg[:db]} 2>/dev/null | cut -d \\| -f 1 | grep -qw #{@opts[:db]} > /dev/null 2>&1"
185
185
  system(cmd)
186
186
  $?.success?
187
187
  end
@@ -26,9 +26,7 @@ Gem::Specification.new do |spec|
26
26
  end
27
27
 
28
28
 
29
- spec.add_dependency 'diplomat'
30
- spec.add_dependency 'dotenv'
31
- spec.add_dependency 'json'
29
+ spec.add_dependency 'aggkit'
32
30
 
33
31
  spec.add_development_dependency 'bundler', '~> 1.14'
34
32
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,5 +1,5 @@
1
1
  module DockerToolkit
2
2
 
3
- VERSION = '0.1.25'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
 
5
5
  end
@@ -1,238 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'English'
3
+ require 'aggkit'
4
+ require 'aggkit/watcher'
3
5
 
4
6
  module DockerToolkit
5
-
6
- class Watcher
7
-
8
-
9
- def initialize
10
- @lock = Mutex.new
11
-
12
- @procs = []
13
- @code = 0
14
- @crashed = false
15
- @threads = []
16
- @who = nil
17
- @stopping = false
18
- end
19
-
20
- def stop_all
21
- @stopping = true
22
-
23
- terminating = @procs.reject do |meta|
24
- meta[:handled] || meta[:process].exited?
25
- end
26
-
27
- terminating.each do |meta|
28
- begin
29
- meta[:stdin].close
30
- rescue StandardError
31
- nil
32
- end
33
- if meta[:termcmd].is_a? String
34
- log "Terminating by #{meta[:termcmd].gsub('%PID%', meta[:process].pid.to_s)}..."
35
- output = `#{meta[:termcmd].gsub('%PID%', meta[:process].pid.to_s)}`
36
- if $?.success?
37
- log "ok: #{output}"
38
- else
39
- log "Error: #{output}"
40
- ::Process.kill 'TERM', meta[:process].pid
41
- end
42
- else
43
- ::Process.kill 'TERM', meta[:process].pid
44
- end
45
- end
46
-
47
- terminating.each do |meta|
48
- begin
49
- meta[:process].poll_for_exit(5)
50
- rescue ChildProcess::TimeoutError
51
- meta[:process].stop(1)
52
- meta[:stdout].close
53
- meta[:stderr].close
54
- end
55
- end
56
-
57
- unless @crashed
58
- meta = @procs.detect do |meta|
59
- meta[:process].crashed?
60
- end
61
-
62
- if meta
63
- @crashed = true
64
- @code = meta[:process].exit_code
65
- @who = meta[:cmd]
66
- end
67
- end
68
-
69
- @procs.each do |meta|
70
- begin
71
- meta[:stdout].close
72
- rescue StandardError
73
- nil
74
- end
75
- begin
76
- meta[:stderr].close
77
- rescue StandardError
78
- nil
79
- end
80
- end
81
-
82
- Thread.new do
83
- sleep 2
84
- @threads.each(&:terminate)
85
- end
86
- end
87
-
88
- def add(*cmd)
89
- options = cmd.last
90
- if options.is_a? Hash
91
- cmd.pop
92
- else
93
- options = {}
94
- end
95
-
96
- cmd = cmd.flatten.map{|c| c.to_s.strip }.reject(&:empty?)
97
- process = ChildProcess.build(*cmd)
98
-
99
- rerr, werr = IO.pipe
100
- rout, wout = IO.pipe
101
-
102
- process.io.stdout = wout
103
- process.io.stderr = werr
104
- process.duplex = true
105
-
106
- meta = {
107
- cmd: cmd,
108
- process: process,
109
- stdout: rout,
110
- stderr: rerr,
111
- stdin: process.io.stdin,
112
- termcmd: options[:termcmd]
113
- }
114
-
115
- @threads << Thread.new(meta[:stdout], STDOUT) do |io, out|
116
- loop do
117
- break unless synchro_readline(io, out)
118
- end
119
- end
120
-
121
- @threads << Thread.new(meta[:stderr], STDERR) do |io, out|
122
- loop do
123
- break unless synchro_readline(io, out)
124
- end
125
- end
126
-
127
- log "Starting #{meta[:cmd]}"
128
- meta[:pid] = meta[:process].start.pid
129
-
130
- @procs.push(meta)
131
- meta
132
- end
133
-
134
- def synchro_readline(io, out)
135
- str = io.gets
136
- @lock.synchronize{ out.puts str }
137
- true
138
- rescue StandardError => e
139
- false
140
- end
141
-
142
- def log(msg)
143
- puts "[watcher]: #{msg}"
144
- end
145
-
146
- def error(msg)
147
- STDERR.puts "[watcher]: Error: #{msg}"
148
- end
149
-
150
- def exec
151
- %w[EXIT QUIT].each do |sig|
152
- trap(sig) do
153
- stop_all
154
- end
155
- end
156
-
157
-
158
- %w[INT TERM].each do |sig|
159
- trap(sig) do
160
- log "Catch #{sig}: try exits gracefully.."
161
- stop_all
162
- end
163
- end
164
-
165
- trap('CLD') do |*_args|
166
- unhandled = @procs.reject do |meta|
167
- meta[:handled] || !meta[:process].exited?
168
- end
169
-
170
- completed = unhandled.any? do |meta|
171
- log 'Child finished'
172
- log " Process[#{meta[:pid]}]: #{meta[:cmd]}"
173
- log " status: #{meta[:process].crashed? ? 'crashed' : 'exited'}"
174
- log " code: #{meta[:process].exit_code}"
175
-
176
- meta[:handled] = true
177
- begin
178
- meta[:stdin].close
179
- rescue StandardError
180
- nil
181
- end
182
- begin
183
- meta[:stdout].close
184
- rescue StandardError
185
- nil
186
- end
187
- begin
188
- meta[:stderr].close
189
- rescue StandardError
190
- nil
191
- end
192
-
193
- if !@crashed && meta[:process].crashed?
194
- @crashed = true
195
- @code = meta[:process].exit_code
196
- @who = meta[:cmd]
197
- end
198
-
199
- unless @stopping
200
- log 'Try exits gracefully..'
201
- stop_all
202
- end
203
-
204
- true
205
- end
206
-
207
- unless completed
208
- pid, status = Process.waitpid2(-1, Process::WNOHANG) rescue nil
209
- if status
210
- log "Subprocess finished: #{status.inspect}"
211
- end
212
- end
213
-
214
- end
215
-
216
- begin
217
- yield(self)
218
- rescue StandardError => e
219
- @crashed = true
220
- @code = 1
221
- error e.inspect
222
- error e.backtrace.last(20).join("\n")
223
- log 'Try exits gracefully..'
224
- stop_all
225
- end
226
-
227
- @threads.map(&:join)
228
-
229
- @code = [@code || 0, 1].max if @crashed
230
-
231
- exit(@code || 0)
232
- end
233
-
234
-
235
-
236
- end
237
-
7
+ Watcher = Aggkit::Watcher
238
8
  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.25
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Godko Ivan
@@ -9,38 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-08 00:00:00.000000000 Z
12
+ date: 2019-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: diplomat
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: dotenv
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: json
15
+ name: aggkit
44
16
  requirement: !ruby/object:Gem::Requirement
45
17
  requirements:
46
18
  - - ">="