class JamesBond::MissionKubernetes::TestHandler

Attributes

config[RW]

Public Class Methods

new(command, config) click to toggle source
# File lib/james_bond/mission_kubernetes/test_handler.rb, line 9
def initialize(command, config)
  @command = command
  @config  = config.for(env: command.env, command: command.main_command)
end

Public Instance Methods

run() click to toggle source
# File lib/james_bond/mission_kubernetes/test_handler.rb, line 14
def run
  tag          = @command.options["tag"]
  app_name     = @config["app_name"]
  test_command = @config["command"]
  image        = @config["image_name"]
  deploy       = "#{app_name}-#{Time.now.to_i}"

  command = [
    "kubectl run #{deploy}",
    "--image=#{image}:#{tag}",
    "--restart=Never",
    "--command --attach --rm",
    "-- #{test_command}",
  ].join(" ")

  Open3.popen3(command) do |stdin, stdout, stderr, thread|
    Thread.new do
      until (line = stdout.gets).nil? do
        puts line
      end
    end

    Thread.new do
      until (line = stderr.gets).nil? do
        puts line
      end
    end

    thread.join
  end
end