class JamesBond::MissionBuild::BuildHandler
Attributes
config[RW]
Public Class Methods
new(command, config)
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 9 def initialize(command, config) @command = command @config = config @docker_config = config.docker_config end
Public Instance Methods
run()
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 15 def run image_name = build_image_name dockerfile_name = build_dockerfile_name raise(UnableToFindDockerfileError, dockerfile_path(dockerfile_name)) \ if !dockerfile_exists?(dockerfile_name) command = "docker build -t #{image_name} -f #{dockerfile_name} ." puts "Building docker image \"#{image_name}\" with #{dockerfile_name}.. " Open3.popen3(command) do |stdin, stdout, stderr, thread| Thread.new do until (line = stdout.gets).nil? do puts line end end thread.join end puts "Done!" end
Private Instance Methods
build_dockerfile_name()
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 44 def build_dockerfile_name @docker_config["dockerfile"]["pattern"].gsub("$environment", @command.env) end
build_image_name()
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 37 def build_image_name namespace = @docker_config["image"]["namespace"] name = @docker_config["image"]["name"] tag = build_tag "#{namespace}/#{name}:#{tag}" end
build_tag()
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 48 def build_tag @command.options[:tag] || "devel-#{Time.now.to_i}" end
dockerfile_exists?(dockerfile_name)
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 52 def dockerfile_exists?(dockerfile_name) File.file?(dockerfile_path(dockerfile_name)) end
dockerfile_path(dockerfile_name)
click to toggle source
# File lib/james_bond/mission_build/build_handler.rb, line 56 def dockerfile_path(dockerfile_name) File.join(Dir.pwd, dockerfile_name) end