lib/percheron/actions/build.rb in percheron-0.7.16 vs lib/percheron/actions/build.rb in percheron-0.8.0
- old
+ new
@@ -1,14 +1,13 @@
module Percheron
module Actions
class Build
-
include Base
- def initialize(unit, nocache: false, forcerm: false, exec_scripts: true)
+ def initialize(unit, usecache: true, forcerm: false, exec_scripts: true)
@unit = unit
- @nocache = nocache
+ @usecache = usecache
@forcerm = forcerm
@exec_scripts = exec_scripts
end
def execute!
@@ -20,19 +19,21 @@
results.compact.empty? ? nil : unit
end
private
- attr_reader :unit, :nocache, :forcerm, :exec_scripts
+ attr_reader :unit, :usecache, :forcerm, :exec_scripts
+ alias_method :usecache?, :usecache
+ alias_method :forcerm?, :forcerm
alias_method :exec_scripts?, :exec_scripts
def options
{
'dockerfile' => dockerfile,
't' => unit.image_name,
- 'forcerm' => forcerm,
- 'nocache' => nocache
+ 'forcerm' => forcerm?,
+ 'nocache' => !usecache?
}
end
def dockerfile
temp_dockerfile.basename.to_s
@@ -65,14 +66,20 @@
def build!
in_working_directory(base_dir) do
execute_pre_build_scripts!
$logger.info "Building '#{unit.image_name}' image"
Connection.perform(Docker::Image, :build_from_dir, base_dir, options) do |out|
- $logger.debug '%s' % [ out.strip ]
+ $logger.info '%s' % [ extract_content(out) ]
end
end
ensure
remove_temp_dockerfile!
+ end
+
+ def extract_content(out)
+ json = JSON.parse(out)
+ return '' unless json['stream']
+ json['stream'].strip
end
def execute_pre_build_scripts!
return nil if !exec_scripts? && unit.pre_build_scripts.empty?
ExecLocal.new(unit, unit.pre_build_scripts, 'PRE build').execute!