Class: Linecook::Squashfs

Inherits:
Object
  • Object
show all
Defined in:
lib/linecook-gem/packager/squashfs.rb

Constant Summary collapse

EXCLUDE_PROFILES =
{
  common: [
    'dev/*',
    'sys/*',
    'proc/*',
    'run/*',
    'tmp/*',
    'home/kitchen',
    'etc/sudoers.d/kitchen',
    '.docker*',
  ],
  ubuntu: [
    'usr/src',
    'var/lib/apt/lists/archive*',
    'var/cache/apt/archives*'
  ]
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Squashfs

Returns a new instance of Squashfs.


28
29
30
31
32
33
34
35
# File 'lib/linecook-gem/packager/squashfs.rb', line 28

def initialize(config)
  @excludes = []
  @excludes << EXCLUDE_PROFILES[:common]
  @excludes << EXCLUDE_PROFILES[config[:distro]] if config[:distro]
  @excludes << config[:excludes] if config[:excludes]
  @excludes.flatten!
  @outdir = config[:outdir] || Dir.pwd
end

Instance Method Details

#package(image) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/linecook-gem/packager/squashfs.rb', line 37

def package(image)
  FileUtils.mkdir_p(@outdir)
  tmpdir = Dir.mktmpdir("#{image.id}-squashfs")
  outfile = File.join(@outdir, "#{image.id}.squashfs")
  puts "Extracting #{image.id} to temporary directory #{tmpdir}..."
  system("sudo tar -C #{tmpdir} -xpf #{image.path}")
  system("sudo mksquashfs #{tmpdir} #{outfile} -noappend -wildcards -e #{@excludes.map { |e| "'#{e}'" }.join(' ')}")
  puts "Squashed image is at #{outfile}"
ensure
  puts "Cleaning up #{tmpdir}..."
  system("sudo rm -rf #{tmpdir}")
end