diff --git a/Makefile b/Makefile index 0ab2d538..ee153c95 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ gem_uninstall: gem uninstall uffizzi-cli gem_reinstall: - rm uffizzi-cli-*.gem -f + ls -la | grep uffizzi-cli- | rm -f make gem_uninstall make gem_build_install diff --git a/lib/uffizzi/services/dev_service.rb b/lib/uffizzi/services/dev_service.rb index 515fff96..1857d19f 100644 --- a/lib/uffizzi/services/dev_service.rb +++ b/lib/uffizzi/services/dev_service.rb @@ -214,13 +214,29 @@ def dev_environment Uffizzi::ConfigHelper.dev_environment end - def find_skaffold_pid(ppid) - ppid_regex = /\w*\s+\d+\s+#{ppid}.*\sskaffold dev/ - pid_regex = /\w*\s+(\d+)\s+#{ppid}.*\sskaffold dev/ - + def find_skaffold_pid(pid) + pid_regex = /\w*#{pid}.*skaffold dev/ io = Uffizzi.ui.popen('ps -ef') - ps = io.readlines.detect { |l| l.match?(ppid_regex) } - ps.match(pid_regex)[1] + processes = io.readlines.select { |l| l.match?(pid_regex) } + + if processes.count.zero? + raise StandardError.new('Can\'t find skaffold process pid') + end + + # HACK: For MacOS + if processes.count == 1 + current_pid = processes[0].gsub(/\s+/, ' ').lstrip.split[1] + return pid if current_pid.to_s == pid.to_s + + raise StandardError.new('Can\'t find skaffold process pid') + end + + # HACK: For Linux + parent_process = processes.detect do |ps| + ps.gsub(/\s+/, ' ').lstrip.split[2].to_s == pid.to_s + end + + parent_process[1] end end end