uffizzi-cli 2.2.1 → 2.2.2

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
  SHA256:
3
- metadata.gz: d24e9582d66d329f45ab42194dfefbf1558843fbc94578dfc8b2127f0d7f3122
4
- data.tar.gz: fa901b1e7257fc8c9384bcf11c4f41490f767dabbecbf039056aa8b0ed488f38
3
+ metadata.gz: 9f1280afea82284077769e8545880e7420aede5c114a837f3ae2e21482637bac
4
+ data.tar.gz: e9f5235cb793d83b710c291c62f5027f0226d400aa836f9ea56c18f95b474d06
5
5
  SHA512:
6
- metadata.gz: cda766f7ab21158e56cfb5e5ea3dabd0416de0fd1d1671c268347465db66ce4a3864f3aa51be04a6fd789848fd6d86cbf2c3e62437aaaf63803f633b5ababc2e
7
- data.tar.gz: d6e79d2994cc487a7986315371715e15a85d5d42659a4ea21361ac7e289219441ba6ee5e77468dd5380e1ee5a8b9214fed0a4894bb2b7c4f26353647c3954fcc
6
+ metadata.gz: ca04830842f417cb76799ae64c1106866a4d91a7774a07fa3c63fbbe726eac5ab78381c2059ef23a6157948b457984e723bc0e4273d6dbeda48d406379ebe3e4
7
+ data.tar.gz: 119bb3460dc17116351d4553400867b6225e6431614bdb6934d5f4dc1c532c0cf21b7d61a254210ac2a0eb0643d7183a6ac301b29ea352d81f6dc6feb6a339f2
@@ -222,8 +222,8 @@ module Uffizzi
222
222
  def launch_demonise_skaffold(config_path)
223
223
  Uffizzi.process.daemon(true)
224
224
 
225
- at_exit do
226
- DevService.delete_pid
225
+ Uffizzi.at_exit do
226
+ DevService.stop_process
227
227
  end
228
228
 
229
229
  DevService.save_pid
@@ -235,8 +235,8 @@ module Uffizzi
235
235
  end
236
236
 
237
237
  def launch_basic_skaffold(config_path)
238
- at_exit do
239
- DevService.delete_pid
238
+ Uffizzi.at_exit do
239
+ DevService.stop_process
240
240
  end
241
241
 
242
242
  DevService.save_pid
@@ -32,13 +32,27 @@ class DevService
32
32
  dev_pid = running_pid
33
33
  skaffold_pid = running_skaffold_pid
34
34
 
35
- Uffizzi.process.kill('INT', skaffold_pid)
36
- Uffizzi.process.kill('INT', dev_pid)
35
+ begin
36
+ Uffizzi.process.kill('INT', skaffold_pid)
37
+ rescue Errno::ESRCH
38
+ end
39
+
40
+ wait_process_stop(skaffold_pid)
37
41
  delete_pid
42
+
43
+ Uffizzi.process.kill('INT', dev_pid)
38
44
  rescue Errno::ESRCH
39
45
  delete_pid
40
46
  end
41
47
 
48
+ def wait_process_stop(pid)
49
+ loop do
50
+ Uffizzi.process.kill(0, pid)
51
+ sleep(1)
52
+ end
53
+ rescue Errno::ESRCH
54
+ end
55
+
42
56
  def process_running?
43
57
  pid = running_pid
44
58
  return false unless pid.positive?
@@ -50,9 +64,9 @@ class DevService
50
64
  end
51
65
 
52
66
  def start_check_pid_file_existence
53
- Thread.new do
67
+ Uffizzi.thread.new do
54
68
  loop do
55
- Uffizzi.process.kill('QUIT', Uffizzi.process.pid) unless File.exist?(pid_path)
69
+ stop_process unless File.exist?(pid_path)
56
70
  sleep(1)
57
71
  end
58
72
  end
@@ -62,6 +76,8 @@ class DevService
62
76
  Uffizzi.ui.say('Start skaffold')
63
77
  cmd = build_skaffold_dev_command(config_path, options)
64
78
 
79
+ Uffizzi.signal.trap('INT') {}
80
+
65
81
  Uffizzi.ui.popen2e(cmd) do |_stdin, stdout_and_stderr, wait_thr|
66
82
  pid = wait_thr.pid
67
83
  skaffold_pid = find_skaffold_pid(pid)
@@ -198,13 +214,29 @@ class DevService
198
214
  Uffizzi::ConfigHelper.dev_environment
199
215
  end
200
216
 
201
- def find_skaffold_pid(ppid)
202
- ppid_regex = /\w*\s+\d+\s+#{ppid}.*\sskaffold dev/
203
- pid_regex = /\w*\s+(\d+)\s+#{ppid}.*\sskaffold dev/
204
-
217
+ def find_skaffold_pid(pid)
218
+ pid_regex = /\w*#{pid}.*skaffold dev/
205
219
  io = Uffizzi.ui.popen('ps -ef')
206
- ps = io.readlines.detect { |l| l.match?(ppid_regex) }
207
- ps.match(pid_regex)[1]
220
+ processes = io.readlines.select { |l| l.match?(pid_regex) }
221
+
222
+ if processes.count.zero?
223
+ raise StandardError.new('Can\'t find skaffold process pid')
224
+ end
225
+
226
+ # HACK: For MacOS
227
+ if processes.count == 1
228
+ current_pid = processes[0].gsub(/\s+/, ' ').lstrip.split[1]
229
+ return pid if current_pid.to_s == pid.to_s
230
+
231
+ raise StandardError.new('Can\'t find skaffold process pid')
232
+ end
233
+
234
+ # HACK: For Linux
235
+ parent_process = processes
236
+ .map { |ps| ps.gsub(/\s+/, ' ').lstrip.split }
237
+ .detect { |ps| ps[2].to_s == pid.to_s }
238
+
239
+ parent_process[1]
208
240
  end
209
241
  end
210
242
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uffizzi
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
data/lib/uffizzi.rb CHANGED
@@ -38,7 +38,19 @@ module Uffizzi
38
38
  end
39
39
 
40
40
  def process
41
- @process ||= Process
41
+ Process
42
+ end
43
+
44
+ def signal
45
+ Signal
46
+ end
47
+
48
+ def thread
49
+ Thread
50
+ end
51
+
52
+ def at_exit(&block)
53
+ Kernel.at_exit(&block)
42
54
  end
43
55
  end
44
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-10-23 00:00:00.000000000 Z
12
+ date: 2023-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport