From e89bd1ca2e3fe0d98ab23b21b9b4718393597a1d Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Mon, 17 Jun 2013 17:17:31 -0400 Subject: [PATCH 1/7] first whack at rvm support in vagrant-cachier --- lib/vagrant-cachier/bucket/rvm.rb | 39 +++++++++++++++++++++++++ lib/vagrant-cachier/cap/linux/rvmdir.rb | 21 +++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 lib/vagrant-cachier/bucket/rvm.rb create mode 100644 lib/vagrant-cachier/cap/linux/rvmdir.rb diff --git a/lib/vagrant-cachier/bucket/rvm.rb b/lib/vagrant-cachier/bucket/rvm.rb new file mode 100644 index 0000000..f06abc4 --- /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 + :rvmdir + end + + def install + machine = @env[:machine] + guest = machine.guest + + if guest.capability?(:rvmdir) + if rvmdir_path = guest.capability(:rvmdir) + prefix = rvmdir_path.split('/').last + bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}" + machine.communicate.tap do |comm| + comm.execute("mkdir -p #{bucket_path}") + + rvm_cache_path = "#{rvmdir_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/rvmdir.rb b/lib/vagrant-cachier/cap/linux/rvmdir.rb new file mode 100644 index 0000000..ff896d4 --- /dev/null +++ b/lib/vagrant-cachier/cap/linux/rvmdir.rb @@ -0,0 +1,21 @@ +module VagrantPlugins + module Cachier + module Cap + module Linux + module Rvmdir + def self.rvmdir(machine) + rvmdir = nil + machine.communicate.tap do |comm| + return unless comm.test('rvm info') + comm.execute 'echo $rvm_path' do |buffer, output| + rvmdir = output.chomp if buffer == :stdout + end + end + return rvmdir + end + end + end + end + end +end + From bf10fc4efc6c8525e888a8173ca3a122c107cece Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Mon, 17 Jun 2013 17:22:38 -0400 Subject: [PATCH 2/7] adding requires for the rvm files --- CHANGELOG.md | 2 +- lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/plugin.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 934b3cd..b100538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ IMPROVEMENTS: - Support enabling NFS for root cache folder. [GH-7] - + - Support RVM bucket ## 0.1.0 (June 9, 2013) IMPROVEMENTS: 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/plugin.rb b/lib/vagrant-cachier/plugin.rb index 31a2870..1766ab8 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -10,6 +10,7 @@ module VagrantPlugins guest_capability 'linux', 'gemdir' do require_relative 'cap/linux/gemdir' + require_relative 'cap/linux/rvmdir' Cap::Linux::Gemdir end From 3a9ac6140b1a7ca762b2f5f9464df4933b987639 Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Fri, 21 Jun 2013 15:08:42 -0400 Subject: [PATCH 3/7] loading in the rvmdir classes in the plugin file. This should now work... --- lib/vagrant-cachier/plugin.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 1766ab8..8a1f3c9 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -10,10 +10,14 @@ module VagrantPlugins guest_capability 'linux', 'gemdir' do require_relative 'cap/linux/gemdir' - require_relative 'cap/linux/rvmdir' Cap::Linux::Gemdir end + guest_capability 'linux', 'rvmdir' do + require_relative 'cap/linux/rvmdir' + Cap::Linux::Rvmdir + end + guest_capability 'debian', 'apt_cache_dir' do require_relative 'cap/debian/apt_cache_dir' Cap::Debian::AptCacheDir From 58c8b40faf2f7df8fc66d60139fd4ef0d7ed1a5d Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Tue, 25 Jun 2013 15:19:55 -0400 Subject: [PATCH 4/7] minor changelog updates. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b100538..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: From d4f96f3f75da11335d8a429138ce1b69f0a3741a Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Tue, 25 Jun 2013 15:51:59 -0400 Subject: [PATCH 5/7] renaming rvmdir -> rvm_path --- lib/vagrant-cachier/bucket/rvm.rb | 10 +++++----- .../cap/linux/{rvmdir.rb => rvm_path.rb} | 10 +++++----- lib/vagrant-cachier/plugin.rb | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) rename lib/vagrant-cachier/cap/linux/{rvmdir.rb => rvm_path.rb} (64%) diff --git a/lib/vagrant-cachier/bucket/rvm.rb b/lib/vagrant-cachier/bucket/rvm.rb index f06abc4..c769ebd 100644 --- a/lib/vagrant-cachier/bucket/rvm.rb +++ b/lib/vagrant-cachier/bucket/rvm.rb @@ -3,21 +3,21 @@ module VagrantPlugins class Bucket class Rvm < Bucket def self.capability - :rvmdir + :rvm_path end def install machine = @env[:machine] guest = machine.guest - if guest.capability?(:rvmdir) - if rvmdir_path = guest.capability(:rvmdir) - prefix = rvmdir_path.split('/').last + 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 = "#{rvmdir_path}/archives" + rvm_cache_path = "#{rvm_path}/archives" @env[:cache_dirs] << rvm_cache_path diff --git a/lib/vagrant-cachier/cap/linux/rvmdir.rb b/lib/vagrant-cachier/cap/linux/rvm_path.rb similarity index 64% rename from lib/vagrant-cachier/cap/linux/rvmdir.rb rename to lib/vagrant-cachier/cap/linux/rvm_path.rb index ff896d4..698d13b 100644 --- a/lib/vagrant-cachier/cap/linux/rvmdir.rb +++ b/lib/vagrant-cachier/cap/linux/rvm_path.rb @@ -2,16 +2,16 @@ module VagrantPlugins module Cachier module Cap module Linux - module Rvmdir - def self.rvmdir(machine) - rvmdir = nil + 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| - rvmdir = output.chomp if buffer == :stdout + rvm_path = output.chomp if buffer == :stdout end end - return rvmdir + return rvm_path end end end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 8a1f3c9..0329ad2 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -13,9 +13,9 @@ module VagrantPlugins Cap::Linux::Gemdir end - guest_capability 'linux', 'rvmdir' do - require_relative 'cap/linux/rvmdir' - Cap::Linux::Rvmdir + guest_capability 'linux', 'rvm_path' do + require_relative 'cap/linux/rvm_path' + Cap::Linux::RvmPath end guest_capability 'debian', 'apt_cache_dir' do From 1eccfb2ad4f98aa2d3877e10ed5ec6ba230a00cf Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Tue, 25 Jun 2013 16:54:32 -0400 Subject: [PATCH 6/7] adding rvm installation to the vagrant file --- development/Vagrantfile | 1 + 1 file changed, 1 insertion(+) 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 From 9831b198dc414457ef3a6dab7af373880f91e6cb Mon Sep 17 00:00:00 2001 From: Bill Cromie Date: Mon, 1 Jul 2013 17:01:55 -0400 Subject: [PATCH 7/7] adding rvm info to the docs --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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_