require 'picsolve_docker_builder/base' module PicsolveDockerBuilder module Builder # File helper to add files to tars class File include PicsolveDockerBuilder::Base attr_reader :path def initialize(path, opts = {}) @opts = opts @path = path end def content return @opts[:content] if @opts.key? :content return read_source if @opts.key? :source fail 'No content found' end def destination @opts[:destination] end def add_to_image? @opts.key? :destination end def source @opts[:source] end def mode ::File.stat(source).mode end def add_to_tar(tar) log.debug "add file from #{source} to #{path} in tar" tar.add_file path, mode do |tf| ::File.open(source, 'rb') { |f| tf.write f.read } end end end end end