⚠️ Massive refactoring of buckets code ⚠️
Doing this is kinda irresponsible because we don't have any unit testing in place but I've had enough of copy & pasting things around. Although it doesn't make the codebase GREAT, I believe it'll reach a _nice_ status :) Thanks to those changes I realized that skipping configuration of buckets that have already been configured was easier than I thought and should be enough to close GH-85 \o/
This commit is contained in:
parent
b548637e4f
commit
d6bed34302
12 changed files with 64 additions and 156 deletions
|
@ -29,6 +29,43 @@ module VagrantPlugins
|
|||
@env = env
|
||||
@configs = configs
|
||||
end
|
||||
|
||||
def machine
|
||||
@env[:machine]
|
||||
end
|
||||
|
||||
def guest
|
||||
machine.guest
|
||||
end
|
||||
|
||||
def comm
|
||||
machine.communicate
|
||||
end
|
||||
|
||||
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}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent
|
||||
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}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.execute("rm -rf #{guest_path}")
|
||||
comm.execute("mkdir -p `dirname #{guest_path}`") if create_parent
|
||||
comm.execute("ln -s #{bucket_path} #{guest_path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,22 +7,13 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:apt_cache_dir)
|
||||
guest_path = guest.capability(:apt_cache_dir)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
return if @env[:cache_dirs].include?(guest_path)
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'APT')
|
||||
end
|
||||
|
|
|
@ -9,22 +9,10 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:apt_cacher_dir)
|
||||
if guest_path = guest.capability(:apt_cacher_dir)
|
||||
if machine.config.cache.enable_nfs
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher')
|
||||
end
|
||||
|
|
|
@ -7,22 +7,13 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:apt_lists_dir)
|
||||
guest_path = guest.capability(:apt_lists_dir)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
return if @env[:cache_dirs].include?(guest_path)
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-lists')
|
||||
end
|
||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:chef_file_cache_path)
|
||||
guest_path = guest.capability(:chef_file_cache_path)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path) if guest_path
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Chef')
|
||||
end
|
||||
|
|
|
@ -7,22 +7,10 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:composer_path)
|
||||
if composer_path = guest.capability(:composer_path)
|
||||
bucket_path = "/tmp/vagrant-cache/#{@name}"
|
||||
@env[:cache_dirs] << composer_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p #{bucket_path}")
|
||||
|
||||
unless comm.test("test -L #{composer_path}")
|
||||
comm.sudo("rm -rf #{composer_path}")
|
||||
comm.sudo("ln -s #{bucket_path} #{composer_path}")
|
||||
end
|
||||
end
|
||||
symlink(composer_path, create_parent: false)
|
||||
end
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer')
|
||||
|
|
|
@ -7,26 +7,13 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:gemdir)
|
||||
if gemdir_path = guest.capability(:gemdir)
|
||||
prefix = gemdir_path.split('/').last
|
||||
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p #{bucket_path}")
|
||||
|
||||
gem_cache_path = "#{gemdir_path}/cache"
|
||||
|
||||
@env[:cache_dirs] << gem_cache_path
|
||||
|
||||
unless comm.test("test -L #{gem_cache_path}")
|
||||
comm.sudo("rm -rf #{gem_cache_path}")
|
||||
comm.sudo("mkdir -p `dirname #{gem_cache_path}`")
|
||||
comm.sudo("ln -s #{bucket_path} #{gem_cache_path}")
|
||||
end
|
||||
end
|
||||
symlink(gem_cache_path, bucket_path)
|
||||
end
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems')
|
||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:npm_cache_dir)
|
||||
guest_path = guest.capability(:npm_cache_dir)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.execute("rm -rf #{guest_path}")
|
||||
comm.execute("mkdir -p `dirname #{guest_path}`")
|
||||
comm.execute("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
user_symlink(guest_path) if guest_path
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'npm')
|
||||
end
|
||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:pacman_cache_dir)
|
||||
guest_path = guest.capability(:pacman_cache_dir)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Pacman')
|
||||
end
|
||||
|
|
|
@ -7,26 +7,13 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:rvm_path)
|
||||
if rvm_path = guest.capability(:rvm_path)
|
||||
prefix = rvm_path.split('/').last
|
||||
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
||||
machine.communicate.tap do |comm|
|
||||
comm.execute("mkdir -p #{bucket_path}")
|
||||
|
||||
rvm_cache_path = "#{rvm_path}/archives"
|
||||
|
||||
@env[:cache_dirs] << rvm_cache_path
|
||||
|
||||
unless comm.test("test -L #{rvm_cache_path}")
|
||||
comm.sudo("rm -rf #{rvm_cache_path}")
|
||||
comm.sudo("mkdir -p `dirname #{rvm_cache_path}`")
|
||||
comm.sudo("ln -s #{bucket_path} #{rvm_cache_path}")
|
||||
end
|
||||
end
|
||||
symlink(rvm_cache_path, bucket_path)
|
||||
end
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RVM')
|
||||
|
|
|
@ -7,25 +7,14 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:yum_cache_dir)
|
||||
guest_path = guest.capability(:yum_cache_dir)
|
||||
return if @env[:cache_dirs].include?(guest_path)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
# Ensure caching is enabled
|
||||
comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf")
|
||||
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum')
|
||||
end
|
||||
|
|
|
@ -7,25 +7,14 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def install
|
||||
machine = @env[:machine]
|
||||
guest = machine.guest
|
||||
|
||||
if guest.capability?(:zypper_cache_dir)
|
||||
guest_path = guest.capability(:zypper_cache_dir)
|
||||
return if @env[:cache_dirs].include?(guest_path)
|
||||
|
||||
@env[:cache_dirs] << guest_path
|
||||
|
||||
machine.communicate.tap do |comm|
|
||||
# Ensure caching is enabled
|
||||
comm.sudo("zypper modifyrepo --keep-packages --all")
|
||||
|
||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
|
||||
unless comm.test("test -L #{guest_path}")
|
||||
comm.sudo("rm -rf #{guest_path}")
|
||||
comm.sudo("mkdir -p `dirname #{guest_path}`")
|
||||
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
||||
end
|
||||
end
|
||||
symlink(guest_path)
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Zypper')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue