Warm up empty buckets with Guest VM files

This commit is contained in:
Fabio Rehm 2014-02-21 20:39:40 -03:00
parent 09966efc26
commit ac4243d85e
2 changed files with 28 additions and 6 deletions

View file

@ -20,9 +20,8 @@ BACKWARDS INCOMPATIBILITY:
FEATURES: FEATURES:
- Warm up cache buckets with files available on guest in case bucket is empty
- Support for offline provisioning of apt-packages by caching `/var/lib/apt/lists` [GH-84] - Support for offline provisioning of apt-packages by caching `/var/lib/apt/lists` [GH-84]
Please note that before warming up the cache for this bucket you'll need to `apt-get update`
so that package lists are downloaded.
- Support for specifying custom cache bucket synced folder opts - Support for specifying custom cache bucket synced folder opts
- Support to force disabe the plugin [GH-72] - Support to force disabe the plugin [GH-72]
- Automatically disable the plugin for cloud providers [GH-45] - Automatically disable the plugin for cloud providers [GH-45]

View file

@ -42,14 +42,20 @@ module VagrantPlugins
machine.communicate machine.communicate
end end
# TODO: "merge" symlink and user_symlink methods
def symlink(guest_path, bucket_path = "/tmp/vagrant-cache/#{@name}", create_parent: true) def symlink(guest_path, bucket_path = "/tmp/vagrant-cache/#{@name}", create_parent: true)
return if @env[:cache_dirs].include?(guest_path) return if @env[:cache_dirs].include?(guest_path)
@env[:cache_dirs] << guest_path @env[:cache_dirs] << guest_path
comm.execute("mkdir -p #{bucket_path}") comm.execute("mkdir -p #{bucket_path}")
unless comm.test("test -L #{guest_path}") unless symlink?(guest_path)
comm.sudo("rm -rf #{guest_path}")
comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent
# Bucket is empty and guest path exists
if empty_dir?(bucket_path) && directory?(guest_path)
# Warm up cache with guest machine data
comm.sudo("shopt -s dotglob && mv #{guest_path}/* #{bucket_path}")
end
comm.sudo("rm -rf #{guest_path}")
comm.sudo("ln -s #{bucket_path} #{guest_path}") comm.sudo("ln -s #{bucket_path} #{guest_path}")
end end
end end
@ -60,12 +66,29 @@ module VagrantPlugins
@env[:cache_dirs] << guest_path @env[:cache_dirs] << guest_path
bucket_path = "/tmp/vagrant-cache/#{@name}" bucket_path = "/tmp/vagrant-cache/#{@name}"
comm.execute("mkdir -p #{bucket_path}") comm.execute("mkdir -p #{bucket_path}")
unless comm.test("test -L #{guest_path}") unless symlink?(guest_path)
comm.execute("rm -rf #{guest_path}")
comm.execute("mkdir -p `dirname #{guest_path}`") comm.execute("mkdir -p `dirname #{guest_path}`")
# Bucket is empty and guest path exists
if empty_dir?(bucket_path) && directory?(guest_path)
# Warm up cache with guest machine data
comm.execute("shopt -s dotglob && mv #{guest_path}/* #{bucket_path}")
end
comm.execute("rm -rf #{guest_path}")
comm.execute("ln -s #{bucket_path} #{guest_path}") comm.execute("ln -s #{bucket_path} #{guest_path}")
end end
end end
def empty_dir?(path)
not comm.test("test \"$(ls -A #{path} 2>/dev/null)\"")
end
def symlink?(path)
comm.test("test -L #{path}")
end
def directory?(path)
comm.test("test -d #{path}")
end
end end
end end
end end