Added apt lists as a cached dir. This allows vagrant-cachier to support provisioning a debian box while disconnected from the network.
This commit is contained in:
parent
12f7963d1f
commit
95f53e0453
3 changed files with 29 additions and 16 deletions
|
@ -11,22 +11,27 @@ module VagrantPlugins
|
||||||
guest = machine.guest
|
guest = machine.guest
|
||||||
|
|
||||||
if guest.capability?(:apt_cache_dir)
|
if guest.capability?(:apt_cache_dir)
|
||||||
guest_path = guest.capability(:apt_cache_dir)
|
apt_capability = guest.capability(:apt_cache_dir)
|
||||||
|
|
||||||
@env[:cache_dirs] << guest_path
|
|
||||||
|
|
||||||
machine.communicate.tap do |comm|
|
machine.communicate.tap do |comm|
|
||||||
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial")
|
create_apt_symlink(comm, apt_capability[:archives_dir])
|
||||||
unless comm.test("test -L #{guest_path}")
|
create_apt_symlink(comm, apt_capability[:lists_dir])
|
||||||
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def create_apt_symlink(comm, path)
|
||||||
|
@env[:cache_dirs] << path
|
||||||
|
folder = File.basename(path)
|
||||||
|
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/#{folder}/partial")
|
||||||
|
unless comm.test("test -L #{path}")
|
||||||
|
comm.sudo("rm -rf #{path}")
|
||||||
|
comm.sudo("mkdir -p `dirname #{path}`")
|
||||||
|
comm.sudo("ln -s /tmp/vagrant-cache/#{@name}/#{folder} #{path}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module VagrantPlugins
|
||||||
module AptCacheDir
|
module AptCacheDir
|
||||||
def self.apt_cache_dir(machine)
|
def self.apt_cache_dir(machine)
|
||||||
# TODO: Find out if there is a config file we can read from
|
# TODO: Find out if there is a config file we can read from
|
||||||
'/var/cache/apt/archives'
|
{ :archives_dir => '/var/cache/apt/archives', :lists_dir => '/var/lib/apt/lists'}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,21 +24,29 @@ load test_helper
|
||||||
@test "APT cache bucket configures the cache dir properly and keeps cache dir around" {
|
@test "APT cache bucket configures the cache dir properly and keeps cache dir around" {
|
||||||
configure_env "auto-detect-with-provisioning.rb"
|
configure_env "auto-detect-with-provisioning.rb"
|
||||||
|
|
||||||
# Make sure cache dir does not exist
|
# Make sure cache/lista dir does not exist
|
||||||
test ! -d tmp/.vagrant/machines/default/cache/apt
|
test ! -d tmp/.vagrant/machines/default/cache/apt/archives
|
||||||
|
test ! -d tmp/.vagrant/machines/default/cache/apt/lists
|
||||||
|
|
||||||
vagrant_up
|
vagrant_up
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|
||||||
# Make sure packages are being cached
|
# Make sure packages are being cached
|
||||||
test -d tmp/.vagrant/machines/default/cache/apt
|
test -d tmp/.vagrant/machines/default/cache/apt/archives
|
||||||
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/git*.deb`)
|
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/archives/git*.deb`)
|
||||||
|
[ ${#FILES[@]} -gt 0 ]
|
||||||
|
|
||||||
|
test -d tmp/.vagrant/machines/default/cache/apt/lists
|
||||||
|
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/lists/*Packages`)
|
||||||
[ ${#FILES[@]} -gt 0 ]
|
[ ${#FILES[@]} -gt 0 ]
|
||||||
|
|
||||||
vagrant_destroy
|
vagrant_destroy
|
||||||
|
|
||||||
# Make sure packages are not removed between machine rebuilds
|
# Make sure packages are not removed between machine rebuilds
|
||||||
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/git*.deb`)
|
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/archives/git*.deb`)
|
||||||
|
[ ${#FILES[@]} -gt 0 ]
|
||||||
|
|
||||||
|
FILES=(`ls tmp/.vagrant/machines/default/cache/apt/lists/*Packages`)
|
||||||
[ ${#FILES[@]} -gt 0 ]
|
[ ${#FILES[@]} -gt 0 ]
|
||||||
|
|
||||||
empty_cache
|
empty_cache
|
||||||
|
|
Loading…
Reference in a new issue