From 5a0b2f0f1a5c3fb4e86afcb7713d1b1df6f02ce7 Mon Sep 17 00:00:00 2001 From: Erno Aapa Date: Sat, 25 Jan 2014 06:20:39 +0200 Subject: [PATCH 01/56] Support for extra synced_folder options Added ability to pass extra synced_folder options through new config.cache.sync_opts -configuration. --- README.md | 2 ++ lib/vagrant-cachier/config.rb | 4 +++- lib/vagrant-cachier/provision_ext.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27b0394..b077d21 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ Vagrant.configure("2") do |config| config.cache.auto_detect = true # If you are using VirtualBox, you might want to enable NFS for shared folders # config.cache.enable_nfs = true + # You can pass extra mount options, for example: + # config.cache.sync_opts = {:create = true} end end ``` diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index a450505..f06883b 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -1,7 +1,7 @@ module VagrantPlugins module Cachier class Config < Vagrant.plugin(2, :config) - attr_accessor :scope, :auto_detect, :enable_nfs + attr_accessor :scope, :auto_detect, :enable_nfs, :sync_opts attr_reader :buckets ALLOWED_SCOPES = %w( box machine ) @@ -10,6 +10,7 @@ module VagrantPlugins @scope = UNSET_VALUE @auto_detect = UNSET_VALUE @enable_nfs = UNSET_VALUE + @sync_opts = UNSET_VALUE end def enable(bucket, opts = {}) @@ -34,6 +35,7 @@ module VagrantPlugins @scope = :box if @scope == UNSET_VALUE @auto_detect = false if @auto_detect == UNSET_VALUE @enable_nfs = false if @enable_nfs == UNSET_VALUE + @sync_opts = {} if @sync_opts == UNSET_VALUE @buckets = @buckets ? @buckets.dup : {} end diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb index a04b266..bcdb3d4 100644 --- a/lib/vagrant-cachier/provision_ext.rb +++ b/lib/vagrant-cachier/provision_ext.rb @@ -18,6 +18,8 @@ module VagrantPlugins FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? synced_folder_opts = {id: "vagrant-cache"} + synced_folder_opts.merge!(env[:machine].config.cache.sync_opts) + if env[:machine].config.cache.enable_nfs # REFACTOR: Drop the `nfs: true` argument once we drop support for Vagrant < 1.4 synced_folder_opts.merge!({ nfs: true, type: 'nfs' }) From d6fbb4d0aa536f2898d61c3b9d2c60abf46a2829 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:05:23 -0200 Subject: [PATCH 02/56] Update bundle --- Gemfile.lock | 90 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f0a5e13..4cdfd99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,32 +1,32 @@ GIT remote: git://github.com/fgrehm/vagrant-global-status.git - revision: a0295400a0e47756cbcb8f97ed9f4449b1fb6b56 + revision: 8ae82e2c57b085a030137a40e9b3d232f42e5117 specs: - vagrant-global-status (0.1.1) + vagrant-global-status (0.1.5.dev) GIT remote: git://github.com/fgrehm/vagrant-lxc.git - revision: 225af5622767059708278db29d42941e93d41994 + revision: 1083f100adc4cf1bd20e7eb794ecfda94ef8b365 specs: - vagrant-lxc (0.6.4.dev) + vagrant-lxc (0.7.1.dev) GIT remote: git://github.com/fgrehm/vagrant-pristine.git - revision: 4638491786943bfbf6f115b1fc379f069963fe46 + revision: 503dbc47848c81d0fbfa6840491856f518d244a1 specs: vagrant-pristine (0.3.0) GIT remote: git://github.com/mitchellh/vagrant.git - revision: 57e95323b6600b146167f0f14f83b22dd31dd03f + revision: f2aad2679e02ff91a8f8b2024ba657975dfaf507 specs: - vagrant (1.3.6.dev) + vagrant (1.4.3.dev) childprocess (~> 0.3.7) erubis (~> 2.7.0) i18n (~> 0.6.0) log4r (~> 1.1.9) net-scp (~> 1.1.0) - net-ssh (~> 2.6.6) + net-ssh (>= 2.6.6, < 2.8.0) PATH remote: . @@ -37,68 +37,92 @@ GEM remote: https://rubygems.org/ specs: archive-tar-minitar (0.5.2) - chef (11.6.0) - erubis - highline (>= 1.6.9) + chef (11.8.2) + chef-zero (~> 1.6, >= 1.6.2) + diff-lcs (~> 1.2, >= 1.2.4) + erubis (~> 2.7) + highline (~> 1.6, >= 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 + mime-types (~> 1.16) + mixlib-authentication (~> 1.3) + mixlib-cli (~> 1.3) + mixlib-config (~> 2.0) + mixlib-log (~> 1.3) + mixlib-shellout (~> 1.2) net-ssh (~> 2.6) net-ssh-multi (~> 1.1.0) - ohai (>= 0.6.0) + ohai (~> 6.0) + pry (~> 0.9) + puma (~> 1.6) rest-client (>= 1.0.4, < 1.7.0) yajl-ruby (~> 1.1) + chef-zero (1.7.2) + hashie (~> 2.0) + json + mixlib-log (~> 1.3) + moneta (< 0.7.0) + rack childprocess (0.3.9) ffi (~> 1.0, >= 1.0.11) + coderay (1.1.0) + diff-lcs (1.2.5) erubis (2.7.0) - ffi (1.9.0) - highline (1.6.19) - i18n (0.6.5) + ffi (1.9.3) + hashie (2.0.5) + highline (1.6.20) + i18n (0.6.9) ipaddress (0.8.0) json (1.7.7) - librarian (0.1.0) + librarian (0.1.1) highline thor (~> 0.15) - librarian-chef (0.0.1) + librarian-chef (0.0.2) archive-tar-minitar (>= 0.5.2) chef (>= 0.10) librarian (~> 0.1.0) log4r (1.1.10) - mime-types (1.23) + method_source (0.8.2) + mime-types (1.25.1) mixlib-authentication (1.3.0) mixlib-log - mixlib-cli (1.3.0) - mixlib-config (1.1.2) + mixlib-cli (1.4.0) + mixlib-config (2.1.0) mixlib-log (1.6.0) - mixlib-shellout (1.2.0) + mixlib-shellout (1.3.0) + moneta (0.6.0) net-scp (1.1.2) net-ssh (>= 2.6.5) - net-ssh (2.6.8) + net-ssh (2.7.0) 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) + ohai (6.20.0) ipaddress mixlib-cli mixlib-config mixlib-log mixlib-shellout - systemu + systemu (~> 2.5.2) yajl-ruby - rake (10.1.0) + pry (0.9.12.4) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + puma (1.6.3) + rack (~> 1.2) + rack (1.5.2) + rake (10.1.1) rest-client (1.6.7) mime-types (>= 1.16) + slop (3.4.7) systemu (2.5.2) thor (0.18.1) - vagrant-librarian-chef (0.1.2) + vagrant-librarian-chef (0.1.4) librarian-chef - vagrant-omnibus (1.1.2) - yajl-ruby (1.1.0) + vagrant-omnibus (1.2.1) + yajl-ruby (1.2.0) PLATFORMS ruby From d77f5a6f18f2bd9f817202d9c73ec097dbcd4bd5 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:11:50 -0200 Subject: [PATCH 03/56] We'll drop support for Vagrant < 1.4, that means we should be bumping to 0.6.0 --- CHANGELOG.md | 2 +- Gemfile.lock | 2 +- lib/vagrant-cachier/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b551fd..02df9fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [0.5.2](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.1...master) (unreleased) +## [0.6.0](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.1...master) (unreleased) ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) diff --git a/Gemfile.lock b/Gemfile.lock index 4cdfd99..b7a6537 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,7 +31,7 @@ GIT PATH remote: . specs: - vagrant-cachier (0.5.2.dev) + vagrant-cachier (0.6.0.dev) GEM remote: https://rubygems.org/ diff --git a/lib/vagrant-cachier/version.rb b/lib/vagrant-cachier/version.rb index 193f89f..f3b4dc0 100644 --- a/lib/vagrant-cachier/version.rb +++ b/lib/vagrant-cachier/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Cachier - VERSION = "0.5.2.dev" + VERSION = "0.6.0.dev" end end From d19ea59b8b81091b3da96e8026a7c5ba12be358a Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:13:09 -0200 Subject: [PATCH 04/56] After 5 months I believe it is safe to get rid of this code --- CHANGELOG.md | 4 ++ .../action/ensure_single_cache_root.rb | 64 ------------------- lib/vagrant-cachier/plugin.rb | 15 ----- 3 files changed, 4 insertions(+), 79 deletions(-) delete mode 100644 lib/vagrant-cachier/action/ensure_single_cache_root.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 02df9fd..a5e8b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [0.6.0](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.1...master) (unreleased) +BACKWARDS INCOMPATIBILITY: + + - Automatic handling of multiple machine scoped cache dirs from versions + prior to 0.3.0 of this plugin was removed. ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) diff --git a/lib/vagrant-cachier/action/ensure_single_cache_root.rb b/lib/vagrant-cachier/action/ensure_single_cache_root.rb deleted file mode 100644 index def6375..0000000 --- a/lib/vagrant-cachier/action/ensure_single_cache_root.rb +++ /dev/null @@ -1,64 +0,0 @@ -require_relative '../errors' - -module VagrantPlugins - module Cachier - class Action - class EnsureSingleCacheRoot - def initialize(app, env) - @app = app - end - - def call(env) - @env = env - - # If the cache is scoped to boxes or the existing cache dirs are not - # provider specific, there's nothing we need to do - if cache_scoped_to_machine? && provider_specific_cache_dirs.any? - ensure_single_cache_root_exists! - end - - @app.call(env) - end - - def cache_scoped_to_machine? - @env[:machine].config.cache.enabled? && - @env[:machine].config.cache.scope.to_sym == :machine - end - - def ensure_single_cache_root_exists! - if provider_specific_cache_dirs.size > 1 - cache_dirs = provider_specific_cache_dirs.map do |dir| - " - #{dir.to_s.gsub(/^#{@env[:root_path]}\//, '')}" - end - machine_path = @env[:machine].data_dir.parent.to_s.gsub(/^#{@env[:root_path]}\//, '') - raise Cachier::Errors::MultipleProviderSpecificCacheDirsFound, - machine: @env[:machine].name, - machine_path: machine_path, - dirs: cache_dirs.join("\n") - else - current_path = provider_specific_cache_dirs.first.to_s.gsub(/^#{@env[:root_path]}\//, '') - new_path = @env[:machine].data_dir.parent.join('cache') - FileUtils.rm_rf new_path.to_s if new_path.directory? - - new_path = new_path.to_s.gsub(/^#{@env[:root_path]}\//, '') - # If we got here there is a single provider specific cacher dir, so - # let's be nice with users and just fix it ;) - @env[:ui].warn I18n.t('vagrant_cachier.will_fix_machine_cache_dir', - current_path: current_path, - new_path: new_path) - FileUtils.mv current_path, new_path - end - end - - def provider_specific_cache_dirs - return @provider_specific_cache_dirs if @provider_specific_cache_dirs - - # By default data_dir points to ./.vagrant/machines//, - # so we go one directory up - machine_dir = @env[:machine].data_dir.parent - @provider_specific_cache_dirs = Pathname.glob(machine_dir.join('*/cache')) - end - end - end - end -end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index c6c638f..6d0ffcd 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -70,21 +70,6 @@ module VagrantPlugins Cap::SuSE::ZypperCacheDir end - # TODO: This should be generic, we don't want to hard code every single - # possible provider action class that Vagrant might have - ensure_single_cache_root = lambda do |hook| - require_relative 'action/ensure_single_cache_root' - hook.before VagrantPlugins::ProviderVirtualBox::Action::Boot, Action::EnsureSingleCacheRoot - - if defined?(Vagrant::LXC) - # TODO: Require just the boot action file once its "require dependencies" are sorted out - require 'vagrant-lxc/action' - hook.before Vagrant::LXC::Action::Boot, Action::EnsureSingleCacheRoot - end - end - action_hook 'ensure-single-cache-root-exists-on-up', :machine_action_up, &ensure_single_cache_root - action_hook 'ensure-single-cache-root-exists-on-reload', :machine_action_reload, &ensure_single_cache_root - clean_action_hook = lambda do |hook| require_relative 'action/clean' hook.before Vagrant::Action::Builtin::GracefulHalt, Action::Clean From 5eca9f6be52e66fa44c32b5c7018d0b1cb37c31a Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:22:04 -0200 Subject: [PATCH 05/56] This is no longer needed --- lib/vagrant-cachier/errors.rb | 9 --------- locales/en.yml | 7 ------- 2 files changed, 16 deletions(-) delete mode 100644 lib/vagrant-cachier/errors.rb diff --git a/lib/vagrant-cachier/errors.rb b/lib/vagrant-cachier/errors.rb deleted file mode 100644 index 0f11696..0000000 --- a/lib/vagrant-cachier/errors.rb +++ /dev/null @@ -1,9 +0,0 @@ -module VagrantPlugins - module Cachier - module Errors - class MultipleProviderSpecificCacheDirsFound < Vagrant::Errors::VagrantError - error_key(:multiple_provider_specific_cache_dirs_found) - end - end - end -end diff --git a/locales/en.yml b/locales/en.yml index 8badb39..a8eaefd 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -16,10 +16,3 @@ en: scoped cache dirs starting with the 0.3.0 version of the plugin. unable_to_ssh: |- vagrant-cachier was unable to SSH into the VM to remove symlinks! - vagrant: - errors: - multiple_provider_specific_cache_dirs_found: |- - There are multiple provider specific cache dirs for the '%{machine}' machine: - %{dirs} - Please move one of them up to `%{machine_path}/cache` and remove the others - before bringing the machine up again. From ccdd2ff4f626697076110cdacddca3da4361eb8c Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 2 Jan 2014 01:28:10 -0200 Subject: [PATCH 06/56] We'll probably forget to update these guys, better do it now :) --- README.md | 2 +- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27b0394..d56efb9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ multiple package managers and Linux distros. ## Installation -Make sure you have Vagrant 1.2+ and run: +Make sure you have Vagrant 1.4+ and run: ``` vagrant plugin install vagrant-cachier diff --git a/docs/index.md b/docs/index.md index f149c4d..913eb05 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,7 +9,7 @@ multiple package managers and Linux distros. ## Installation -Make sure you have Vagrant 1.2+ and run: +Make sure you have Vagrant 1.4+ and run: ``` vagrant plugin install vagrant-cachier From 125ae613943e01c3a69d4ae831a14861d9bc0c8f Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 31 Jan 2014 23:02:11 -0200 Subject: [PATCH 07/56] Update docs to reflect what's going to be implemented --- README.md | 19 +++++++++++++++---- docs/index.md | 20 ++++++++++++++++++-- docs/usage.md | 30 ++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 77f2f1e..7680a82 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,21 @@ from within your `Vagrantfile`: Vagrant.configure("2") do |config| config.vm.box = 'your-box' if Vagrant.has_plugin?("vagrant-cachier") + # Enable cache buckets auto detection config.cache.auto_detect = true - # If you are using VirtualBox, you might want to enable NFS for shared folders - # config.cache.enable_nfs = true - # You can pass extra mount options, for example: - # config.cache.sync_opts = {:create = true} + + # If you are using VirtualBox, you might want to use that to enable NFS for + # shared folders. This is also very useful for vagrant-libvirt if you want + # bi-directional sync + config.cache.synced_folder_opts = { + type: 'nfs', + # The nolock option can be useful for an NFSv3 client that wants to avoid the + # NLM sideband protocol. Without this option, apt-get might hang if it tries + # to lock files needed for /var/cache/* operations. All of this can be avoided + # by using NFSv4 everywhere. Please note that the tcp option is not the default. + mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + } + # For more information please check http://docs.vagrantup.com/v2/synced-folders/basic_usage.html end end ``` @@ -43,6 +53,7 @@ http://fgrehm.viewdocs.io/vagrant-cachier. * [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc) * [VMware providers](http://www.vagrantup.com/vmware) with NFS enabled (See [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) +* [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) ## Contributing diff --git a/docs/index.md b/docs/index.md index 913eb05..394541f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,9 +24,24 @@ from within your `Vagrantfile`: Vagrant.configure("2") do |config| config.vm.box = 'your-box' if Vagrant.has_plugin?("vagrant-cachier") + # Enable cache buckets auto detection config.cache.auto_detect = true - # If you are using VirtualBox, you might want to enable NFS for shared folders - # config.cache.enable_nfs = true + + # You can pass in extra mount options for your cache buckets + # from http://docs.vagrantup.com/v2/synced-folders/basic_usage.html + config.cache.synced_folder_opts = { create: true } + + # If you are using VirtualBox, you might want to use that to enable NFS for + # shared folders. This is also very useful for vagrant-libvirt if you want + # bi-directional sync + config.cache.synced_folder_opts = { + type: 'nfs', + # The nolock option can be useful for an NFSv3 client that wants to avoid the + # NLM sideband protocol. Without this option, apt-get might hang if it tries + # to lock files needed for /var/cache/* operations. All of this can be avoided + # by using NFSv4 everywhere. Please note that the tcp option is not the default. + mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + } end end ``` @@ -40,6 +55,7 @@ For more information please check out the links on the menu above. * [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc) * [VMware providers](http://www.vagrantup.com/vmware) with NFS enabled (See [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) +* [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) ## Contributing diff --git a/docs/usage.md b/docs/usage.md index d0538a0..41a27a7 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -4,9 +4,9 @@ This is the easiest way to get started with plugin. By adding the code below to your `Vagrantfile` you can enable automatic detection of supported cache _buckets_. -It is a good practise to wrap plugin specific configuration with `has_plugin?` checks -so the user's Vagrantfiles do not break if plugin is uninstalled or Vagrantfile shared -with people not having the plugin installed. +It is a good practice to wrap plugin specific configuration with `has_plugin?` checks +so the user's Vagrantfiles do not break if vagrant-cachier is uninstalled or +the Vagrantfile is shared with people that do not have the plugin installed. ```ruby Vagrant.configure("2") do |config| @@ -17,7 +17,7 @@ Vagrant.configure("2") do |config| end ``` -This will make vagrant-cachier do its best to find out what is supported on the +This will make `vagrant-cachier` do its best to find out what is supported on the guest machine and will set buckets accordingly. ## Enable buckets as needed @@ -35,6 +35,28 @@ end _Please refer to the "Available Buckets" menu above to find out which buckets are supported._ +## Custom cache buckets synced folders options + +For fine grained control over the cache bucket synced folder options you can use +the `synced_folder_opts` config. That's useful if, for example, you are using +VirtualBox and want to enable NFS for improved performance: + +```ruby +Vagrant.configure("2") do |config| + config.cache.synced_folder_opts = { + type: 'nfs', + # The nolock option can be useful for an NFSv3 client that wants to avoid the + # NLM sideband protocol. Without this option, apt-get might hang if it tries + # to lock files needed for /var/cache/* operations. All of this can be avoided + # by using NFSv4 everywhere. Please note that the tcp option is not the default. + mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + } +end +``` + +Please referer to http://docs.vagrantup.com/v2/synced-folders/basic_usage.html for +more information about the supported parameters. + ## Cache scope By default downloaded packages will get stored on a folder scoped to base boxes From ef0a3f3fc9f93a3537fb5ef26ca4b9311db45d88 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 00:03:20 -0200 Subject: [PATCH 08/56] Replace `enable_nfs` and `sync_opts` config with `synced_folder_opts` --- lib/vagrant-cachier/config.rb | 14 ++++++-------- lib/vagrant-cachier/provision_ext.rb | 8 ++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index f06883b..77a3e97 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -1,16 +1,15 @@ module VagrantPlugins module Cachier class Config < Vagrant.plugin(2, :config) - attr_accessor :scope, :auto_detect, :enable_nfs, :sync_opts + attr_accessor :scope, :auto_detect, :enable_nfs, :synced_folder_opts attr_reader :buckets ALLOWED_SCOPES = %w( box machine ) def initialize - @scope = UNSET_VALUE + @scope = UNSET_VALUE @auto_detect = UNSET_VALUE - @enable_nfs = UNSET_VALUE - @sync_opts = UNSET_VALUE + @synced_folder_opts = UNSET_VALUE end def enable(bucket, opts = {}) @@ -32,11 +31,10 @@ module VagrantPlugins def finalize! return unless enabled? - @scope = :box if @scope == UNSET_VALUE + @scope = :box if @scope == UNSET_VALUE @auto_detect = false if @auto_detect == UNSET_VALUE - @enable_nfs = false if @enable_nfs == UNSET_VALUE - @sync_opts = {} if @sync_opts == UNSET_VALUE - @buckets = @buckets ? @buckets.dup : {} + @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE + @buckets = @buckets ? @buckets.dup : {} end def enabled? diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb index bcdb3d4..e3c446c 100644 --- a/lib/vagrant-cachier/provision_ext.rb +++ b/lib/vagrant-cachier/provision_ext.rb @@ -18,12 +18,8 @@ module VagrantPlugins FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? synced_folder_opts = {id: "vagrant-cache"} - synced_folder_opts.merge!(env[:machine].config.cache.sync_opts) - - if env[:machine].config.cache.enable_nfs - # REFACTOR: Drop the `nfs: true` argument once we drop support for Vagrant < 1.4 - synced_folder_opts.merge!({ nfs: true, type: 'nfs' }) - end + synced_folder_opts.merge!(env[:machine].config.cache.synced_folder_opts) + env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts env[:cache_dirs] = [] From 8260a43aa07c7dd5851db08ca84673c7c72c4f2a Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 00:04:51 -0200 Subject: [PATCH 09/56] Mark `config.enable_nfs` as deprecated --- CHANGELOG.md | 2 ++ lib/vagrant-cachier/config.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e8b89..fc1556b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ BACKWARDS INCOMPATIBILITY: - Automatic handling of multiple machine scoped cache dirs from versions prior to 0.3.0 of this plugin was removed. + - Support for `enable_nfs` has been deprecated and will be removed on 0.7.0, + please use `cache.synced_folder_opts = {type: 'nfs'}` instead. ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index 77a3e97..933bbe8 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -1,7 +1,7 @@ module VagrantPlugins module Cachier class Config < Vagrant.plugin(2, :config) - attr_accessor :scope, :auto_detect, :enable_nfs, :synced_folder_opts + attr_accessor :scope, :auto_detect, :synced_folder_opts attr_reader :buckets ALLOWED_SCOPES = %w( box machine ) @@ -16,6 +16,14 @@ module VagrantPlugins (@buckets ||= {})[bucket] = opts end + def enable_nfs=(value) + puts "The `enable_nfs` config for vagrant-cachier has been deprecated " \ + "and will be removed on 0.7.0, please use " \ + "`synced_folder_opts = { type: 'nfs' }` instead." + + @synced_folder_opts = { type: 'nfs' } if value + end + def validate(machine) errors = _detected_errors From deedb5a11a5dbe0e4bad8f91bd31a479b451b8c5 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 00:06:24 -0200 Subject: [PATCH 10/56] Mention `synced_folder_opts` on CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc1556b..ada6d9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ BACKWARDS INCOMPATIBILITY: - Support for `enable_nfs` has been deprecated and will be removed on 0.7.0, please use `cache.synced_folder_opts = {type: 'nfs'}` instead. +FEATURES: + + - Support for specifying custom cache bucket synced folder opts + ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) BUG FIXES: From bfdb2c53f390279d579bac97d2f77f35b6f22db0 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 02:34:49 -0200 Subject: [PATCH 11/56] Lock vagrant to 1.4.3 --- Gemfile | 2 +- Gemfile.lock | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 995df3d..af80dba 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gemspec group :development do - gem 'vagrant', github: 'mitchellh/vagrant' + gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.4.3' gem 'vagrant-lxc', github: 'fgrehm/vagrant-lxc' gem 'vagrant-pristine', github: 'fgrehm/vagrant-pristine' gem 'vagrant-global-status', github: 'fgrehm/vagrant-global-status' diff --git a/Gemfile.lock b/Gemfile.lock index b7a6537..293aa78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,9 +18,10 @@ GIT GIT remote: git://github.com/mitchellh/vagrant.git - revision: f2aad2679e02ff91a8f8b2024ba657975dfaf507 + revision: 4f0eb9504cc786d5a57a43814427e8eb35407a4c + tag: v1.4.3 specs: - vagrant (1.4.3.dev) + vagrant (1.4.3) childprocess (~> 0.3.7) erubis (~> 2.7.0) i18n (~> 0.6.0) From 5c35320800dad059a28542ef9c480aee283cbd9c Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 02:35:48 -0200 Subject: [PATCH 12/56] Display a warning using Vagrant's UI in case enable_nfs is set --- lib/vagrant-cachier/config.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index 933bbe8..dddc807 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -17,14 +17,18 @@ module VagrantPlugins end def enable_nfs=(value) - puts "The `enable_nfs` config for vagrant-cachier has been deprecated " \ - "and will be removed on 0.7.0, please use " \ - "`synced_folder_opts = { type: 'nfs' }` instead." - - @synced_folder_opts = { type: 'nfs' } if value + # Flag to raise warning on #validate + @_enable_nfs_set = true + @synced_folder_opts = { type: 'nfs', nfs: true } if value end def validate(machine) + if @_enable_nfs_set + machine.ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \ + "and will be removed on 0.7.0, please use " \ + "`synced_folder_opts = { type: 'nfs' }` instead." + end + errors = _detected_errors if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s) From 77def39754bf79d287f6eaf4ea5f9c00beabc4cc Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 02:57:51 -0200 Subject: [PATCH 13/56] Display enable_nfs deprecation warning only once --- lib/vagrant-cachier/config.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index dddc807..1648179 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -10,6 +10,7 @@ module VagrantPlugins @scope = UNSET_VALUE @auto_detect = UNSET_VALUE @synced_folder_opts = UNSET_VALUE + @ui = Vagrant::UI::Colored.new end def enable(bucket, opts = {}) @@ -17,18 +18,15 @@ module VagrantPlugins end def enable_nfs=(value) - # Flag to raise warning on #validate - @_enable_nfs_set = true + # TODO: Show warning!!! + @ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \ + "and will be removed on 0.7.0, please use " \ + "`synced_folder_opts = { type: 'nfs' }` instead.\n" + @synced_folder_opts = { type: 'nfs', nfs: true } if value end def validate(machine) - if @_enable_nfs_set - machine.ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \ - "and will be removed on 0.7.0, please use " \ - "`synced_folder_opts = { type: 'nfs' }` instead." - end - errors = _detected_errors if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s) From a2e541f6a0cf42b757c2b43bd2ced1f8de270ccb Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 04:36:00 -0200 Subject: [PATCH 14/56] When specifying NFS synced folders we need to use a symbol (fix GH-76) --- CHANGELOG.md | 2 +- README.md | 2 +- docs/index.md | 2 +- docs/usage.md | 4 ++-- lib/vagrant-cachier/config.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ada6d9d..58ddd8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ BACKWARDS INCOMPATIBILITY: - Automatic handling of multiple machine scoped cache dirs from versions prior to 0.3.0 of this plugin was removed. - Support for `enable_nfs` has been deprecated and will be removed on 0.7.0, - please use `cache.synced_folder_opts = {type: 'nfs'}` instead. + please use `cache.synced_folder_opts = {type: :nfs}` instead. FEATURES: diff --git a/README.md b/README.md index 7680a82..36cda8c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Vagrant.configure("2") do |config| # shared folders. This is also very useful for vagrant-libvirt if you want # bi-directional sync config.cache.synced_folder_opts = { - type: 'nfs', + type: :nfs, # The nolock option can be useful for an NFSv3 client that wants to avoid the # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided diff --git a/docs/index.md b/docs/index.md index 394541f..4ad4d1c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -35,7 +35,7 @@ Vagrant.configure("2") do |config| # shared folders. This is also very useful for vagrant-libvirt if you want # bi-directional sync config.cache.synced_folder_opts = { - type: 'nfs', + type: :nfs, # The nolock option can be useful for an NFSv3 client that wants to avoid the # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided diff --git a/docs/usage.md b/docs/usage.md index 41a27a7..ef4c047 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -6,7 +6,7 @@ This is the easiest way to get started with plugin. By adding the code below to your `Vagrantfile` you can enable automatic detection of supported cache _buckets_. It is a good practice to wrap plugin specific configuration with `has_plugin?` checks so the user's Vagrantfiles do not break if vagrant-cachier is uninstalled or -the Vagrantfile is shared with people that do not have the plugin installed. +the Vagrantfile is shared with people that don't have the plugin installed. ```ruby Vagrant.configure("2") do |config| @@ -44,7 +44,7 @@ VirtualBox and want to enable NFS for improved performance: ```ruby Vagrant.configure("2") do |config| config.cache.synced_folder_opts = { - type: 'nfs', + type: :nfs, # The nolock option can be useful for an NFSv3 client that wants to avoid the # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index 1648179..6fc8ec2 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -21,9 +21,9 @@ module VagrantPlugins # TODO: Show warning!!! @ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \ "and will be removed on 0.7.0, please use " \ - "`synced_folder_opts = { type: 'nfs' }` instead.\n" + "`synced_folder_opts = { type: :nfs }` instead.\n" - @synced_folder_opts = { type: 'nfs', nfs: true } if value + @synced_folder_opts = { type: :nfs } if value end def validate(machine) From 5b8b5a59d8dd31d1e631dc23dc16f012bc5f2a69 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 16:11:43 -0200 Subject: [PATCH 15/56] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ddd8c..9bca526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ FEATURES: - Support for specifying custom cache bucket synced folder opts +BUG FIXES: + + - Properly fix NFS support for Vagrant 1.4+ [GH-76] + ## [0.5.1](https://github.com/fgrehm/vagrant-cachier/compare/v0.5.0...v0.5.1) (Dec 20, 2013) BUG FIXES: From 9e830dacbd332099da72180775dd9cd4e6beb109 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 16:18:58 -0200 Subject: [PATCH 16/56] Blow up if using vagrant < 1.4.0 --- CHANGELOG.md | 2 ++ lib/vagrant-cachier/plugin.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bca526..4ee07b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ BACKWARDS INCOMPATIBILITY: + - Support for Vagrant < 1.4 is gone, please use a previous plugin version if + you are running Vagrant 1.2 / 1.3 - Automatic handling of multiple machine scoped cache dirs from versions prior to 0.3.0 of this plugin was removed. - Support for `enable_nfs` has been deprecated and will be removed on 0.7.0, diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 6d0ffcd..275e8c3 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -1,3 +1,9 @@ +# TODO: Switch to Vagrant.require_version before 1.0.0 +# see: https://github.com/mitchellh/vagrant/blob/bc55081e9ffaa6820113e449a9f76b293a29b27d/lib/vagrant.rb#L202-L228 +unless Gem::Requirement.new('>= 1.4.0').satisfied_by?(Gem::Version.new(Vagrant::VERSION)) + raise 'vagrant-cachier requires Vagrant >= 1.4.0 in order to work!' +end + require_relative 'provision_ext' Vagrant::Action::Builtin::Provision.class_eval do include VagrantPlugins::Cachier::ProvisionExt From a97af929f194282c900d32ed23d1b4973bd470dc Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 17:21:46 -0200 Subject: [PATCH 17/56] Extract cachier's root bucket directory creation out to a separate action [GH-60] --- .../action/configure_bucket_root.rb | 46 +++++++++++++++++++ lib/vagrant-cachier/plugin.rb | 5 ++ lib/vagrant-cachier/provision_ext.rb | 20 -------- 3 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 lib/vagrant-cachier/action/configure_bucket_root.rb diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb new file mode 100644 index 0000000..70f275a --- /dev/null +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -0,0 +1,46 @@ +require 'timeout' + +module VagrantPlugins + module Cachier + class Action + class ConfigureBucketRoot + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant::cachier::action::clean") + end + + def call(env) + @env = env + + if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled? + setup_buckets_folder + env[:cache_buckets_folder_configured] = true + end + + @app.call env + end + + def setup_buckets_folder + FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? + + synced_folder_opts = {id: "vagrant-cache"} + synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts) + + @env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts + @env[:cache_dirs] = [] + end + + def cache_root + @cache_root ||= case @env[:machine].config.cache.scope.to_sym + when :box + @env[:home_path].join('cache', @env[:machine].box.name) + when :machine + @env[:machine].data_dir.parent.join('cache') + else + raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 275e8c3..8d68e80 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -82,6 +82,11 @@ module VagrantPlugins end action_hook 'remove-guest-symlinks-on-halt', :machine_action_halt, &clean_action_hook action_hook 'remove-guest-symlinks-on-package', :machine_action_package, &clean_action_hook + + action_hook ALL_ACTIONS do |hook| + require_relative 'action/configure_bucket_root' + hook.before Vagrant::Action::Builtin::Provision, Action::ConfigureBucketRoot + end end end end diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb index e3c446c..4c0c384 100644 --- a/lib/vagrant-cachier/provision_ext.rb +++ b/lib/vagrant-cachier/provision_ext.rb @@ -15,15 +15,6 @@ module VagrantPlugins return old_call(env) unless env[:machine].config.cache.enabled? - FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? - - synced_folder_opts = {id: "vagrant-cache"} - synced_folder_opts.merge!(env[:machine].config.cache.synced_folder_opts) - - env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts - - env[:cache_dirs] = [] - old_call(env) configure_cache_buckets @@ -54,17 +45,6 @@ module VagrantPlugins data_file = @env[:machine].data_dir.join('cache_dirs') data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } end - - def cache_root - @cache_root ||= case @env[:machine].config.cache.scope.to_sym - when :box - @env[:home_path].join('cache', @env[:machine].box.name) - when :machine - @env[:machine].data_dir.parent.join('cache') - else - raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" - end - end end end end From 0031a99522f9e300c2637ffbc51a32326fa0c1cd Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 17:50:12 -0200 Subject: [PATCH 18/56] :bomb: monkey patch on Builtin::Provision action \o/ (closes GH-60) --- lib/vagrant-cachier/action/install_buckets.rb | 40 ++++++++++++++ lib/vagrant-cachier/plugin.rb | 15 ++++-- lib/vagrant-cachier/provision_ext.rb | 52 ------------------- 3 files changed, 50 insertions(+), 57 deletions(-) create mode 100644 lib/vagrant-cachier/action/install_buckets.rb delete mode 100644 lib/vagrant-cachier/provision_ext.rb diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb new file mode 100644 index 0000000..f96d947 --- /dev/null +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -0,0 +1,40 @@ +require_relative '../bucket' + +module VagrantPlugins + module Cachier + class Action + class InstallBuckets + def initialize(app, env) + @app = app + end + + def call(env) + @app.call(env) + + @env = env + configure_cache_buckets + end + + def configure_cache_buckets + return unless @env[:machine].config.cache.enabled? + + if @env[:machine].config.cache.auto_detect + Bucket.auto_detect(@env) + end + + return unless @env[:machine].config.cache.buckets.any? + + @env[:ui].info 'Configuring cache buckets...' + cache_config = @env[:machine].config.cache + cache_config.buckets.each do |bucket_name, configs| + # cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" + Bucket.install(bucket_name, @env, configs) + end + + data_file = @env[:machine].data_dir.join('cache_dirs') + data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } + end + end + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 8d68e80..7b20598 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -4,11 +4,6 @@ unless Gem::Requirement.new('>= 1.4.0').satisfied_by?(Gem::Version.new(Vagrant:: raise 'vagrant-cachier requires Vagrant >= 1.4.0 in order to work!' end -require_relative 'provision_ext' -Vagrant::Action::Builtin::Provision.class_eval do - include VagrantPlugins::Cachier::ProvisionExt -end - # Add our custom translations to the load path I18n.load_path << File.expand_path("../../../locales/en.yml", __FILE__) @@ -85,7 +80,17 @@ module VagrantPlugins action_hook ALL_ACTIONS do |hook| require_relative 'action/configure_bucket_root' + require_relative 'action/install_buckets' + hook.before Vagrant::Action::Builtin::Provision, Action::ConfigureBucketRoot + # This will do the initial buckets installation + hook.after Vagrant::Action::Builtin::Provision, Action::InstallBuckets + end + + # This ensure buckets are reconfigured after provisioners runs + action_hook :provisioner_run do |hook| + require_relative 'action/install_buckets' + hook.after :run_provisioner, Action::InstallBuckets end end end diff --git a/lib/vagrant-cachier/provision_ext.rb b/lib/vagrant-cachier/provision_ext.rb deleted file mode 100644 index 4c0c384..0000000 --- a/lib/vagrant-cachier/provision_ext.rb +++ /dev/null @@ -1,52 +0,0 @@ -require_relative 'bucket' - -module VagrantPlugins - module Cachier - module ProvisionExt - def self.included(base) - base.class_eval do - def cachier_debug(msg) - @logger.debug "[CACHIER] #{msg}" - end - - alias :old_call :call - def call(env) - @env = env - - return old_call(env) unless env[:machine].config.cache.enabled? - - old_call(env) - - configure_cache_buckets - end - - alias :old_run_provisioner :run_provisioner - def run_provisioner(*args) - configure_cache_buckets - old_run_provisioner(*args) - end - - def configure_cache_buckets - return unless @env[:machine].config.cache.enabled? - - if @env[:machine].config.cache.auto_detect - Bucket.auto_detect(@env) - end - - return unless @env[:machine].config.cache.buckets.any? - - @env[:ui].info 'Configuring cache buckets...' - cache_config = @env[:machine].config.cache - cache_config.buckets.each do |bucket_name, configs| - cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" - Bucket.install(bucket_name, @env, configs) - end - - data_file = @env[:machine].data_dir.join('cache_dirs') - data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } - end - end - end - end - end -end From dc2cb5eb79f485e55706484a041c422cf7b6d566 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 18:12:38 -0200 Subject: [PATCH 19/56] Clean up InstallBuckets action a bit --- lib/vagrant-cachier/action/install_buckets.rb | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb index f96d947..0114fb8 100644 --- a/lib/vagrant-cachier/action/install_buckets.rb +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -11,28 +11,27 @@ module VagrantPlugins def call(env) @app.call(env) - @env = env - configure_cache_buckets + configure_cache_buckets(env) end def configure_cache_buckets - return unless @env[:machine].config.cache.enabled? + return unless env[:machine].config.cache.enabled? - if @env[:machine].config.cache.auto_detect - Bucket.auto_detect(@env) + if env[:machine].config.cache.auto_detect + Bucket.auto_detect(env) end - return unless @env[:machine].config.cache.buckets.any? + return unless env[:machine].config.cache.buckets.any? - @env[:ui].info 'Configuring cache buckets...' - cache_config = @env[:machine].config.cache + env[:ui].info 'Configuring cache buckets...' + cache_config = env[:machine].config.cache cache_config.buckets.each do |bucket_name, configs| # cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" - Bucket.install(bucket_name, @env, configs) + Bucket.install(bucket_name, env, configs) end - data_file = @env[:machine].data_dir.join('cache_dirs') - data_file.open('w') { |f| f.print @env[:cache_dirs].uniq.join("\n") } + data_file = env[:machine].data_dir.join('cache_dirs') + data_file.open('w') { |f| f.print env[:cache_dirs].uniq.join("\n") } end end end From a8963c374101065c93005f26074e4f1aba322bfe Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 18:13:42 -0200 Subject: [PATCH 20/56] Improved logging --- lib/vagrant-cachier/action/clean.rb | 2 +- lib/vagrant-cachier/action/install_buckets.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-cachier/action/clean.rb b/lib/vagrant-cachier/action/clean.rb index a2015bf..a908bff 100644 --- a/lib/vagrant-cachier/action/clean.rb +++ b/lib/vagrant-cachier/action/clean.rb @@ -56,7 +56,7 @@ module VagrantPlugins def remove_symlink(symlink) if @machine.communicate.test("test -L #{symlink}") - @logger.debug "Removing symlink for '#{symlink}'" + @logger.info "Removing symlink for '#{symlink}'" @machine.communicate.sudo("unlink #{symlink}") end end diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb index 0114fb8..94025bd 100644 --- a/lib/vagrant-cachier/action/install_buckets.rb +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -5,7 +5,8 @@ module VagrantPlugins class Action class InstallBuckets def initialize(app, env) - @app = app + @app = app + @logger = Log4r::Logger.new("vagrant::cachier::action::clean") end def call(env) @@ -26,7 +27,7 @@ module VagrantPlugins env[:ui].info 'Configuring cache buckets...' cache_config = env[:machine].config.cache cache_config.buckets.each do |bucket_name, configs| - # cachier_debug "Installing #{bucket_name} with configs #{configs.inspect}" + @logger.info "Installing #{bucket_name} with configs #{configs.inspect}" Bucket.install(bucket_name, env, configs) end From beffce64fa12c6edf52146b0f2e9771d55d4b438 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 18:38:35 -0200 Subject: [PATCH 21/56] Add support for disabling the plugin [GH-72] --- lib/vagrant-cachier/config.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index 6fc8ec2..ac857a7 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -18,7 +18,6 @@ module VagrantPlugins end def enable_nfs=(value) - # TODO: Show warning!!! @ui.warn "The `enable_nfs` config for vagrant-cachier has been deprecated " \ "and will be removed on 0.7.0, please use " \ "`synced_folder_opts = { type: :nfs }` instead.\n" @@ -38,6 +37,16 @@ module VagrantPlugins { "vagrant cachier" => errors } end + def enabled? + return @enabled unless @enabled.nil? + + @enabled = (@auto_detect != UNSET_VALUE || @buckets != nil) + end + + def disable! + @enabled = false + end + def finalize! return unless enabled? @@ -46,11 +55,6 @@ module VagrantPlugins @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE @buckets = @buckets ? @buckets.dup : {} end - - def enabled? - @enabled ||= @auto_detect != UNSET_VALUE || - @buckets != nil - end end end end From 2dad88e2758c82dffda27a679f4c964c9d749324 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 18:40:09 -0200 Subject: [PATCH 22/56] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ee07b4..1e4e04d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ BACKWARDS INCOMPATIBILITY: FEATURES: - Support for specifying custom cache bucket synced folder opts + - Support to force disabe the plugin [GH-72] BUG FIXES: From b8fcfb950fa1204dec6ef1aae92bec1a618d6c2d Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 18:47:32 -0200 Subject: [PATCH 23/56] Extract plugin hooks and capabilities out to separate files --- lib/vagrant-cachier/capabilities.rb | 59 +++++++++++++++++++++ lib/vagrant-cachier/hooks.rb | 27 ++++++++++ lib/vagrant-cachier/plugin.rb | 79 ++--------------------------- 3 files changed, 89 insertions(+), 76 deletions(-) create mode 100644 lib/vagrant-cachier/capabilities.rb create mode 100644 lib/vagrant-cachier/hooks.rb diff --git a/lib/vagrant-cachier/capabilities.rb b/lib/vagrant-cachier/capabilities.rb new file mode 100644 index 0000000..81323ac --- /dev/null +++ b/lib/vagrant-cachier/capabilities.rb @@ -0,0 +1,59 @@ +module VagrantPlugins + module Cachier + class Plugin < Vagrant.plugin('2') + guest_capability 'linux', 'gemdir' do + require_relative 'cap/linux/gemdir' + Cap::Linux::Gemdir + end + + guest_capability 'linux', 'rvm_path' do + require_relative 'cap/linux/rvm_path' + Cap::Linux::RvmPath + end + + guest_capability 'linux', 'composer_path' do + require_relative 'cap/linux/composer_path' + Cap::Linux::ComposerPath + end + + guest_capability 'linux', 'chef_file_cache_path' do + require_relative 'cap/linux/chef_file_cache_path' + Cap::Linux::ChefFileCachePath + end + + guest_capability 'linux', 'npm_cache_dir' do + require_relative 'cap/linux/npm_cache_dir' + Cap::Linux::NpmCacheDir + end + + guest_capability 'debian', 'apt_cache_dir' do + require_relative 'cap/debian/apt_cache_dir' + Cap::Debian::AptCacheDir + end + + guest_capability 'debian', 'apt_cacher_dir' do + require_relative 'cap/debian/apt_cacher_dir' + Cap::Debian::AptCacherDir + end + + guest_capability 'redhat', 'yum_cache_dir' do + require_relative 'cap/redhat/yum_cache_dir' + Cap::RedHat::YumCacheDir + end + + guest_capability 'suse', 'yum_cache_dir' do + # Disable Yum on suse guests + end + + guest_capability 'arch', 'pacman_cache_dir' do + require_relative 'cap/arch/pacman_cache_dir' + Cap::Arch::PacmanCacheDir + end + + guest_capability 'suse', 'zypper_cache_dir' do + require_relative 'cap/suse/zypper_cache_dir' + Cap::SuSE::ZypperCacheDir + end + end + end +end diff --git a/lib/vagrant-cachier/hooks.rb b/lib/vagrant-cachier/hooks.rb new file mode 100644 index 0000000..7030dd8 --- /dev/null +++ b/lib/vagrant-cachier/hooks.rb @@ -0,0 +1,27 @@ +module VagrantPlugins + module Cachier + class Plugin < Vagrant.plugin('2') + action_hook VagrantPlugins::Cachier::Plugin::ALL_ACTIONS do |hook| + require_relative 'action/configure_bucket_root' + require_relative 'action/install_buckets' + + hook.before Vagrant::Action::Builtin::Provision, Action::ConfigureBucketRoot + # This will do the initial buckets installation + hook.after Vagrant::Action::Builtin::Provision, Action::InstallBuckets + end + + # This ensure buckets are reconfigured after provisioners runs + action_hook :provisioner_run do |hook| + require_relative 'action/install_buckets' + hook.after :run_provisioner, Action::InstallBuckets + end + + clean_action_hook = lambda do |hook| + require_relative 'action/clean' + hook.before Vagrant::Action::Builtin::GracefulHalt, Action::Clean + end + action_hook 'remove-guest-symlinks-on-halt', :machine_action_halt, &clean_action_hook + action_hook 'remove-guest-symlinks-on-package', :machine_action_package, &clean_action_hook + end + end +end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 7b20598..93a9b27 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -16,82 +16,9 @@ module VagrantPlugins require_relative "config" Config end - - guest_capability 'linux', 'gemdir' do - require_relative 'cap/linux/gemdir' - Cap::Linux::Gemdir - end - - guest_capability 'linux', 'rvm_path' do - require_relative 'cap/linux/rvm_path' - Cap::Linux::RvmPath - end - - guest_capability 'linux', 'composer_path' do - require_relative 'cap/linux/composer_path' - Cap::Linux::ComposerPath - end - - guest_capability 'linux', 'chef_file_cache_path' do - require_relative 'cap/linux/chef_file_cache_path' - Cap::Linux::ChefFileCachePath - end - - guest_capability 'linux', 'npm_cache_dir' do - require_relative 'cap/linux/npm_cache_dir' - Cap::Linux::NpmCacheDir - end - - guest_capability 'debian', 'apt_cache_dir' do - require_relative 'cap/debian/apt_cache_dir' - Cap::Debian::AptCacheDir - end - - guest_capability 'debian', 'apt_cacher_dir' do - require_relative 'cap/debian/apt_cacher_dir' - Cap::Debian::AptCacherDir - end - - guest_capability 'redhat', 'yum_cache_dir' do - require_relative 'cap/redhat/yum_cache_dir' - Cap::RedHat::YumCacheDir - end - - guest_capability 'suse', 'yum_cache_dir' do - # Disable Yum on suse guests - end - - guest_capability 'arch', 'pacman_cache_dir' do - require_relative 'cap/arch/pacman_cache_dir' - Cap::Arch::PacmanCacheDir - end - - guest_capability 'suse', 'zypper_cache_dir' do - require_relative 'cap/suse/zypper_cache_dir' - Cap::SuSE::ZypperCacheDir - end - - clean_action_hook = lambda do |hook| - require_relative 'action/clean' - hook.before Vagrant::Action::Builtin::GracefulHalt, Action::Clean - end - action_hook 'remove-guest-symlinks-on-halt', :machine_action_halt, &clean_action_hook - action_hook 'remove-guest-symlinks-on-package', :machine_action_package, &clean_action_hook - - action_hook ALL_ACTIONS do |hook| - require_relative 'action/configure_bucket_root' - require_relative 'action/install_buckets' - - hook.before Vagrant::Action::Builtin::Provision, Action::ConfigureBucketRoot - # This will do the initial buckets installation - hook.after Vagrant::Action::Builtin::Provision, Action::InstallBuckets - end - - # This ensure buckets are reconfigured after provisioners runs - action_hook :provisioner_run do |hook| - require_relative 'action/install_buckets' - hook.after :run_provisioner, Action::InstallBuckets - end end end end + +require_relative "hooks" +require_relative "capabilities" From e0797d4e9ae14df7e3c46d452a76f5ace4522d83 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 20:17:01 -0200 Subject: [PATCH 24/56] Ooops --- lib/vagrant-cachier/action/install_buckets.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb index 94025bd..bb3adfd 100644 --- a/lib/vagrant-cachier/action/install_buckets.rb +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -15,7 +15,7 @@ module VagrantPlugins configure_cache_buckets(env) end - def configure_cache_buckets + def configure_cache_buckets(env) return unless env[:machine].config.cache.enabled? if env[:machine].config.cache.auto_detect From 385da382cd528e39ef9c20467375510a67b11b4d Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 20:24:14 -0200 Subject: [PATCH 25/56] Disable the plugin on machines backed by cloud providers (fix GH-45) --- lib/vagrant-cachier/config.rb | 12 ++++++++++++ lib/vagrant-cachier/plugin.rb | 6 +++++- locales/en.yml | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index ac857a7..fb43280 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -28,6 +28,12 @@ module VagrantPlugins def validate(machine) errors = _detected_errors + if enabled? && backed_by_cloud_provider?(machine) + machine.ui.warn(I18n.t('vagrant_cachier.backed_by_cloud_provider', + provider: machine.provider_name)) + disable! + end + if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s) errors << I18n.t('vagrant_cachier.unknown_cache_scope', allowed: ALLOWED_SCOPES.inspect, @@ -55,6 +61,12 @@ module VagrantPlugins @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE @buckets = @buckets ? @buckets.dup : {} end + + private + + def backed_by_cloud_provider?(machine) + CLOUD_PROVIDERS.include?(machine.provider_name.to_s) + end end end end diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index 93a9b27..e9523dc 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -11,12 +11,16 @@ module VagrantPlugins module Cachier class Plugin < Vagrant.plugin('2') name 'vagrant-cachier' - config 'cache' do require_relative "config" Config end end + + # Keep an eye on https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#wiki-providers + # for more. + CLOUD_PROVIDERS = %w( aws cloudstack digitalocean hp joyent openstack rackspace + softlayer proxmox managed virtualbox ) end end diff --git a/locales/en.yml b/locales/en.yml index a8eaefd..c67c616 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -16,3 +16,6 @@ en: scoped cache dirs starting with the 0.3.0 version of the plugin. unable_to_ssh: |- vagrant-cachier was unable to SSH into the VM to remove symlinks! + backed_by_cloud_provider: |- + The machine is backed by a cloud provider (%{provider}), caching + will be disabled. From c494876ac106ea6c3b86d5e58b1c461d7a9176f7 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 20:26:21 -0200 Subject: [PATCH 26/56] Sorry about that, was testing GH-45 --- lib/vagrant-cachier/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb index e9523dc..11460bf 100644 --- a/lib/vagrant-cachier/plugin.rb +++ b/lib/vagrant-cachier/plugin.rb @@ -20,7 +20,7 @@ module VagrantPlugins # Keep an eye on https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#wiki-providers # for more. CLOUD_PROVIDERS = %w( aws cloudstack digitalocean hp joyent openstack rackspace - softlayer proxmox managed virtualbox ) + softlayer proxmox managed ) end end From dd549717e55ada2db32b6b8e9228a5b82c74efb4 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Wed, 5 Feb 2014 18:01:30 -0300 Subject: [PATCH 27/56] Fix usage examples --- README.md | 2 +- docs/index.md | 2 +- docs/usage.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36cda8c..1aa88a9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Vagrant.configure("2") do |config| # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided # by using NFSv4 everywhere. Please note that the tcp option is not the default. - mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + mount_options: ['rw', 'vers=3', 'tcp', 'nolock'] } # For more information please check http://docs.vagrantup.com/v2/synced-folders/basic_usage.html end diff --git a/docs/index.md b/docs/index.md index 4ad4d1c..27151be 100644 --- a/docs/index.md +++ b/docs/index.md @@ -40,7 +40,7 @@ Vagrant.configure("2") do |config| # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided # by using NFSv4 everywhere. Please note that the tcp option is not the default. - mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + mount_options: ['rw', 'vers=3', 'tcp', 'nolock'] } end end diff --git a/docs/usage.md b/docs/usage.md index ef4c047..93e9a0b 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -49,7 +49,7 @@ Vagrant.configure("2") do |config| # NLM sideband protocol. Without this option, apt-get might hang if it tries # to lock files needed for /var/cache/* operations. All of this can be avoided # by using NFSv4 everywhere. Please note that the tcp option is not the default. - mount_options = ['rw', 'vers=3', 'tcp', 'nolock'] + mount_options: ['rw', 'vers=3', 'tcp', 'nolock'] } end ``` From 99b72b016798fe6ffa80af334fc1acfc2fff897b Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 1 Feb 2014 20:27:12 -0200 Subject: [PATCH 28/56] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4e04d..86e7e64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ FEATURES: - Support for specifying custom cache bucket synced folder opts - Support to force disabe the plugin [GH-72] + - Automatically disable the plugin for cloud providers [GH-45] BUG FIXES: From 3790045986536f559e0bef404a32999f5553b4b7 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 5 Feb 2014 19:43:24 -0200 Subject: [PATCH 29/56] Github have analytics now, lets not worry about bitdeli --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 1aa88a9..c50936d 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,3 @@ http://fgrehm.viewdocs.io/vagrant-cachier. 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fgrehm/vagrant-cachier/trend.png)](https://bitdeli.com/free "Bitdeli Badge") From 06cde8c2c848f6a7604e33a31faa2569069d7733 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 5 Feb 2014 19:50:15 -0200 Subject: [PATCH 30/56] We dont have any provider specific code on around anymore so it should be compatible with any "non-cloud provider" --- README.md | 5 ++++- docs/index.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c50936d..82acfd4 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ For more information please read the documentation available at http://fgrehm.viewdocs.io/vagrant-cachier. -## Compatible providers +## Providers that are known to work * Vagrant's built in VirtualBox provider * [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc) @@ -55,6 +55,9 @@ http://fgrehm.viewdocs.io/vagrant-cachier. [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) * [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) +_Please note that as of v0.6.0 the plugin will automatically disable any +previously defined configs for [cloud providers](lib/vagrant-cachier/plugin.rb#L19-22)_ + ## Contributing diff --git a/docs/index.md b/docs/index.md index 27151be..e146bdb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -49,7 +49,7 @@ end For more information please check out the links on the menu above. -## Compatible providers +## Providers that are known to work * Vagrant's built in VirtualBox provider * [vagrant-lxc](https://github.com/fgrehm/vagrant-lxc) @@ -57,6 +57,9 @@ For more information please check out the links on the menu above. [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) * [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) +_Please note that as of v0.6.0 the plugin will automatically disable any +previously defined configs for [cloud providers](lib/vagrant-cachier/plugin.rb#L19-22)_ + ## Contributing From c118febcb1fb500dbd90330775055537dd22bacd Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 5 Feb 2014 19:51:00 -0200 Subject: [PATCH 31/56] According to @miurahr on GH-81 we are compatible with vagrant-kvm \o/ --- README.md | 1 + docs/index.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 82acfd4..fefe1e8 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ http://fgrehm.viewdocs.io/vagrant-cachier. * [VMware providers](http://www.vagrantup.com/vmware) with NFS enabled (See [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) * [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) +* [vagrant-kvm](https://github.com/adrahon/vagrant-kvm) _Please note that as of v0.6.0 the plugin will automatically disable any previously defined configs for [cloud providers](lib/vagrant-cachier/plugin.rb#L19-22)_ diff --git a/docs/index.md b/docs/index.md index e146bdb..316bae4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -56,6 +56,7 @@ For more information please check out the links on the menu above. * [VMware providers](http://www.vagrantup.com/vmware) with NFS enabled (See [GH-24](https://github.com/fgrehm/vagrant-cachier/issues/24) for more info) * [vagrant-libvirt](https://github.com/pradels/vagrant-libvirt) +* [vagrant-kvm](https://github.com/adrahon/vagrant-kvm) _Please note that as of v0.6.0 the plugin will automatically disable any previously defined configs for [cloud providers](lib/vagrant-cachier/plugin.rb#L19-22)_ From 98324a5d35c14f5f5f29a298e6475a77dbf4e46e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 5 Feb 2014 20:48:28 -0200 Subject: [PATCH 32/56] http://tom.preston-werner.com/2010/08/23/readme-driven-development.html --- CHANGELOG.md | 9 ++++ README.md | 8 ++-- docs/index.md | 9 ++-- docs/usage.md | 102 +++++++++++++++++++++++----------------- vagrant-cachier.gemspec | 12 ++++- 5 files changed, 86 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e7e64..f88a3a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ BACKWARDS INCOMPATIBILITY: + - Plugin activation is now triggered by the `cache.scope` config and that config + is now required. Previous versions of the plugin had it set to `:box` but + there is no consensus whether `:box` and `:machine` is better. This is to + highlight that you need to think about the caching strategy you are going + to use. For more information and to discuss this move please check [GH-17](https://github.com/fgrehm/vagrant-cachier/issues/17). + - Because `cache.scope` is now a requirement and in order to reduce the amount of + configuration required by the plugin, we enabled automatic bucket detection by + default. To revert to the old behavior you can disable it globally from your + `~/.vagrant.d/Vagrantfile`. - Support for Vagrant < 1.4 is gone, please use a previous plugin version if you are running Vagrant 1.2 / 1.3 - Automatic handling of multiple machine scoped cache dirs from versions diff --git a/README.md b/README.md index fefe1e8..9a205c8 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,13 @@ vagrant plugin install vagrant-cachier ## Quick start -The easiest way to set things up is just to enable [cache buckets auto detection](http://fgrehm.viewdocs.io/vagrant-cachier/usage) -from within your `Vagrantfile`: - ```ruby Vagrant.configure("2") do |config| config.vm.box = 'your-box' if Vagrant.has_plugin?("vagrant-cachier") - # Enable cache buckets auto detection - config.cache.auto_detect = true + # Configure cached packages to be shared between instances of the same base box. + # More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage + config.cache.scope = :box # If you are using VirtualBox, you might want to use that to enable NFS for # shared folders. This is also very useful for vagrant-libvirt if you want diff --git a/docs/index.md b/docs/index.md index 316bae4..c3d0507 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,12 +24,9 @@ from within your `Vagrantfile`: Vagrant.configure("2") do |config| config.vm.box = 'your-box' if Vagrant.has_plugin?("vagrant-cachier") - # Enable cache buckets auto detection - config.cache.auto_detect = true - - # You can pass in extra mount options for your cache buckets - # from http://docs.vagrantup.com/v2/synced-folders/basic_usage.html - config.cache.synced_folder_opts = { create: true } + # Configure cached packages to be shared between instances of the same base box. + # More info on the "Usage" link above + config.cache.scope = :box # If you are using VirtualBox, you might want to use that to enable NFS for # shared folders. This is also very useful for vagrant-libvirt if you want diff --git a/docs/usage.md b/docs/usage.md index 93e9a0b..e3d71dd 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -1,24 +1,76 @@ # Usage -## Auto detect supported cache buckets +## Being nice to others -This is the easiest way to get started with plugin. By adding the code below to -your `Vagrantfile` you can enable automatic detection of supported cache _buckets_. It is a good practice to wrap plugin specific configuration with `has_plugin?` checks -so the user's Vagrantfiles do not break if vagrant-cachier is uninstalled or -the Vagrantfile is shared with people that don't have the plugin installed. +so the user's Vagrantfiles do not break if `vagrant-cachier` is uninstalled or +the Vagrantfile is shared with people that don't have the plugin installed: ```ruby Vagrant.configure("2") do |config| # ... if Vagrant.has_plugin?("vagrant-cachier") - config.cache.auto_detect = true + # ... vagrant-cachier configs ... end end ``` -This will make `vagrant-cachier` do its best to find out what is supported on the -guest machine and will set buckets accordingly. +## Cache scope + +This is the only required configuration for the plugin to work and should be present +on your project's specific `Vagrantfile` or on your `~/.vagrant.d/Vagrantfile` in +order to enable it. + +### `:box` scope + +By setting `cache.scope` to `:box`, downloaded packages will get stored on a folder +scoped to base boxes under your `~/.vagrant.d/cache`. The idea is to leverage the +cache by allowing downloaded packages to be reused across projects. So, if your +`Vagrantfile` has something like: + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-box' + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end +end +``` + +The cached files will be stored under `$HOME/.vagrant.d/cache/some-box`. + +### `:machine` scope + +If you are on a [multi VM environment](http://docs.vagrantup.com/v2/multi-machine/index.html), +there is a huge chance that you'll end up having issues by sharing the same bucket +across different machines. For example, if you `apt-get install` from two machines +at "almost the same time" you are probably going to hit a _"SystemError: Failed to +lock /var/cache/apt/archives/lock"_. To work around that, you can set the scope +to be based on machines: + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-box' + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :machine + end +end +``` + +This will tell vagrant-cachier to download packages to `.vagrant/machines//cache` +on your current project directory. + +## Cache buckets automatic detection + +This is the easiest way to get started with plugin and is enabled by default. +Under the hood, `vagrant-cachier` does its best to find out what is supported on the +guest machine and will set buckets accordingly + + +By adding the code below to +your `Vagrantfile` you can enable automatic detection of supported cache _buckets_. + +This will make . ## Enable buckets as needed @@ -57,40 +109,6 @@ end Please referer to http://docs.vagrantup.com/v2/synced-folders/basic_usage.html for more information about the supported parameters. -## Cache scope - -By default downloaded packages will get stored on a folder scoped to base boxes -under your `$HOME/.vagrant.d/cache`. The idea is to leverage the cache by allowing -downloaded packages to be reused across projects. So, if your `Vagrantfile` has -something like: - -```ruby -Vagrant.configure("2") do |config| - config.vm.box = 'some-box' - config.cache.auto_detect = true -end -``` - -The cached files will be stored under `$HOME/.vagrant.d/cache/some-box`. - -If you are on a [multi VM environment](http://docs.vagrantup.com/v2/multi-machine/index.html), -there is a huge chance that you'll end up having issues by sharing the same bucket -across different machines. For example, if you `apt-get install` from two machines -at "almost the same time" you are probably going to hit a _"SystemError: Failed to -lock /var/cache/apt/archives/lock"_. To work around that, you can set the scope -to be based on machines: - -```ruby -Vagrant.configure("2") do |config| - config.vm.box = 'some-box' - config.cache.scope = :machine -end -``` - -This will tell vagrant-cachier to download packages to `.vagrant/machines//cache` -on your current project directory. - - ## Finding out disk space used by buckets At some point we might implement a `vagrant cache stats` command that will give you that diff --git a/vagrant-cachier.gemspec b/vagrant-cachier.gemspec index 1b14ea9..243ce2c 100644 --- a/vagrant-cachier.gemspec +++ b/vagrant-cachier.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.version = VagrantPlugins::Cachier::VERSION spec.authors = ["Fabio Rehm"] spec.email = ["fgrehm@gmail.com"] - spec.description = %q{Speed up vagrant boxes provisioning} + spec.description = %q{Caffeine reducer} spec.summary = spec.description spec.homepage = "https://github.com/fgrehm/vagrant-cachier" spec.license = "MIT" @@ -17,4 +17,14 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] + + spec.post_install_message = %q{ + If you are new to vagrant-cachier just follow along with the docs available + at http://fgrehm.viewdocs.io/vagrant-cachier. + + If you are a long time user, please note that plugin has gone through many + backwards incompatible changes since 0.6.0 so checkout + https://github.com/fgrehm/vagrant-cachier/blob/master/CHANGELOG.md + before continuing and caching all the things :) + } end From 4ae25633fef3c09b91fe551f908f3193dc3f9e50 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 5 Feb 2014 20:48:42 -0200 Subject: [PATCH 33/56] Forgot to update this to reflect whats going on under the hood --- docs/how-does-it-work.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/how-does-it-work.md b/docs/how-does-it-work.md index 80a8f5d..b357d89 100644 --- a/docs/how-does-it-work.md +++ b/docs/how-does-it-work.md @@ -20,12 +20,11 @@ _as part of_ the boot process (synced folders are actually `lxc-start` parameter and as of now we are not able to get some information that this plugin requires about the guest machine / container before it is actually up and running. -Under the hood, the plugin will monkey patch `Vagrant::Builtin::Provision` and -will set things up for each configured cache bucket _before and after_ running each -defined provisioner. Before halting the machine, it will also revert the changes -required to set things up by hooking into calls to `Vagrant::Builtin::GracefulHalt` -so that you can repackage the machine for others to use without requiring users to -install the plugin as well. +Under the hood, the plugin will hook into Vagrant in order to set things up for each +configured cache bucket _before and after_ running each defined provisioner. Before +halting the machine, it will also revert the changes required to set things up by +hooking into calls to `Vagrant::Builtin::GracefulHalt` so that you can repackage +the machine for others to use without requiring users to install the plugin as well. Please keep in mind that this plugin won't do magic, if you are compiling things during provisioning or manually downloading packages outside of a bucket you From e5946fc02efea2dc4a6cb0d616a51b3e94c1f33d Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 11 Feb 2014 22:45:04 -0200 Subject: [PATCH 34/56] Update usage docs --- docs/usage.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index e3d71dd..8b810c7 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -64,13 +64,20 @@ on your current project directory. This is the easiest way to get started with plugin and is enabled by default. Under the hood, `vagrant-cachier` does its best to find out what is supported on the -guest machine and will set buckets accordingly +guest machine and will set buckets accordingly. +If you want that behavior to be disabled, you can set `cache.auto_detect` to `false` +from your Vagrantfile: -By adding the code below to -your `Vagrantfile` you can enable automatic detection of supported cache _buckets_. - -This will make . +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-box' + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :machine # or :box + config.cache.auto_detect = false + end +end +``` ## Enable buckets as needed @@ -79,6 +86,7 @@ are configured, you can do so by "cherry picking" them on your `Vagrantfile`: ```ruby Vagrant.configure("2") do |config| + config.cache.auto_detect = false config.cache.enable :apt config.cache.enable :gem end From 95b939a3155b0dd0549501764178f031ded5dc81 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 11 Feb 2014 22:46:08 -0200 Subject: [PATCH 35/56] Fix example of removing buckets from machine scoped dirs [GH-82] --- docs/usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index 8b810c7..09e82fa 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -148,5 +148,5 @@ the code below if you are on a Linux machine: $ rm -rf $HOME/.vagrant.d/cache// # scope = :machine -$ rm -rf .vagrant/cache// +$ rm -rf .vagrant/machines//cache/ ``` From e793dff8915db0cf90d58da35a23bfa7352cb6c2 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 11 Feb 2014 23:24:48 -0200 Subject: [PATCH 36/56] Trigger plugin activation by setting cache scope [GH-17] --- lib/vagrant-cachier/config.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-cachier/config.rb b/lib/vagrant-cachier/config.rb index fb43280..5d2351c 100644 --- a/lib/vagrant-cachier/config.rb +++ b/lib/vagrant-cachier/config.rb @@ -46,7 +46,7 @@ module VagrantPlugins def enabled? return @enabled unless @enabled.nil? - @enabled = (@auto_detect != UNSET_VALUE || @buckets != nil) + @enabled = @scope != UNSET_VALUE end def disable! @@ -56,8 +56,7 @@ module VagrantPlugins def finalize! return unless enabled? - @scope = :box if @scope == UNSET_VALUE - @auto_detect = false if @auto_detect == UNSET_VALUE + @auto_detect = true if @auto_detect == UNSET_VALUE @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE @buckets = @buckets ? @buckets.dup : {} end From 6282b09c6cb0455cfe84a1d57d73e6ac088403cd Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 11 Feb 2014 23:53:07 -0200 Subject: [PATCH 37/56] `chmod` /tmp/vagrant-cache on guest VM to 777 to work around some permission issues as explained on GH-74 --- lib/vagrant-cachier/action/install_buckets.rb | 9 ++++++++- lib/vagrant-cachier/hooks.rb | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb index bb3adfd..96f83ef 100644 --- a/lib/vagrant-cachier/action/install_buckets.rb +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -4,17 +4,24 @@ module VagrantPlugins module Cachier class Action class InstallBuckets - def initialize(app, env) + def initialize(app, env, opts = {}) @app = app @logger = Log4r::Logger.new("vagrant::cachier::action::clean") + @opts = opts end def call(env) @app.call(env) + chmod_bucket_root(env[:machine]) if @opts[:chmod] configure_cache_buckets(env) end + def chmod_bucket_root(machine) + @logger.info "'chmod'ing bucket root dir to 777..." + machine.communicate.sudo 'chmod 777 /tmp/vagrant-cache' + end + def configure_cache_buckets(env) return unless env[:machine].config.cache.enabled? diff --git a/lib/vagrant-cachier/hooks.rb b/lib/vagrant-cachier/hooks.rb index 7030dd8..c2c235f 100644 --- a/lib/vagrant-cachier/hooks.rb +++ b/lib/vagrant-cachier/hooks.rb @@ -7,7 +7,7 @@ module VagrantPlugins hook.before Vagrant::Action::Builtin::Provision, Action::ConfigureBucketRoot # This will do the initial buckets installation - hook.after Vagrant::Action::Builtin::Provision, Action::InstallBuckets + hook.after Vagrant::Action::Builtin::Provision, Action::InstallBuckets, chmod: true end # This ensure buckets are reconfigured after provisioners runs From d4d5603b47a1039c30f3368e7e828b059e4af920 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 12 Feb 2014 00:48:20 -0200 Subject: [PATCH 38/56] Handle nil value for synced_folder_opts --- lib/vagrant-cachier/action/configure_bucket_root.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index 70f275a..0630378 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -24,7 +24,7 @@ module VagrantPlugins FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? synced_folder_opts = {id: "vagrant-cache"} - synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts) + synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {}) @env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts @env[:cache_dirs] = [] From d42e5a98863541c830ad429a162b42c26f27a6de Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Wed, 12 Feb 2014 00:49:00 -0200 Subject: [PATCH 39/56] Do not attempt `chmod`s when the plugin is disabled --- lib/vagrant-cachier/action/install_buckets.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-cachier/action/install_buckets.rb b/lib/vagrant-cachier/action/install_buckets.rb index 96f83ef..aeb8037 100644 --- a/lib/vagrant-cachier/action/install_buckets.rb +++ b/lib/vagrant-cachier/action/install_buckets.rb @@ -13,6 +13,8 @@ module VagrantPlugins def call(env) @app.call(env) + return unless env[:machine].config.cache.enabled? + chmod_bucket_root(env[:machine]) if @opts[:chmod] configure_cache_buckets(env) end @@ -23,8 +25,6 @@ module VagrantPlugins end def configure_cache_buckets(env) - return unless env[:machine].config.cache.enabled? - if env[:machine].config.cache.auto_detect Bucket.auto_detect(env) end From b548637e4ff783a253e11505c4f76c29867b12ec Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 14 Feb 2014 00:28:12 -0200 Subject: [PATCH 40/56] Support for offline provisioning of apt-packages by caching `/var/lib/apt/lists` [GH-84] --- CHANGELOG.md | 1 + lib/vagrant-cachier/bucket.rb | 1 + lib/vagrant-cachier/bucket/apt_lists.rb | 33 +++++++++++++++++++ .../cap/debian/apt_lists_dir.rb | 13 ++++++++ lib/vagrant-cachier/capabilities.rb | 5 +++ 5 files changed, 53 insertions(+) create mode 100644 lib/vagrant-cachier/bucket/apt_lists.rb create mode 100644 lib/vagrant-cachier/cap/debian/apt_lists_dir.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index f88a3a1..c67cc9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ BACKWARDS INCOMPATIBILITY: FEATURES: + - Support for offline provisioning of apt-packages by caching `/var/lib/apt/lists` [GH-84] - Support for specifying custom cache bucket synced folder opts - Support to force disabe the plugin [GH-72] - Automatically disable the plugin for cloud providers [GH-45] diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index 7f38131..66fbd6b 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -40,6 +40,7 @@ require_relative "bucket/pacman" require_relative "bucket/yum" require_relative "bucket/rvm" require_relative "bucket/apt_cacher" +require_relative "bucket/apt_lists" require_relative "bucket/composer" require_relative "bucket/npm" require_relative "bucket/zypper" diff --git a/lib/vagrant-cachier/bucket/apt_lists.rb b/lib/vagrant-cachier/bucket/apt_lists.rb new file mode 100644 index 0000000..65ed60f --- /dev/null +++ b/lib/vagrant-cachier/bucket/apt_lists.rb @@ -0,0 +1,33 @@ +module VagrantPlugins + module Cachier + class Bucket + class AptLists < Bucket + def self.capability + :apt_lists_dir + end + + def install + machine = @env[:machine] + guest = machine.guest + + if guest.capability?(:apt_lists_dir) + guest_path = guest.capability(:apt_lists_dir) + + @env[:cache_dirs] << guest_path + + machine.communicate.tap do |comm| + comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial") + 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 + @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-lists') + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/cap/debian/apt_lists_dir.rb b/lib/vagrant-cachier/cap/debian/apt_lists_dir.rb new file mode 100644 index 0000000..7d454e8 --- /dev/null +++ b/lib/vagrant-cachier/cap/debian/apt_lists_dir.rb @@ -0,0 +1,13 @@ +module VagrantPlugins + module Cachier + module Cap + module Debian + module AptListsDir + def self.apt_lists_dir(machine) + '/var/lib/apt/lists' + end + end + end + end + end +end diff --git a/lib/vagrant-cachier/capabilities.rb b/lib/vagrant-cachier/capabilities.rb index 81323ac..a6b46ef 100644 --- a/lib/vagrant-cachier/capabilities.rb +++ b/lib/vagrant-cachier/capabilities.rb @@ -36,6 +36,11 @@ module VagrantPlugins Cap::Debian::AptCacherDir end + guest_capability 'debian', 'apt_lists_dir' do + require_relative 'cap/debian/apt_lists_dir' + Cap::Debian::AptListsDir + end + guest_capability 'redhat', 'yum_cache_dir' do require_relative 'cap/redhat/yum_cache_dir' Cap::RedHat::YumCacheDir From d6bed343023cee8873653051866b92084a9ca3d1 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 14 Feb 2014 01:15:43 -0200 Subject: [PATCH 41/56] :warning: Massive refactoring of buckets code :warning: Doing this is kinda irresponsible because we don't have any unit testing in place but I've had enough of copy & pasting things around. Although it doesn't make the codebase GREAT, I believe it'll reach a _nice_ status :) Thanks to those changes I realized that skipping configuration of buckets that have already been configured was easier than I thought and should be enough to close GH-85 \o/ --- lib/vagrant-cachier/bucket.rb | 37 ++++++++++++++++++++++++ lib/vagrant-cachier/bucket/apt.rb | 15 ++-------- lib/vagrant-cachier/bucket/apt_cacher.rb | 14 +-------- lib/vagrant-cachier/bucket/apt_lists.rb | 15 ++-------- lib/vagrant-cachier/bucket/chef.rb | 15 +--------- lib/vagrant-cachier/bucket/composer.rb | 14 +-------- lib/vagrant-cachier/bucket/gem.rb | 21 +++----------- lib/vagrant-cachier/bucket/npm.rb | 15 +--------- lib/vagrant-cachier/bucket/pacman.rb | 15 +--------- lib/vagrant-cachier/bucket/rvm.rb | 21 +++----------- lib/vagrant-cachier/bucket/yum.rb | 19 +++--------- lib/vagrant-cachier/bucket/zypper.rb | 19 +++--------- 12 files changed, 64 insertions(+), 156 deletions(-) diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb index 66fbd6b..5aa7cb5 100644 --- a/lib/vagrant-cachier/bucket.rb +++ b/lib/vagrant-cachier/bucket.rb @@ -29,6 +29,43 @@ module VagrantPlugins @env = env @configs = configs end + + def machine + @env[:machine] + end + + def guest + machine.guest + end + + def comm + machine.communicate + end + + def symlink(guest_path, bucket_path = "/tmp/vagrant-cache/#{@name}", create_parent: true) + return if @env[:cache_dirs].include?(guest_path) + + @env[:cache_dirs] << guest_path + comm.execute("mkdir -p #{bucket_path}") + unless comm.test("test -L #{guest_path}") + comm.sudo("rm -rf #{guest_path}") + comm.sudo("mkdir -p `dirname #{guest_path}`") if create_parent + comm.sudo("ln -s #{bucket_path} #{guest_path}") + end + end + + def user_symlink(guest_path) + return if @env[:cache_dirs].include?(guest_path) + + @env[:cache_dirs] << guest_path + bucket_path = "/tmp/vagrant-cache/#{@name}" + comm.execute("mkdir -p #{bucket_path}") + unless comm.test("test -L #{guest_path}") + comm.execute("rm -rf #{guest_path}") + comm.execute("mkdir -p `dirname #{guest_path}`") if create_parent + comm.execute("ln -s #{bucket_path} #{guest_path}") + end + end end end end diff --git a/lib/vagrant-cachier/bucket/apt.rb b/lib/vagrant-cachier/bucket/apt.rb index 3b326df..44cf0fc 100644 --- a/lib/vagrant-cachier/bucket/apt.rb +++ b/lib/vagrant-cachier/bucket/apt.rb @@ -7,22 +7,13 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:apt_cache_dir) guest_path = guest.capability(:apt_cache_dir) - @env[:cache_dirs] << guest_path + return if @env[:cache_dirs].include?(guest_path) - machine.communicate.tap do |comm| - comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial") - 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 + comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial") + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'APT') end diff --git a/lib/vagrant-cachier/bucket/apt_cacher.rb b/lib/vagrant-cachier/bucket/apt_cacher.rb index 57c6f8d..5e81405 100644 --- a/lib/vagrant-cachier/bucket/apt_cacher.rb +++ b/lib/vagrant-cachier/bucket/apt_cacher.rb @@ -9,22 +9,10 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:apt_cacher_dir) if guest_path = guest.capability(:apt_cacher_dir) if machine.config.cache.enable_nfs - @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 + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.nfs_required', bucket: 'apt-cacher') end diff --git a/lib/vagrant-cachier/bucket/apt_lists.rb b/lib/vagrant-cachier/bucket/apt_lists.rb index 65ed60f..e6bef12 100644 --- a/lib/vagrant-cachier/bucket/apt_lists.rb +++ b/lib/vagrant-cachier/bucket/apt_lists.rb @@ -7,22 +7,13 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:apt_lists_dir) guest_path = guest.capability(:apt_lists_dir) - @env[:cache_dirs] << guest_path + return if @env[:cache_dirs].include?(guest_path) - machine.communicate.tap do |comm| - comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial") - 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 + comm.execute("mkdir -p /tmp/vagrant-cache/#{@name}/partial") + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'apt-lists') end diff --git a/lib/vagrant-cachier/bucket/chef.rb b/lib/vagrant-cachier/bucket/chef.rb index b78bbe4..ac28aaa 100644 --- a/lib/vagrant-cachier/bucket/chef.rb +++ b/lib/vagrant-cachier/bucket/chef.rb @@ -7,22 +7,9 @@ module VagrantPlugins 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 + symlink(guest_path) if guest_path else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Chef') end diff --git a/lib/vagrant-cachier/bucket/composer.rb b/lib/vagrant-cachier/bucket/composer.rb index cb939ad..f13661e 100644 --- a/lib/vagrant-cachier/bucket/composer.rb +++ b/lib/vagrant-cachier/bucket/composer.rb @@ -7,22 +7,10 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:composer_path) if composer_path = guest.capability(:composer_path) bucket_path = "/tmp/vagrant-cache/#{@name}" - @env[:cache_dirs] << composer_path - - machine.communicate.tap do |comm| - comm.execute("mkdir -p #{bucket_path}") - - unless comm.test("test -L #{composer_path}") - comm.sudo("rm -rf #{composer_path}") - comm.sudo("ln -s #{bucket_path} #{composer_path}") - end - end + symlink(composer_path, create_parent: false) end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer') diff --git a/lib/vagrant-cachier/bucket/gem.rb b/lib/vagrant-cachier/bucket/gem.rb index e166520..7e7b886 100644 --- a/lib/vagrant-cachier/bucket/gem.rb +++ b/lib/vagrant-cachier/bucket/gem.rb @@ -7,26 +7,13 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:gemdir) if gemdir_path = guest.capability(:gemdir) - prefix = gemdir_path.split('/').last - bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}" - machine.communicate.tap do |comm| - comm.execute("mkdir -p #{bucket_path}") + prefix = gemdir_path.split('/').last + bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}" + gem_cache_path = "#{gemdir_path}/cache" - gem_cache_path = "#{gemdir_path}/cache" - - @env[:cache_dirs] << gem_cache_path - - unless comm.test("test -L #{gem_cache_path}") - comm.sudo("rm -rf #{gem_cache_path}") - comm.sudo("mkdir -p `dirname #{gem_cache_path}`") - comm.sudo("ln -s #{bucket_path} #{gem_cache_path}") - end - end + symlink(gem_cache_path, bucket_path) end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RubyGems') diff --git a/lib/vagrant-cachier/bucket/npm.rb b/lib/vagrant-cachier/bucket/npm.rb index f10a2ce..cb3bca7 100644 --- a/lib/vagrant-cachier/bucket/npm.rb +++ b/lib/vagrant-cachier/bucket/npm.rb @@ -7,22 +7,9 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:npm_cache_dir) guest_path = guest.capability(:npm_cache_dir) - - @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.execute("rm -rf #{guest_path}") - comm.execute("mkdir -p `dirname #{guest_path}`") - comm.execute("ln -s /tmp/vagrant-cache/#{@name} #{guest_path}") - end - end + user_symlink(guest_path) if guest_path else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'npm') end diff --git a/lib/vagrant-cachier/bucket/pacman.rb b/lib/vagrant-cachier/bucket/pacman.rb index c9d9cdc..0f91a7e 100644 --- a/lib/vagrant-cachier/bucket/pacman.rb +++ b/lib/vagrant-cachier/bucket/pacman.rb @@ -7,22 +7,9 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:pacman_cache_dir) guest_path = guest.capability(:pacman_cache_dir) - - @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 + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Pacman') end diff --git a/lib/vagrant-cachier/bucket/rvm.rb b/lib/vagrant-cachier/bucket/rvm.rb index ce57ff8..2c51bf9 100644 --- a/lib/vagrant-cachier/bucket/rvm.rb +++ b/lib/vagrant-cachier/bucket/rvm.rb @@ -7,26 +7,13 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - 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}") + prefix = rvm_path.split('/').last + bucket_path = "/tmp/vagrant-cache/#{@name}/#{prefix}" + rvm_cache_path = "#{rvm_path}/archives" - rvm_cache_path = "#{rvm_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 + symlink(rvm_cache_path, bucket_path) end else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'RVM') diff --git a/lib/vagrant-cachier/bucket/yum.rb b/lib/vagrant-cachier/bucket/yum.rb index d43af7c..b58ce19 100644 --- a/lib/vagrant-cachier/bucket/yum.rb +++ b/lib/vagrant-cachier/bucket/yum.rb @@ -7,25 +7,14 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:yum_cache_dir) guest_path = guest.capability(:yum_cache_dir) + return if @env[:cache_dirs].include?(guest_path) - @env[:cache_dirs] << guest_path + # Ensure caching is enabled + comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf") - machine.communicate.tap do |comm| - # Ensure caching is enabled - comm.sudo("sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf") - - 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 + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Yum') end diff --git a/lib/vagrant-cachier/bucket/zypper.rb b/lib/vagrant-cachier/bucket/zypper.rb index f556b21..26aec74 100644 --- a/lib/vagrant-cachier/bucket/zypper.rb +++ b/lib/vagrant-cachier/bucket/zypper.rb @@ -7,25 +7,14 @@ module VagrantPlugins end def install - machine = @env[:machine] - guest = machine.guest - if guest.capability?(:zypper_cache_dir) guest_path = guest.capability(:zypper_cache_dir) + return if @env[:cache_dirs].include?(guest_path) - @env[:cache_dirs] << guest_path + # Ensure caching is enabled + comm.sudo("zypper modifyrepo --keep-packages --all") - machine.communicate.tap do |comm| - # Ensure caching is enabled - comm.sudo("zypper modifyrepo --keep-packages --all") - - 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 + symlink(guest_path) else @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Zypper') end From b98cc76ebe7edbfb83f00c4232c4c225cac1ed4d Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 14 Feb 2014 01:37:56 -0200 Subject: [PATCH 42/56] Add docs for apt-lists bucket --- docs/buckets/apt-lists.md | 18 ++++++++++++++++++ docs/template.html | 1 + 2 files changed, 19 insertions(+) create mode 100644 docs/buckets/apt-lists.md diff --git a/docs/buckets/apt-lists.md b/docs/buckets/apt-lists.md new file mode 100644 index 0000000..228ca15 --- /dev/null +++ b/docs/buckets/apt-lists.md @@ -0,0 +1,18 @@ +# APT lists + +Used by Debian-like Linux distros, will get configured under guest's `/var/lib/apt/lists`. + +As explained on [Wikipedia](http://en.wikipedia.org/wiki/Advanced_Packaging_Tool#Files), +`/var/lib/apt/lists` is the "storage area for state information for each package +resource specified in sources.list". By enabling this bucket, `apt` will be able +to install cached packages without hitting the remote repositories for the main +package lists, [being particularly useful when developing offline](https://github.com/fgrehm/vagrant-cachier/pull/84#issue-27311414). + +To manually enable it: + +```ruby +Vagrant.configure("2") do |config| + config.vm.box = 'some-debian-box' + config.cache.enable :apt_lists +end +``` diff --git a/docs/template.html b/docs/template.html index ac464ae..e26d63c 100644 --- a/docs/template.html +++ b/docs/template.html @@ -83,6 +83,7 @@ Available Buckets