vagrant-cachier 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 358ed900ee09d49b65042a0bf76b3d6b888c60b8
4
- data.tar.gz: c24d390fbd5c1fc4446a956c6c65bacb56dee603
3
+ metadata.gz: 9d005d0ebd01b54b6648f88f5c3f1a5f103147f1
4
+ data.tar.gz: 40b706c52c2111de471c191c2a16aff8cfa7f2ef
5
5
  SHA512:
6
- metadata.gz: 2e64ed67cbd86f0fb5ab18583f4a637ba9114f33a3bb64032b20293b09fc41cb1d2677fb1fc8980139efcfad27523bb92c1d5f026b9fa6b38ce43a6efa94899d
7
- data.tar.gz: 266406520e8f8cd08a9e6914399b526813b512fb9279ca21aef489f7c1cf00bda47a0e0db98de047501cd217c367507b4c62cb1698dea9ce2117be27482eac32
6
+ metadata.gz: b2bdb5ddeb225925825c14cc82e79fb21864ca9b969ce0689d98e6cd21196d920ab31f88568bbdc7c5dc07613f036baf751d6809760cc1dc9eb1cd6f5d9ac86d
7
+ data.tar.gz: b00798e93230d7f3c2ddd364d3d584575e68ded7ebe0b47ede21ac9ebc11fb7ecd9f25b665acc8ed26111b4ecef7d3983658949153d3edd40d79220c0054b7f0
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
17
  .vagrant
18
+ development/cookbooks
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [0.3.0](https://github.com/fgrehm/vagrant-cachier/compare/v0.2.0...v0.3.0) (Aug 5, 2013)
2
+
3
+ BACKWARDS INCOMPATIBILITIES:
4
+
5
+ - Machine scoped cache dirs are now kept on `.vagrant/machines/MACHINE/cache`
6
+ to allow downloaded packages to be reused between providers. If a single cache
7
+ directory exists, the plugin will automatically move it to the right place,
8
+ if multiple directories are found, it will halt execution and will error out,
9
+ letting the user know what has to be done in order to fix things.
10
+
11
+ FEATURES:
12
+
13
+ - Add `file_cache_path` support for Chef. [GH-14]
14
+ - Reconfigure buckets before each provisioner. [GH-26] / [GH-32]
15
+
16
+ IMPROVEMENTS:
17
+
18
+ - Don't error out if a bucket is configured for a non-capable guest. [GH-27]
19
+
1
20
  ## [0.2.0](https://github.com/fgrehm/vagrant-cachier/compare/v0.1.0...v0.2.0) (July 10, 2013)
2
21
 
3
22
  FEATURES:
data/Gemfile CHANGED
@@ -4,7 +4,10 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem 'vagrant', github: 'mitchellh/vagrant'
8
- gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
7
+ gem 'vagrant', github: 'mitchellh/vagrant'
8
+ gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc'
9
+ gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine'
10
+ gem 'vagrant-librarian-chef'
11
+ gem 'vagrant-omnibus'
9
12
  gem 'rake'
10
13
  end
data/Gemfile.lock CHANGED
@@ -1,18 +1,23 @@
1
1
  GIT
2
2
  remote: git://github.com/fgrehm/vagrant-lxc.git
3
- revision: 2f88a060c911c466d304768dd349708336f8af1c
3
+ revision: 5ae82681cdedaf2a6f778e005dd65014fc7c2cec
4
4
  specs:
5
- vagrant-lxc (0.3.4)
5
+ vagrant-lxc (0.5.1.dev)
6
+
7
+ GIT
8
+ remote: git://github.com/fgrehm/vagrant-pristine.git
9
+ revision: 5c400d7850fc5f98d9601b59f4c3bd74818650de
10
+ specs:
11
+ vagrant-pristine (0.2.0)
6
12
 
7
13
  GIT
8
14
  remote: git://github.com/mitchellh/vagrant.git
9
- revision: ccfd321ef98dc5c12b180cc3a26f12d870c0eff5
15
+ revision: 16002d03c07f842a23497543129fa99f40f2bbc0
10
16
  specs:
11
- vagrant (1.2.3.dev)
17
+ vagrant (1.2.8.dev)
12
18
  childprocess (~> 0.3.7)
13
19
  erubis (~> 2.7.0)
14
20
  i18n (~> 0.6.0)
15
- json (>= 1.5.1, < 1.8.0)
16
21
  log4r (~> 1.1.9)
17
22
  net-scp (~> 1.1.0)
18
23
  net-ssh (~> 2.6.6)
@@ -20,22 +25,74 @@ GIT
20
25
  PATH
21
26
  remote: .
22
27
  specs:
23
- vagrant-cachier (0.2.0)
28
+ vagrant-cachier (0.3.0)
24
29
 
25
30
  GEM
26
31
  remote: https://rubygems.org/
27
32
  specs:
33
+ archive-tar-minitar (0.5.2)
34
+ chef (11.6.0)
35
+ erubis
36
+ highline (>= 1.6.9)
37
+ json (>= 1.4.4, <= 1.7.7)
38
+ mixlib-authentication (>= 1.3.0)
39
+ mixlib-cli (~> 1.3.0)
40
+ mixlib-config (>= 1.1.2)
41
+ mixlib-log (>= 1.3.0)
42
+ mixlib-shellout
43
+ net-ssh (~> 2.6)
44
+ net-ssh-multi (~> 1.1.0)
45
+ ohai (>= 0.6.0)
46
+ rest-client (>= 1.0.4, < 1.7.0)
47
+ yajl-ruby (~> 1.1)
28
48
  childprocess (0.3.9)
29
49
  ffi (~> 1.0, >= 1.0.11)
30
50
  erubis (2.7.0)
31
- ffi (1.8.1)
51
+ ffi (1.9.0)
52
+ highline (1.6.19)
32
53
  i18n (0.6.4)
54
+ ipaddress (0.8.0)
33
55
  json (1.7.7)
56
+ librarian (0.1.0)
57
+ highline
58
+ thor (~> 0.15)
59
+ librarian-chef (0.0.1)
60
+ archive-tar-minitar (>= 0.5.2)
61
+ chef (>= 0.10)
62
+ librarian (~> 0.1.0)
34
63
  log4r (1.1.10)
35
- net-scp (1.1.0)
64
+ mime-types (1.23)
65
+ mixlib-authentication (1.3.0)
66
+ mixlib-log
67
+ mixlib-cli (1.3.0)
68
+ mixlib-config (1.1.2)
69
+ mixlib-log (1.6.0)
70
+ mixlib-shellout (1.2.0)
71
+ net-scp (1.1.2)
72
+ net-ssh (>= 2.6.5)
73
+ net-ssh (2.6.8)
74
+ net-ssh-gateway (1.2.0)
36
75
  net-ssh (>= 2.6.5)
37
- net-ssh (2.6.7)
38
- rake (10.0.4)
76
+ net-ssh-multi (1.1)
77
+ net-ssh (>= 2.1.4)
78
+ net-ssh-gateway (>= 0.99.0)
79
+ ohai (6.18.0)
80
+ ipaddress
81
+ mixlib-cli
82
+ mixlib-config
83
+ mixlib-log
84
+ mixlib-shellout
85
+ systemu
86
+ yajl-ruby
87
+ rake (10.1.0)
88
+ rest-client (1.6.7)
89
+ mime-types (>= 1.16)
90
+ systemu (2.5.2)
91
+ thor (0.18.1)
92
+ vagrant-librarian-chef (0.1.2)
93
+ librarian-chef
94
+ vagrant-omnibus (1.1.0)
95
+ yajl-ruby (1.1.0)
39
96
 
40
97
  PLATFORMS
41
98
  ruby
@@ -44,4 +101,7 @@ DEPENDENCIES
44
101
  rake
45
102
  vagrant!
46
103
  vagrant-cachier!
104
+ vagrant-librarian-chef
47
105
  vagrant-lxc!
106
+ vagrant-omnibus
107
+ vagrant-pristine!
data/README.md CHANGED
@@ -36,10 +36,8 @@ For more information about available buckets, please see the [configuration sect
36
36
 
37
37
  * Vagrant's built in VirtualBox provider
38
38
  * [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc)
39
-
40
- _It is possibly compatible with the [VMware providers](http://www.vagrantup.com/vmware)
41
- as well but I haven't tried yet._
42
-
39
+ * [VMware providers](http://www.vagrantup.com/vmware) with NFS enabled (See
40
+ [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info)
43
41
 
44
42
  ## How does it work?
45
43
 
@@ -48,12 +46,12 @@ configure things properly from your `Vagrantfile`. Please have a look at
48
46
  the [available cache buckets](#available-cache-buckets) section below for more
49
47
  information.
50
48
 
51
- Under the hood, the plugin will hook into calls to `Vagrant::Builtin::Provision`
52
- during `vagrant up` / `vagrant reload` and will set things up for each configured
53
- cache bucket. Before halting the machine, it will revert the changes required
54
- to set things up by hooking into calls to `Vagrant::Builtin::GracefulHalt` so
55
- that you can repackage the machine for others to use without requiring users to
56
- install the plugin as well.
49
+ Under the hood, the plugin will monkey patch `Vagrant::Builtin::Provision` and
50
+ will set things up for each configured cache bucket before running each defined
51
+ provisioner and after all provisioners are done. Before halting the machine,
52
+ it will revert the changes required to set things up by hooking into calls to
53
+ `Vagrant::Builtin::GracefulHalt` so that you can repackage the machine for others
54
+ to use without requiring users to install the plugin as well.
57
55
 
58
56
  Cache buckets will be available from `/tmp/vagrant-cachier` on your guest and
59
57
  the appropriate folders will get symlinked to the right path _after_ the machine is
@@ -168,6 +166,18 @@ end
168
166
 
169
167
  Used by Arch Linux, will get configured under guest's `/var/cache/pacman/pkg`.
170
168
 
169
+ #### Chef
170
+
171
+ ```ruby
172
+ Vagrant.configure("2") do |config|
173
+ config.vm.box = 'some-box-using-chef-provisioner'
174
+ config.cache.enable :chef
175
+ end
176
+ ```
177
+
178
+ When a Chef provisioner is detected, this bucket caches the default
179
+ `file_cache_path` directory, `/var/chef/cache`. Requires Vagrant 1.2.4+.
180
+
171
181
  #### RubyGems
172
182
 
173
183
  ```ruby
@@ -183,7 +193,6 @@ folder under the result of running `gem env gemdir` as the default SSH user (usu
183
193
  it is already installed before enabling the bucket, otherwise you won't benefit
184
194
  from this plugin.
185
195
 
186
-
187
196
  #### RVM
188
197
 
189
198
  ```ruby
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
4
+ site 'http://community.opscode.com/api/v1'
5
+
6
+ cookbook 'java'
@@ -0,0 +1,12 @@
1
+ SITE
2
+ remote: http://community.opscode.com/api/v1
3
+ specs:
4
+ chef_handler (1.1.4)
5
+ java (1.12.0)
6
+ windows (>= 0.0.0)
7
+ windows (1.10.0)
8
+ chef_handler (>= 0.0.0)
9
+
10
+ DEPENDENCIES
11
+ java (>= 0)
12
+
@@ -2,7 +2,10 @@
2
2
  # vi: set ft=ruby :
3
3
 
4
4
  Vagrant.require_plugin 'vagrant-cachier'
5
+ Vagrant.require_plugin 'vagrant-librarian-chef'
5
6
  Vagrant.require_plugin 'vagrant-lxc'
7
+ Vagrant.require_plugin 'vagrant-omnibus'
8
+ Vagrant.require_plugin 'vagrant-pristine'
6
9
 
7
10
  Vagrant.configure("2") do |config|
8
11
  config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root'#, nfs: true
@@ -15,6 +18,18 @@ Vagrant.configure("2") do |config|
15
18
  vb.vm.network :private_network, ip: "192.168.50.123"
16
19
  end
17
20
 
21
+ config.omnibus.chef_version = :latest
22
+ config.vm.provision :chef_solo do |chef|
23
+ chef.add_recipe "java::oracle"
24
+ chef.json = {
25
+ :java => {
26
+ :oracle => {
27
+ :accept_oracle_download_terms => true
28
+ }
29
+ }
30
+ }
31
+ end
32
+
18
33
  debian_like_configs = lambda do |debian|
19
34
  debian.vm.provision :shell, inline: '
20
35
  if ! (which bundle > /dev/null); then
@@ -0,0 +1,39 @@
1
+ module VagrantPlugins
2
+ module Cachier
3
+ class Action
4
+ class Clean
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new("vagrant::cachier::action::clean")
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+
13
+ if env[:machine].state.id == :running && symlinks.any?
14
+ env[:ui].info I18n.t('vagrant_cachier.cleanup')
15
+ symlinks.each do |symlink|
16
+ remove_symlink symlink
17
+ end
18
+
19
+ File.delete env[:machine].data_dir.join('cache_dirs').to_s
20
+ end
21
+
22
+ @app.call env
23
+ end
24
+
25
+ def symlinks
26
+ # TODO: Check if file exists instead of a blank rescue
27
+ @symlinks ||= @env[:machine].data_dir.join('cache_dirs').read.split rescue []
28
+ end
29
+
30
+ def remove_symlink(symlink)
31
+ if @env[:machine].communicate.test("test -L #{symlink}")
32
+ @logger.debug "Removing symlink for '#{symlink}'"
33
+ @env[:machine].communicate.sudo("unlink #{symlink}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../errors'
2
+
3
+ module VagrantPlugins
4
+ module Cachier
5
+ class Action
6
+ class EnsureSingleCacheRoot
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @env = env
13
+
14
+ # If the cache is scoped to boxes or the existing cache dirs are not
15
+ # provider specific, there's nothing we need to do
16
+ if cache_scoped_to_machine? && provider_specific_cache_dirs.any?
17
+ ensure_single_cache_root_exists!
18
+ end
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def cache_scoped_to_machine?
24
+ @env[:machine].config.cache.scope.to_sym == :machine
25
+ end
26
+
27
+ def ensure_single_cache_root_exists!
28
+ if provider_specific_cache_dirs.size > 1
29
+ cache_dirs = provider_specific_cache_dirs.map do |dir|
30
+ " - #{dir.to_s.gsub(/^#{@env[:root_path]}\//, '')}"
31
+ end
32
+ machine_path = @env[:machine].data_dir.parent.to_s.gsub(/^#{@env[:root_path]}\//, '')
33
+ raise Cachier::Errors::MultipleProviderSpecificCacheDirsFound,
34
+ machine: @env[:machine].name,
35
+ machine_path: machine_path,
36
+ dirs: cache_dirs.join("\n")
37
+ else
38
+ current_path = provider_specific_cache_dirs.first.to_s.gsub(/^#{@env[:root_path]}\//, '')
39
+ new_path = @env[:machine].data_dir.parent.join('cache')
40
+ FileUtils.rm_rf new_path.to_s if new_path.directory?
41
+
42
+ new_path = new_path.to_s.gsub(/^#{@env[:root_path]}\//, '')
43
+ # If we got here there is a single provider specific cacher dir, so
44
+ # let's be nice with users and just fix it ;)
45
+ @env[:ui].warn I18n.t('vagrant_cachier.will_fix_machine_cache_dir',
46
+ current_path: current_path,
47
+ new_path: new_path)
48
+ FileUtils.mv current_path, new_path
49
+ end
50
+ end
51
+
52
+ def provider_specific_cache_dirs
53
+ return @provider_specific_cache_dirs if @provider_specific_cache_dirs
54
+
55
+ # By default data_dir points to ./.vagrant/machines/<NAME>/<PROVIDER>,
56
+ # so we go one directory up
57
+ machine_dir = @env[:machine].data_dir.parent
58
+ @provider_specific_cache_dirs = Pathname.glob(machine_dir.join('*/cache'))
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -34,6 +34,7 @@ module VagrantPlugins
34
34
  end
35
35
 
36
36
  require_relative "bucket/apt"
37
+ require_relative "bucket/chef"
37
38
  require_relative "bucket/gem"
38
39
  require_relative "bucket/pacman"
39
40
  require_relative "bucket/yum"
@@ -24,8 +24,7 @@ module VagrantPlugins
24
24
  end
25
25
  end
26
26
  else
27
- # TODO: Raise a better error
28
- raise "You've configured an APT cache for a guest machine that does not support it!"
27
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'APT')
29
28
  end
30
29
  end
31
30
  end
@@ -0,0 +1,33 @@
1
+ module VagrantPlugins
2
+ module Cachier
3
+ class Bucket
4
+ class Chef < Bucket
5
+ def self.capability
6
+ :chef_file_cache_path
7
+ end
8
+
9
+ def install
10
+ machine = @env[:machine]
11
+ guest = machine.guest
12
+
13
+ if guest.capability?(:chef_file_cache_path)
14
+ guest_path = guest.capability(:chef_file_cache_path)
15
+
16
+ @env[:cache_dirs] << guest_path
17
+
18
+ machine.communicate.tap do |comm|
19
+ comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}")
20
+ unless comm.test("test -L #{guest_path}")
21
+ comm.sudo("rm -rf #{guest_path}")
22
+ comm.sudo("mkdir -p `dirname #{guest_path}`")
23
+ comm.sudo("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}")
24
+ end
25
+ end
26
+ else
27
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Chef')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -29,8 +29,7 @@ module VagrantPlugins
29
29
  end
30
30
  end
31
31
  else
32
- # TODO: Raise a better error
33
- raise "You've configured a RubyGems cache for a guest machine that does not support it!"
32
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems')
34
33
  end
35
34
  end
36
35
  end
@@ -24,8 +24,7 @@ module VagrantPlugins
24
24
  end
25
25
  end
26
26
  else
27
- # TODO: Raise a better error
28
- raise "You've configured a Pacman cache for a guest machine that does not support it!"
27
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Pacman')
29
28
  end
30
29
  end
31
30
  end
@@ -29,8 +29,7 @@ module VagrantPlugins
29
29
  end
30
30
  end
31
31
  else
32
- # TODO: Raise a better error
33
- raise "You've configured a RVM cache for a guest machine that does not support it!"
32
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RVM')
34
33
  end
35
34
  end
36
35
  end
@@ -27,8 +27,7 @@ module VagrantPlugins
27
27
  end
28
28
  end
29
29
  else
30
- # TODO: Raise a better error
31
- raise "You've configured a Yum cache for a guest machine that does not support it!"
30
+ @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum')
32
31
  end
33
32
  end
34
33
  end
@@ -0,0 +1,31 @@
1
+ module VagrantPlugins
2
+ module Cachier
3
+ module Cap
4
+ module Linux
5
+ module ChefFileCachePath
6
+ def self.chef_provisioner?(machine)
7
+ provisioners = machine.config.vm.provisioners
8
+ chef_provisioners = [:chef_solo, :chef_client]
9
+ compat_provisioners = provisioners.keep_if { |p| chef_provisioners.include? p.name }
10
+
11
+ if compat_provisioners.size > 1
12
+ raise "One machine is using multiple chef provisioners, which is unsupported."
13
+ end
14
+
15
+ using_chef = compat_provisioners.empty? ? false : true
16
+
17
+ using_chef
18
+ end
19
+
20
+ def self.chef_file_cache_path(machine)
21
+ chef_file_cache_path = nil
22
+ # TODO: Determine paths rather than using default.
23
+ chef_file_cache_path = '/var/chef/cache' if chef_provisioner?(machine)
24
+
25
+ return chef_file_cache_path
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -4,6 +4,8 @@ module VagrantPlugins
4
4
  attr_accessor :scope, :auto_detect, :enable_nfs
5
5
  attr_reader :buckets
6
6
 
7
+ ALLOWED_SCOPES = %w( box machine )
8
+
7
9
  def initialize
8
10
  @scope = UNSET_VALUE
9
11
  @auto_detect = UNSET_VALUE
@@ -14,6 +16,18 @@ module VagrantPlugins
14
16
  (@buckets ||= {})[bucket] = opts
15
17
  end
16
18
 
19
+ def validate(machine)
20
+ errors = _detected_errors
21
+
22
+ if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s)
23
+ errors << I18n.t('vagrant_cachier.unknown_cache_scope',
24
+ allowed: ALLOWED_SCOPES.inspect,
25
+ cache_scope: @scope)
26
+ end
27
+
28
+ { "vagrant cachier" => errors }
29
+ end
30
+
17
31
  def finalize!
18
32
  return unless enabled?
19
33
 
@@ -0,0 +1,9 @@
1
+ module VagrantPlugins
2
+ module Cachier
3
+ module Errors
4
+ class MultipleProviderSpecificCacheDirsFound < Vagrant::Errors::VagrantError
5
+ error_key(:multiple_provider_specific_cache_dirs_found)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,11 @@
1
+ require_relative 'provision_ext'
2
+ Vagrant::Action::Builtin::Provision.class_eval do
3
+ include VagrantPlugins::Cachier::ProvisionExt
4
+ end
5
+
6
+ # Add our custom translations to the load path
7
+ I18n.load_path << File.expand_path("../../../locales/en.yml", __FILE__)
8
+
1
9
  module VagrantPlugins
2
10
  module Cachier
3
11
  class Plugin < Vagrant.plugin('2')
@@ -18,6 +26,11 @@ module VagrantPlugins
18
26
  Cap::Linux::RvmPath
19
27
  end
20
28
 
29
+ guest_capability 'linux', 'chef_file_cache_path' do
30
+ require_relative 'cap/linux/chef_file_cache_path'
31
+ Cap::Linux::ChefFileCachePath
32
+ end
33
+
21
34
  guest_capability 'debian', 'apt_cache_dir' do
22
35
  require_relative 'cap/debian/apt_cache_dir'
23
36
  Cap::Debian::AptCacheDir
@@ -33,19 +46,27 @@ module VagrantPlugins
33
46
  Cap::Arch::PacmanCacheDir
34
47
  end
35
48
 
36
- install_action_hook = lambda do |hook|
37
- require_relative 'action'
38
- hook.after Vagrant::Action::Builtin::Provision, VagrantPlugins::Cachier::Action::Install
49
+ # TODO: This should be generic, we don't want to hard code every single
50
+ # possible provider action class that Vagrant might have
51
+ ensure_single_cache_root = lambda do |hook|
52
+ require_relative 'action/ensure_single_cache_root'
53
+ hook.before VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::EnsureSingleCacheRoot
54
+
55
+ if defined?(Vagrant::LXC)
56
+ # TODO: Require just the boot action file once its "require dependencies" are sorted out
57
+ require 'vagrant-lxc/action'
58
+ hook.before Vagrant::LXC::Action::Boot, Action::EnsureSingleCacheRoot
59
+ end
39
60
  end
40
- action_hook 'set-shared-cache-on-machine-up', :machine_action_up, &install_action_hook
41
- action_hook 'set-shared-cache-on-machine-reload', :machine_action_reload, &install_action_hook
61
+ action_hook 'ensure-single-cache-root-exists-on-up', :machine_action_up, &ensure_single_cache_root
62
+ action_hook 'ensure-single-cache-root-exists-on-reload', :machine_action_reload, &ensure_single_cache_root
42
63
 
43
64
  clean_action_hook = lambda do |hook|
44
- require_relative 'action'
45
- hook.before Vagrant::Action::Builtin::GracefulHalt, VagrantPlugins::Cachier::Action::Clean
65
+ require_relative 'action/clean'
66
+ hook.before Vagrant::Action::Builtin::GracefulHalt, Action::Clean
46
67
  end
47
- action_hook 'remove-guest-symlinks-on-machine-halt', :machine_action_halt, &clean_action_hook
48
- action_hook 'remove-guest-symlinks-on-machine-package', :machine_action_package, &clean_action_hook
68
+ action_hook 'remove-guest-symlinks-on-halt', :machine_action_halt, &clean_action_hook
69
+ action_hook 'remove-guest-symlinks-on-package', :machine_action_package, &clean_action_hook
49
70
  end
50
71
  end
51
72
  end
@@ -0,0 +1,68 @@
1
+ require_relative 'bucket'
2
+
3
+ module VagrantPlugins
4
+ module Cachier
5
+ module ProvisionExt
6
+ def self.included(base)
7
+ base.class_eval do
8
+ def cachier_debug(msg)
9
+ @logger.debug "[CACHIER] #{msg}"
10
+ end
11
+
12
+ alias :old_call :call
13
+ def call(env)
14
+ return old_call(env) unless env[:machine].config.cache.enabled?
15
+
16
+ @env = env
17
+
18
+ FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
19
+
20
+ nfs_flag = env[:machine].config.cache.enable_nfs
21
+ env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag
22
+
23
+ env[:cache_dirs] = []
24
+
25
+ old_call(env)
26
+
27
+ configure_cache_buckets
28
+ end
29
+
30
+ alias :old_run_provisioner :run_provisioner
31
+ def run_provisioner(*args)
32
+ configure_cache_buckets
33
+ old_run_provisioner(*args)
34
+ end
35
+
36
+ def configure_cache_buckets
37
+ if @env[:machine].config.cache.auto_detect
38
+ Bucket.auto_detect(@env)
39
+ end
40
+
41
+ return unless @env[:machine].config.cache.buckets.any?
42
+
43
+ @env[:ui].info 'Configuring cache buckets...'
44
+ cache_config = @env[:machine].config.cache
45
+ cache_config.buckets.each do |bucket_name, configs|
46
+ cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}"
47
+ Bucket.install(bucket_name, @env, configs)
48
+ end
49
+
50
+ data_file = @env[:machine].data_dir.join('cache_dirs')
51
+ data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") }
52
+ end
53
+
54
+ def cache_root
55
+ @cache_root ||= case @env[:machine].config.cache.scope.to_sym
56
+ when :box
57
+ @env[:home_path].join('cache', @env[:machine].box.name)
58
+ when :machine
59
+ @env[:machine].data_dir.parent.join('cache')
60
+ else
61
+ raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Cachier
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/locales/en.yml ADDED
@@ -0,0 +1,20 @@
1
+ en:
2
+ vagrant_cachier:
3
+ cleanup: |-
4
+ Removing cache buckets symlinks...
5
+ skipping_bucket: |-
6
+ Skipping %{bucket} cache bucket as the guest machine does not support it
7
+ unknown_cache_scope: |-
8
+ Unknown cache scope '%{cache_scope}' (allowed scopes: %{allowed})
9
+ will_fix_machine_cache_dir: |-
10
+ A vagrant-cachier provider specific cache dir was found under
11
+ '%{current_path}' and it will be moved to
12
+ '%{new_path}' as it is the new path for keeping machine
13
+ scoped cache dirs starting with the 0.3.0 version of the plugin.
14
+ vagrant:
15
+ errors:
16
+ multiple_provider_specific_cache_dirs_found: |-
17
+ There are multiple provider specific cache dirs for the '%{machine}' machine:
18
+ %{dirs}
19
+ Please move one of them up to `%{machine_path}/cache` and remove the others
20
+ before bringing the machine up again.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-cachier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Speed up vagrant boxes provisioning
14
14
  email:
@@ -24,23 +24,31 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
+ - development/Cheffile
28
+ - development/Cheffile.lock
27
29
  - development/Vagrantfile
28
30
  - lib/vagrant-cachier.rb
29
- - lib/vagrant-cachier/action.rb
31
+ - lib/vagrant-cachier/action/clean.rb
32
+ - lib/vagrant-cachier/action/ensure_single_cache_root.rb
30
33
  - lib/vagrant-cachier/bucket.rb
31
34
  - lib/vagrant-cachier/bucket/apt.rb
35
+ - lib/vagrant-cachier/bucket/chef.rb
32
36
  - lib/vagrant-cachier/bucket/gem.rb
33
37
  - lib/vagrant-cachier/bucket/pacman.rb
34
38
  - lib/vagrant-cachier/bucket/rvm.rb
35
39
  - lib/vagrant-cachier/bucket/yum.rb
36
40
  - lib/vagrant-cachier/cap/arch/pacman_cache_dir.rb
37
41
  - lib/vagrant-cachier/cap/debian/apt_cache_dir.rb
42
+ - lib/vagrant-cachier/cap/linux/chef_file_cache_path.rb
38
43
  - lib/vagrant-cachier/cap/linux/gemdir.rb
39
44
  - lib/vagrant-cachier/cap/linux/rvm_path.rb
40
45
  - lib/vagrant-cachier/cap/redhat/yum_cache_dir.rb
41
46
  - lib/vagrant-cachier/config.rb
47
+ - lib/vagrant-cachier/errors.rb
42
48
  - lib/vagrant-cachier/plugin.rb
49
+ - lib/vagrant-cachier/provision_ext.rb
43
50
  - lib/vagrant-cachier/version.rb
51
+ - locales/en.yml
44
52
  - vagrant-cachier.gemspec
45
53
  homepage: https://github.com/fgrehm/vagrant-cachier
46
54
  licenses:
@@ -1,90 +0,0 @@
1
- require_relative 'bucket'
2
-
3
- module VagrantPlugins
4
- module Cachier
5
- class Action
6
- class Install
7
- def initialize(app, env)
8
- @app = app
9
- @logger = Log4r::Logger.new("vagrant::cachier::action::install")
10
- end
11
-
12
- def call(env)
13
- return @app.call(env) unless env[:machine].config.cache.enabled?
14
-
15
- @env = env
16
-
17
- FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist?
18
-
19
- nfs_flag = env[:machine].config.cache.enable_nfs
20
- env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache", nfs: nfs_flag
21
-
22
- @app.call env
23
-
24
- env[:cache_dirs] = []
25
-
26
- if env[:machine].config.cache.auto_detect
27
- Bucket.auto_detect(env)
28
- end
29
-
30
- if env[:machine].config.cache.buckets.any?
31
- env[:ui].info 'Configuring cache buckets...'
32
- cache_config = env[:machine].config.cache
33
- cache_config.buckets.each do |bucket_name, configs|
34
- @logger.debug "Installing #{bucket_name} with configs #{configs.inspect}"
35
- Bucket.install(bucket_name, env, configs)
36
- end
37
-
38
- data_file = env[:machine].data_dir.join('cache_dirs')
39
- data_file.open('w') { |f| f.print env[:cache_dirs].join("\n") }
40
- end
41
- end
42
-
43
- def cache_root
44
- @cache_root ||= case @env[:machine].config.cache.scope
45
- when :box
46
- @env[:home_path].join('cache', @env[:machine].box.name)
47
- when :machine
48
- @env[:machine].data_dir.join('cache')
49
- else
50
- raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'"
51
- end
52
- end
53
- end
54
-
55
- class Clean
56
- def initialize(app, env)
57
- @app = app
58
- @logger = Log4r::Logger.new("vagrant::cachier::action::clean")
59
- end
60
-
61
- def call(env)
62
- @env = env
63
-
64
- if env[:machine].state.id == :running && symlinks.any?
65
- env[:ui].info 'Removing cache buckets symlinks...'
66
- symlinks.each do |symlink|
67
- remove_symlink symlink
68
- end
69
-
70
- File.delete env[:machine].data_dir.join('cache_dirs').to_s
71
- end
72
-
73
- @app.call env
74
- end
75
-
76
- def symlinks
77
- # TODO: Check if file exists instead of a blank rescue
78
- @symlinks ||= @env[:machine].data_dir.join('cache_dirs').read.split rescue []
79
- end
80
-
81
- def remove_symlink(symlink)
82
- if @env[:machine].communicate.test("test -L #{symlink}")
83
- @logger.debug "Removing symlink for '#{symlink}'"
84
- @env[:machine].communicate.sudo("unlink #{symlink}")
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end