Class: JamesBond::MissionKubernetes::BuildHandler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, config) ⇒ BuildHandler

Returns a new instance of BuildHandler.



9
10
11
12
# File 'lib/james_bond/mission_kubernetes/build_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/build_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
# File 'lib/james_bond/mission_kubernetes/build_handler.rb', line 14

def run
  target = "#{config["image_name"]}:#{tag}"
  command = "docker build -t #{target} ."

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

    thread.join
  end

  { tag: tag }
end

#tagObject



31
32
33
34
35
36
37
38
39
# File 'lib/james_bond/mission_kubernetes/build_handler.rb', line 31

def tag
  options = @command.options
  time_tag = "devel-#{Time.now.to_i}"
  @tag ||= if options && options[:tag]
             options[:tag]
           else
             time_tag
           end
end