diff --git a/CHANGELOG.md b/CHANGELOG.md index 934b3cd..4b445c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ ## 0.1.1 (unreleased) -IMPROVEMENTS: +FEATURES: - Support enabling NFS for root cache folder. [GH-7] + - Support RVM bucket + ## 0.1.0 (June 9, 2013) IMPROVEMENTS: diff --git a/README.md b/README.md index 67b503b..135c8df 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,21 @@ it is already installed before enabling the bucket, otherwise you won't benefit from this plugin. +#### RVM + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-box-with-ruby-installed' + config.cache.enable :rvm +end +``` + +Compatible with probably with any type of linux guest distro, will hook into the `cache` +folder under the result of running `rvm info` as the default SSH user (usualy +`vagrant`) on your guest. If you use rvm on the guest machine, make sure +it is already installed before enabling the bucket, otherwise you won't benefit +from this plugin. + ## Finding out disk space used by buckets _TODO_ diff --git a/development/Vagrantfile b/development/Vagrantfile index 919e523..fb00d2d 100644 --- a/development/Vagrantfile +++ b/development/Vagrantfile @@ -54,4 +54,5 @@ Vagrant.configure("2") do |config| time sudo pacman -Syu --noconfirm libffi git fi' end + config.vm.provision :shell, inline: '\curl -L https://get.rvm.io | bash -s stable' end diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index af3b3b4..8462618 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -37,3 +37,4 @@ require_relative "bucket/apt" require_relative "bucket/gem" require_relative "bucket/pacman" require_relative "bucket/yum" +require_relative "bucket/rvm" diff --git a/lib/vagrant-cachier/bucket/rvm.rb b/lib/vagrant-cachier/bucket/rvm.rb new file mode 100644 index 0000000..c769ebd --- /dev/null +++ b/lib/vagrant-cachier/bucket/rvm.rb @@ -0,0 +1,39 @@ +module VagrantPlugins + module Cachier + class Bucket + class Rvm < Bucket + def self.capability + :rvm_path + 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 + end + else + # TODO: Raise a better error + raise "You've configured a RVM cache for a guest machine that does not support it!" + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/linux/rvm_path.rb b/lib/vagrant-cachier/cap/linux/rvm_path.rb new file mode 100644 index 0000000..698d13b --- /dev/null +++ b/lib/vagrant-cachier/cap/linux/rvm_path.rb @@ -0,0 +1,21 @@ +module VagrantPlugins + module Cachier + module Cap + module Linux + module RvmPath + def self.rvm_path(machine) + rvm_path = nil + machine.communicate.tap do |comm| + return unless comm.test('rvm info') + comm.execute 'echo $rvm_path' do |buffer, output| + rvm_path = output.chomp if buffer == :stdout + end + end + return rvm_path + end + end + end + end + end +end + diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 31a2870..0329ad2 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -13,6 +13,11 @@ module VagrantPlugins Cap::Linux::Gemdir end + guest_capability 'linux', 'rvm_path' do + require_relative 'cap/linux/rvm_path' + Cap::Linux::RvmPath + end + guest_capability 'debian', 'apt_cache_dir' do require_relative 'cap/debian/apt_cache_dir' Cap::Debian::AptCacheDir