module Retag::Utils
Public Instance Methods
cmd!(cmd, capture: false, logger: $logger)
click to toggle source
# File lib/retag/utils.rb, line 7 def cmd!(cmd, capture: false, logger: $logger) $cmdnum ||= 0 $cmdnum += 1 tag = $cmdnum.to_s.rjust(3, '0') output = '' logger.tagged("CMD#{tag}".colorize(:light_black)) { logger.debug cmd.colorize(:light_black) } code = Open3.popen3(cmd) do |stdin, stdout, stderr, thr| stdin.close_write files = [stdout, stderr] until files.empty? ready = IO.select(files) readable = ready[0] readable.each do |f| begin line = f.readline if f == stderr logger.tagged("ERR#{tag}") { logger.error(line.strip) } else output += line logger.tagged("OUT#{tag}") { logger.info(line.strip) } unless capture end rescue EOFError => e files.delete f end end end thr.value end raise "Execution failed #{code}: #{cmd}" unless code.success? output end
dockerauth(hostname)
click to toggle source
# File lib/retag/utils.rb, line 46 def dockerauth(hostname) json = ENV['DOCKER_AUTH_CONFIG'].presence || File.read(File.expand_path('~/.docker/config.json')) auth = JSON.parse(json).dig('auths', hostname, 'auth') Base64.decode64(auth) if auth end