Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Add support for caching chef gems (in /opt/chef/embedded). #129

Merged
merged 1 commit into from
Jan 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/buckets/chef_rubygems.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions lib/vagrant-cachier/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def symlink?(path)
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"
Expand Down
25 changes: 25 additions & 0 deletions lib/vagrant-cachier/bucket/chef_gem.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions lib/vagrant-cachier/cap/linux/chef_gemdir.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/vagrant-cachier/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class Plugin < Vagrant.plugin('2')
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
Expand Down