Merge pull request #21 from cromulus/rvm_support

Rvm support
This commit is contained in:
Fabio Rehm 2013-07-10 16:46:16 -07:00
commit 5f26cade6c
7 changed files with 85 additions and 1 deletions

View file

@ -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:

View file

@ -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_

View file

@ -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

View file

@ -37,3 +37,4 @@ require_relative "bucket/apt"
require_relative "bucket/gem"
require_relative "bucket/pacman"
require_relative "bucket/yum"
require_relative "bucket/rvm"

View file

@ -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

View file

@ -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

View file

@ -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