class Dapp::Dimg::Image::Scratch

Attributes

from_archives[RW]

Public Class Methods

new(**_kwargs) click to toggle source
Calls superclass method
# File lib/dapp/dimg/image/scratch.rb, line 7
def initialize(**_kwargs)
  super
  @from_archives = []
end

Public Instance Methods

add_archive(*archives) click to toggle source
# File lib/dapp/dimg/image/scratch.rb, line 12
def add_archive(*archives)
  @from_archives.concat(archives.flatten)
end
build!(**_kwargs) click to toggle source
# File lib/dapp/dimg/image/scratch.rb, line 16
def build!(**_kwargs)
  @built_id = dapp.shellout!("docker import #{prepared_change} #{archive}").stdout.strip
ensure
  FileUtils.rm_rf(tmp_path)
end

Protected Instance Methods

archive() click to toggle source
# File lib/dapp/dimg/image/scratch.rb, line 26
def archive
  tmp_path('archive.tar').tap do |archive_path|
    tar_write(archive_path) do |common_tar|
      from_archives.each do |from_archive|
        tar_gz_read(from_archive) do |tar|
          tar.each_entry do |entry|
            mode = entry.header.mode
            path = entry.full_name

            if entry.directory?
              common_tar.mkdir path, mode
            elsif entry.symlink?
              common_tar.add_symlink path, entry.header.linkname, mode
            else
              common_tar.add_file path, mode do |tf|
                tf.write entry.read
              end
            end
          end
        end
      end
    end
  end
end
tmp_path(*path) click to toggle source
# File lib/dapp/dimg/image/scratch.rb, line 51
def tmp_path(*path)
  @tmp_path ||= Dir.mktmpdir('dapp-scratch-', dapp.tmp_base_dir)
  dapp.make_path(@tmp_path, *path).expand_path.tap { |p| p.parent.mkpath }
end