Class: JamesBond::MissionKubernetes::ServerHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/james_bond/mission_kubernetes/server_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, config) ⇒ ServerHandler

Returns a new instance of ServerHandler.



9
10
11
12
# File 'lib/james_bond/mission_kubernetes/server_handler.rb', line 9

def initialize(command, config)
  @command = command
  @config  = config.for(env: command.env, command: command.main_command)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/james_bond/mission_kubernetes/server_handler.rb', line 7

def config
  @config
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/james_bond/mission_kubernetes/server_handler.rb', line 14

def run
  tag          = @command.options["tag"]
  app_name     = @config["app_name"]
  image        = @config["image_name"]
  deploy       = "#{app_name}-#{Time.now.to_i}"

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

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

    thread.join
  end
end