2013-06-07 22:37:02 -04:00
|
|
|
module VagrantPlugins
|
2013-05-22 19:38:26 -03:00
|
|
|
module Cachier
|
|
|
|
class Bucket
|
|
|
|
def self.inherited(base)
|
|
|
|
@buckets ||= []
|
|
|
|
@buckets << base
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.auto_detect(env)
|
|
|
|
@buckets.each do |bucket|
|
|
|
|
if env[:machine].guest.capability?(bucket.capability)
|
|
|
|
env[:machine].config.cache.enable bucket.bucket_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.bucket_name
|
2013-07-17 13:45:02 +02:00
|
|
|
class_name = self.name.split('::').last
|
|
|
|
class_name.scan(/[A-Z][a-z]*/).map{|x| x.downcase}.join("_")
|
2013-05-22 19:38:26 -03:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.install(name, env, configs)
|
2013-07-17 11:50:44 +02:00
|
|
|
bucket = const_get(name.to_s.split("_").map{|x| x.capitalize}.join(""))
|
2013-05-22 19:38:26 -03:00
|
|
|
bucket.new(name, env, configs).install
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name, env, configs)
|
|
|
|
@name = name
|
|
|
|
@env = env
|
|
|
|
@configs = configs
|
|
|
|
end
|
2014-02-14 01:15:43 -02:00
|
|
|
|
|
|
|
def machine
|
|
|
|
@env[:machine]
|
|
|
|
end
|
|
|
|
|
|
|
|
def guest
|
|
|
|
machine.guest
|
|
|
|
end
|
|
|
|
|
|
|
|
def comm
|
|
|
|
machine.communicate
|
|
|
|
end
|
|
|
|
|
2014-02-21 20:39:40 -03:00
|
|
|
# TODO: "merge" symlink and user_symlink methods
|
2014-02-14 01:15:43 -02:00
|
|
|
def symlink(guest_path, bucket_path = "/tmp/vagrant-cache/#{@name}", create_parent: true)
|
|
|
|
return if @env[:cache_dirs].include?(guest_path)
|
|
|
|
|
|
|
|
@env[:cache_dirs] << guest_path
|
|
|
|
comm.execute("mkdir -p #{bucket_path}")
|
2014-02-21 20:39:40 -03:00
|
|
|
unless symlink?(guest_path)
|
2014-02-14 01:15:43 -02:00
|
|
|
comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent
|
2014-02-21 23:45:21 -03:00
|
|
|
if empty_dir?(bucket_path) && !empty_dir?(guest_path)
|
2014-02-21 20:39:40 -03:00
|
|
|
# Warm up cache with guest machine data
|
|
|
|
comm.sudo("shopt -s dotglob && mv #{guest_path}/* #{bucket_path}")
|
|
|
|
end
|
|
|
|
comm.sudo("rm -rf #{guest_path}")
|
2014-02-14 01:15:43 -02:00
|
|
|
comm.sudo("ln -s #{bucket_path} #{guest_path}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_symlink(guest_path)
|
|
|
|
return if @env[:cache_dirs].include?(guest_path)
|
|
|
|
|
|
|
|
@env[:cache_dirs] << guest_path
|
|
|
|
bucket_path = "/tmp/vagrant-cache/#{@name}"
|
|
|
|
comm.execute("mkdir -p #{bucket_path}")
|
2014-02-21 20:39:40 -03:00
|
|
|
unless symlink?(guest_path)
|
2014-02-14 01:43:59 -02:00
|
|
|
comm.execute("mkdir -p `dirname #{guest_path}`")
|
2014-02-21 23:45:21 -03:00
|
|
|
if empty_dir?(bucket_path) && !empty_dir?(guest_path)
|
2014-02-21 20:39:40 -03:00
|
|
|
# Warm up cache with guest machine data
|
|
|
|
comm.execute("shopt -s dotglob && mv #{guest_path}/* #{bucket_path}")
|
|
|
|
end
|
|
|
|
comm.execute("rm -rf #{guest_path}")
|
2014-02-14 01:15:43 -02:00
|
|
|
comm.execute("ln -s #{bucket_path} #{guest_path}")
|
|
|
|
end
|
|
|
|
end
|
2014-02-21 20:39:40 -03:00
|
|
|
|
|
|
|
def empty_dir?(path)
|
|
|
|
not comm.test("test \"$(ls -A #{path} 2>/dev/null)\"")
|
|
|
|
end
|
|
|
|
|
|
|
|
def symlink?(path)
|
|
|
|
comm.test("test -L #{path}")
|
|
|
|
end
|
2013-05-22 19:38:26 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require_relative "bucket/apt"
|
2013-06-11 15:43:42 -04:00
|
|
|
require_relative "bucket/chef"
|
2013-05-22 19:38:26 -03:00
|
|
|
require_relative "bucket/gem"
|
|
|
|
require_relative "bucket/pacman"
|
|
|
|
require_relative "bucket/yum"
|
2013-06-17 17:22:38 -04:00
|
|
|
require_relative "bucket/rvm"
|
2013-10-13 13:14:05 -07:00
|
|
|
require_relative "bucket/apt_cacher"
|
2014-02-14 00:28:12 -02:00
|
|
|
require_relative "bucket/apt_lists"
|
2013-10-21 11:17:59 +02:00
|
|
|
require_relative "bucket/composer"
|
2013-10-23 15:44:49 +03:00
|
|
|
require_relative "bucket/npm"
|
2013-11-05 15:00:39 +01:00
|
|
|
require_relative "bucket/zypper"
|