class Rummager::ImageBuildTask
Image build tasks
Constants
- IMG_BUILD_ARGS
Attributes
add_files[RW]
source[RW]
Public Class Methods
new(task_name, app)
click to toggle source
Calls superclass method
# File lib/rummager/images.rb, line 78 def initialize(task_name, app) super(task_name,app) @build_args = IMG_BUILD_ARGS @actions << Proc.new { @build_args[:'t'] = "#{@repo}:#{fingerprint}" puts "Image '#{@repo}:#{fingerprint}' begin build" if @source.is_a?( Dir ) puts "building from dir '#{Dir.to_s}'" newimage = Docker::Image.build_from_dir( @source, @build_args ) do |c| begin print JSON(c)['stream'] rescue print "WARN JSON parse error with:" + c end end else puts "building from string/tar" if Rake.verbose == true tarout = StringIO.new Gem::Package::TarWriter.new(tarout) do |tarin| tarin.add_file('Dockerfile',0640) { |tf| tf.write(@source) } if @add_files @add_files.each do | af | puts "add:#{af} to tarfile" if Rake.verbose == true tarin.add_file( af, 0640 ) { |tf| tf.write(IO.read(af)) } end end end newimage = Docker::Image.build_from_tar( tarout.tap(&:rewind), @build_args ) do |c| begin print JSON(c)['stream'] rescue print "WARN JSON parse error with:" + c end end end newimage.tag( 'repo' => @repo, 'tag' => 'latest', 'force' => true ) puts "Image '#{@repo}': build complete" puts "#{@build_args} -> #{newimage.json}" if Rake.verbose == true } end
Public Instance Methods
fingerprint()
click to toggle source
# File lib/rummager/images.rb, line 70 def fingerprint @fingerprint ||= fingerprint_sources end
fingerprint_sources()
click to toggle source
# File lib/rummager/images.rb, line 51 def fingerprint_sources content = nil # grab the source string or source directory as the content if @source.is_a?( String ) content = @source # include any added files in the hash if @add_files @add_files.each { |af| content << IO.read(af) } end elsif source.is_a?( Dir ) files = Dir["#{source.path}/**/*"].reject{ |f| File.directory?(f) } content = files.map{|f| File.read(f)}.join else raise ArgumentError, "Unhandled argument: #{source.to_s} is not a String or Dir" end # return an MD5 hash sum Digest::MD5.hexdigest(content) end
needed?()
click to toggle source
# File lib/rummager/images.rb, line 74 def needed? !Docker::Image.all(:all => true).any? { |image| image.info['RepoTags'].any? { |s| s.include?("#{@repo}:#{fingerprint}") } } end