⚠️ 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
1c2116f317
commit
437ba6a4cf
12 changed files with 64 additions and 156 deletions
|
@ -29,6 +29,43 @@ module VagrantPlugins
|
||||||
@env = env
|
@env = env
|
||||||
@configs = configs
|
@configs = configs
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,13 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:apt_cache_dir)
|
if guest.capability?(:apt_cache_dir)
|
||||||
guest_path = 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")
|
||||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial")
|
symlink(guest_path)
|
||||||
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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'APT')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'APT')
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,22 +9,10 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:apt_cacher_dir)
|
if guest.capability?(:apt_cacher_dir)
|
||||||
if guest_path = guest.capability(:apt_cacher_dir)
|
if guest_path = guest.capability(:apt_cacher_dir)
|
||||||
if machine.config.cache.enable_nfs
|
if machine.config.cache.enable_nfs
|
||||||
@env[:cache_dirs] << guest_path
|
symlink(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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher')
|
@env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,13 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:apt_lists_dir)
|
if guest.capability?(:apt_lists_dir)
|
||||||
guest_path = 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")
|
||||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial")
|
symlink(guest_path)
|
||||||
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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-lists')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-lists')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:chef_file_cache_path)
|
if guest.capability?(:chef_file_cache_path)
|
||||||
guest_path = guest.capability(:chef_file_cache_path)
|
guest_path = guest.capability(:chef_file_cache_path)
|
||||||
|
symlink(guest_path) if guest_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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Chef')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Chef')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,10 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:composer_path)
|
if guest.capability?(:composer_path)
|
||||||
if composer_path = guest.capability(:composer_path)
|
if composer_path = guest.capability(:composer_path)
|
||||||
bucket_path = "/tmp/vagrant-cache/#{@name}"
|
bucket_path = "/tmp/vagrant-cache/#{@name}"
|
||||||
@env[:cache_dirs] << composer_path
|
symlink(composer_path, create_parent: false)
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer')
|
||||||
|
|
|
@ -7,26 +7,13 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:gemdir)
|
if guest.capability?(:gemdir)
|
||||||
if gemdir_path = guest.capability(:gemdir)
|
if gemdir_path = guest.capability(:gemdir)
|
||||||
prefix = gemdir_path.split('/').last
|
prefix = gemdir_path.split('/').last
|
||||||
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
||||||
machine.communicate.tap do |comm|
|
gem_cache_path = "#{gemdir_path}/cache"
|
||||||
comm.execute("mkdir -p #{bucket_path}")
|
|
||||||
|
|
||||||
gem_cache_path = "#{gemdir_path}/cache"
|
symlink(gem_cache_path, bucket_path)
|
||||||
|
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems')
|
||||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:npm_cache_dir)
|
if guest.capability?(:npm_cache_dir)
|
||||||
guest_path = guest.capability(:npm_cache_dir)
|
guest_path = guest.capability(:npm_cache_dir)
|
||||||
|
user_symlink(guest_path) if guest_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.execute("rm -rf #{guest_path}")
|
|
||||||
comm.execute("mkdir -p `dirname #{guest_path}`")
|
|
||||||
comm.execute("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'npm')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'npm')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,9 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:pacman_cache_dir)
|
if guest.capability?(:pacman_cache_dir)
|
||||||
guest_path = guest.capability(:pacman_cache_dir)
|
guest_path = guest.capability(:pacman_cache_dir)
|
||||||
|
symlink(guest_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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Pacman')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Pacman')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,26 +7,13 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:rvm_path)
|
if guest.capability?(:rvm_path)
|
||||||
if rvm_path = guest.capability(:rvm_path)
|
if rvm_path = guest.capability(:rvm_path)
|
||||||
prefix = rvm_path.split('/').last
|
prefix = rvm_path.split('/').last
|
||||||
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
||||||
machine.communicate.tap do |comm|
|
rvm_cache_path = "#{rvm_path}/archives"
|
||||||
comm.execute("mkdir -p #{bucket_path}")
|
|
||||||
|
|
||||||
rvm_cache_path = "#{rvm_path}/archives"
|
symlink(rvm_cache_path, bucket_path)
|
||||||
|
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RVM')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RVM')
|
||||||
|
|
|
@ -7,25 +7,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:yum_cache_dir)
|
if guest.capability?(:yum_cache_dir)
|
||||||
guest_path = 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
|
# Ensure caching is enabled
|
||||||
|
comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf")
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
symlink(guest_path)
|
||||||
# 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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum')
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,25 +7,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def install
|
||||||
machine = @env[:machine]
|
|
||||||
guest = machine.guest
|
|
||||||
|
|
||||||
if guest.capability?(:zypper_cache_dir)
|
if guest.capability?(:zypper_cache_dir)
|
||||||
guest_path = 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
|
# Ensure caching is enabled
|
||||||
|
comm.sudo("zypper modifyrepo --keep-packages --all")
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
symlink(guest_path)
|
||||||
# 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
|
|
||||||
else
|
else
|
||||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Zypper')
|
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Zypper')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue