From 3d59cabe51261dc10c1aae4ac121a4783e251bef Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 25 Oct 2023 11:09:06 +0300 Subject: [PATCH] Fix skaffold pid fo macos --- Makefile | 2 +- lib/uffizzi/services/dev_service.rb | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) 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