Merge branch 'cache-chef-gems' of https://github.com/jperville/vagrant-cachier
This commit is contained in:
commit
050e9ea464
5 changed files with 69 additions and 0 deletions
18
docs/buckets/chef_rubygems.md
Normal file
18
docs/buckets/chef_rubygems.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Chef RubyGems
|
||||
|
||||
When a Chef installation is detected, this bucket caches its embedded gems.
|
||||
Most of these gems are part of the Chef omnibus package but sometimes cookbooks
|
||||
need to install extra gems to run within the context of a Chef recipe using the
|
||||
`chef_gem` resource.
|
||||
|
||||
The embedded Chef gem location is returned by running the
|
||||
`/opt/chef/embedded/bin/gem env gemdir` command.
|
||||
|
||||
To manually enable it:
|
||||
|
||||
```ruby
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = 'some-box-using-chef-provisioner'
|
||||
config.cache.enable :chef_gem
|
||||
end
|
||||
```
|
|
@ -90,6 +90,7 @@ end
|
|||
require_relative "bucket/apt"
|
||||
require_relative "bucket/chef"
|
||||
require_relative "bucket/gem"
|
||||
require_relative "bucket/chef_gem"
|
||||
require_relative "bucket/pacman"
|
||||
require_relative "bucket/yum"
|
||||
require_relative "bucket/rvm"
|
||||
|
|
25
lib/vagrant-cachier/bucket/chef_gem.rb
Normal file
25
lib/vagrant-cachier/bucket/chef_gem.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module VagrantPlugins
|
||||
module Cachier
|
||||
class Bucket
|
||||
class ChefGem < Bucket
|
||||
def self.capability
|
||||
:chef_gemdir
|
||||
end
|
||||
|
||||
def install
|
||||
if guest.capability?(:chef_gemdir)
|
||||
if gemdir_path = guest.capability(:chef_gemdir)
|
||||
prefix = gemdir_path.split('/').last
|
||||
bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}"
|
||||
gem_cache_path = "#{gemdir_path}/cache"
|
||||
|
||||
symlink(gem_cache_path, bucket_path)
|
||||
end
|
||||
else
|
||||
@env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'ChefRubyGems')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
lib/vagrant-cachier/cap/linux/chef_gemdir.rb
Normal file
20
lib/vagrant-cachier/cap/linux/chef_gemdir.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module VagrantPlugins
|
||||
module Cachier
|
||||
module Cap
|
||||
module Linux
|
||||
module ChefGemdir
|
||||
def self.chef_gemdir(machine)
|
||||
gemdir = nil
|
||||
machine.communicate.tap do |comm|
|
||||
return unless comm.test('test -f /opt/chef/embedded/bin/gem')
|
||||
comm.execute '/opt/chef/embedded/bin/gem env gemdir' do |buffer, output|
|
||||
gemdir = output.chomp if buffer == :stdout
|
||||
end
|
||||
end
|
||||
return gemdir
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,6 +6,11 @@ module VagrantPlugins
|
|||
Cap::Linux::Gemdir
|
||||
end
|
||||
|
||||
guest_capability 'linux', 'chef_gemdir' do
|
||||
require_relative 'cap/linux/chef_gemdir'
|
||||
Cap::Linux::ChefGemdir
|
||||
end
|
||||
|
||||
guest_capability 'linux', 'rvm_path' do
|
||||
require_relative 'cap/linux/rvm_path'
|
||||
Cap::Linux::RvmPath
|
||||
|
|
Loading…
Reference in a new issue