Merge pull request #14 from patcon/14-chef-file-cache-path

Adds `file_cache_path` support for Chef
This commit is contained in:
Patrick Connolly 2013-07-22 09:16:51 -07:00
commit a5b01d2060
11 changed files with 177 additions and 4 deletions

1
.gitignore vendored
View file

@ -15,3 +15,4 @@ test/tmp
test/version_tmp
tmp
.vagrant
development/cookbooks

View file

@ -4,8 +4,10 @@ source 'https://rubygems.org'
gemspec
group :development do
gem 'vagrant', github: 'mitchellh/vagrant'
gem 'vagrant', github: 'mitchellh/vagrant', ref: 'v1.2.4'
gem 'vagrant-librarian-chef'
gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
gem 'vagrant-omnibus'
gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
gem 'rake'
end

View file

@ -12,9 +12,10 @@ GIT
GIT
remote: git://github.com/mitchellh/vagrant.git
revision: cf0e302e34f3def9d5405bb14847b4b0cb67de01
revision: 0219bb87725aac28a97c0e924c310cc97831fd9d
ref: v1.2.4
specs:
vagrant (1.2.5.dev)
vagrant (1.2.4)
childprocess (~> 0.3.7)
erubis (~> 2.7.0)
i18n (~> 0.6.0)
@ -30,16 +31,69 @@ PATH
GEM
remote: https://rubygems.org/
specs:
archive-tar-minitar (0.5.2)
chef (11.4.4)
erubis
highline (>= 1.6.9)
json (>= 1.4.4, <= 1.7.7)
mixlib-authentication (>= 1.3.0)
mixlib-cli (~> 1.3.0)
mixlib-config (>= 1.1.2)
mixlib-log (>= 1.3.0)
mixlib-shellout
net-ssh (~> 2.6)
net-ssh-multi (~> 1.1.0)
ohai (>= 0.6.0)
rest-client (>= 1.0.4, < 1.7.0)
yajl-ruby (~> 1.1)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
erubis (2.7.0)
ffi (1.9.0)
highline (1.6.19)
i18n (0.6.4)
ipaddress (0.8.0)
json (1.7.7)
librarian (0.1.0)
highline
thor (~> 0.15)
librarian-chef (0.0.1)
archive-tar-minitar (>= 0.5.2)
chef (>= 0.10)
librarian (~> 0.1.0)
log4r (1.1.10)
mime-types (1.23)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.3.0)
mixlib-config (1.1.2)
mixlib-log (1.6.0)
mixlib-shellout (1.2.0)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.6.8)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
ohai (6.18.0)
ipaddress
mixlib-cli
mixlib-config
mixlib-log
mixlib-shellout
systemu
yajl-ruby
rake (10.1.0)
rest-client (1.6.7)
mime-types (>= 1.16)
systemu (2.5.2)
thor (0.18.1)
vagrant-librarian-chef (0.1.2)
librarian-chef
vagrant-omnibus (1.1.0)
yajl-ruby (1.1.0)
PLATFORMS
ruby
@ -48,5 +102,7 @@ DEPENDENCIES
rake
vagrant!
vagrant-cachier!
vagrant-librarian-chef
vagrant-lxc!
vagrant-omnibus
vagrant-pristine!

View file

@ -168,6 +168,18 @@ end
Used by Arch Linux, will get configured under guest's `/var/cache/pacman/pkg`.
#### Chef
```ruby
Vagrant.configure("2") do |config|
config.vm.box = 'some-box-using-chef-provisioner'
config.cache.enable :chef
end
```
When a Chef provisioner is detected, this bucket caches the default
`file_cache_path` directory, `/var/chef/cache`. Requires Vagrant 1.2.4+.
#### RubyGems
```ruby
@ -183,7 +195,6 @@ folder under the result of running `gem env gemdir` as the default SSH user (usu
it is already installed before enabling the bucket, otherwise you won't benefit
from this plugin.
#### RVM
```ruby

6
development/Cheffile Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'java'

12
development/Cheffile.lock Normal file
View file

@ -0,0 +1,12 @@
SITE
remote: http://community.opscode.com/api/v1
specs:
chef_handler (1.1.4)
java (1.12.0)
windows (>= 0.0.0)
windows (1.10.0)
chef_handler (>= 0.0.0)
DEPENDENCIES
java (>= 0)

View file

@ -2,7 +2,9 @@
# vi: set ft=ruby :
Vagrant.require_plugin 'vagrant-cachier'
Vagrant.require_plugin 'vagrant-librarian-chef'
Vagrant.require_plugin 'vagrant-lxc'
Vagrant.require_plugin 'vagrant-omnibus'
Vagrant.require_plugin 'vagrant-pristine'
Vagrant.configure("2") do |config|
@ -16,6 +18,18 @@ Vagrant.configure("2") do |config|
vb.vm.network :private_network, ip: "192.168.50.123"
end
config.omnibus.chef_version = :latest
config.vm.provision :chef_solo do |chef|
chef.add_recipe "java::oracle"
chef.json = {
:java => {
:oracle => {
:accept_oracle_download_terms => true
}
}
}
end
debian_like_configs = lambda do |debian|
debian.vm.provision :shell, inline: '
if ! (which bundle > /dev/null); then

View file

@ -34,6 +34,7 @@ module VagrantPlugins
end
require_relative "bucket/apt"
require_relative "bucket/chef"
require_relative "bucket/gem"
require_relative "bucket/pacman"
require_relative "bucket/yum"

View file

@ -0,0 +1,34 @@
module VagrantPlugins
module Cachier
class Bucket
class Chef < Bucket
def self.capability
:chef_file_cache_path
end
def install
machine = @env[:machine]
guest = machine.guest
if guest.capability?(:chef_file_cache_path)
guest_path = guest.capability(:chef_file_cache_path)
@env[:cache_dirs] << guest_path
machine.communicate.tap do |comm|
comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
unless comm.test("test -L #{guest_path}")
comm.sudo("rm -rf #{guest_path}")
comm.sudo("mkdir -p `dirname #{guest_path}`")
comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
end
end
else
# TODO: Raise a better error
raise "You've configured a Chef cache for a guest machine that does not support it!"
end
end
end
end
end
end

View file

@ -0,0 +1,31 @@
module VagrantPlugins
module Cachier
module Cap
module Linux
module ChefFileCachePath
def self.chef_provisioner?(machine)
provisioners = machine.config.vm.provisioners
chef_provisioners = [:chef_solo, :chef_client]
compat_provisioners = provisioners.keep_if { |p| chef_provisioners.include? p.name }
if compat_provisioners.size > 1
raise "One machine is using multiple chef provisioners, which is unsupported."
end
using_chef = compat_provisioners.empty? ? false : true
using_chef
end
def self.chef_file_cache_path(machine)
chef_file_cache_path = nil
# TODO: Determine paths rather than using default.
chef_file_cache_path = '/var/chef/cache' if chef_provisioner?(machine)
return chef_file_cache_path
end
end
end
end
end
end

View file

@ -18,6 +18,11 @@ module VagrantPlugins
Cap::Linux::RvmPath
end
guest_capability 'linux', 'chef_file_cache_path' do
require_relative 'cap/linux/chef_file_cache_path'
Cap::Linux::ChefFileCachePath
end
guest_capability 'debian', 'apt_cache_dir' do
require_relative 'cap/debian/apt_cache_dir'
Cap::Debian::AptCacheDir