From 9e18803b955736b40ad1462a2d14aa2af1b4835f Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 14:40:32 +0100 Subject: [PATCH 1/6] if the vagrant-omnibus plugin is detected and enabled for that VM, set the `OMNIBUS_DOWNLOAD_DIR` env var --- .../action/configure_bucket_root.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index 0630378..f041720 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -15,11 +15,32 @@ module VagrantPlugins if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled? setup_buckets_folder env[:cache_buckets_folder_configured] = true + if cache_vagrant_omnibus? + setup_omnibus_cache_folder + end end @app.call env end + def cache_vagrant_omnibus? + plugin_defined = defined?(VagrantPlugins::Omnibus::Plugin) + puts "xxx - cap: vagrant-omnibus defined? #{plugin_defined}" + return false unless plugin_defined + + chef_version = @env[:machine].config.omnibus.chef_version + puts "xxx - cap: chef_version? #{chef_version}" + return chef_version != nil + end + + def setup_omnibus_cache_folder + # since it's not configurable via the vagrant-omnibus plugin (yet) + # we specify the directory where to download the omnibus package here + omnibus_cache_dir = File.join(cache_root.to_s, 'omnibus') + FileUtils.mkdir_p(omnibus_cache_dir) unless File.exist? omnibus_cache_dir + ENV['OMNIBUS_DOWNLOAD_DIR'] = "/tmp/vagrant-cache/omnibus" + end + def setup_buckets_folder FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? From f5966d5166d8afbeb180e1c1aaf4d8d9cb0a7357 Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 14:52:54 +0100 Subject: [PATCH 2/6] refactor, code cleanup, remove println debugging --- .../action/configure_bucket_root.rb | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index f041720..233c089 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -14,45 +14,33 @@ module VagrantPlugins if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled? setup_buckets_folder + setup_omnibus_cache_folder env[:cache_buckets_folder_configured] = true - if cache_vagrant_omnibus? - setup_omnibus_cache_folder - end end @app.call env end - def cache_vagrant_omnibus? - plugin_defined = defined?(VagrantPlugins::Omnibus::Plugin) - puts "xxx - cap: vagrant-omnibus defined? #{plugin_defined}" - return false unless plugin_defined - - chef_version = @env[:machine].config.omnibus.chef_version - puts "xxx - cap: chef_version? #{chef_version}" - return chef_version != nil - end - - def setup_omnibus_cache_folder - # since it's not configurable via the vagrant-omnibus plugin (yet) - # we specify the directory where to download the omnibus package here - omnibus_cache_dir = File.join(cache_root.to_s, 'omnibus') - FileUtils.mkdir_p(omnibus_cache_dir) unless File.exist? omnibus_cache_dir - ENV['OMNIBUS_DOWNLOAD_DIR'] = "/tmp/vagrant-cache/omnibus" - end - def setup_buckets_folder - FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? + FileUtils.mkdir_p(host_cache_root.to_s) unless host_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[:machine].config.vm.synced_folder host_cache_root, guest_cache_root, synced_folder_opts @env[:cache_dirs] = [] end - def cache_root - @cache_root ||= case @env[:machine].config.cache.scope.to_sym + def setup_omnibus_cache_folder + # unfortunately vagrant-omnibus hooks in before our buckets are installed, yet + # this is early enough to tell it to download to the vagrant-omnibus pseudo bucket + if omnibus_plugin_detected? && omnibus_plugin_enabled? + ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant-omnibus" + end + end + + def host_cache_root + @host_cache_root ||= case @env[:machine].config.cache.scope.to_sym when :box @env[:home_path].join('cache', @env[:machine].box.name) when :machine @@ -61,6 +49,18 @@ module VagrantPlugins raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" end end + + def guest_cache_root + '/tmp/vagrant-cache' + end + + def omnibus_plugin_detected? + defined?(VagrantPlugins::Omnibus::Plugin) + end + + def omnibus_plugin_enabled? + @env[:machine].config.omnibus.chef_version != nil + end end end end From daf8cfcdeab7b0fe8092d1a479ba26ccf373ad89 Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 14:55:57 +0100 Subject: [PATCH 3/6] only set the `OMNIBUS_DOWNLOAD_DIR` env var if `auto_detect` is true --- 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 233c089..d91beed 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -34,7 +34,7 @@ module VagrantPlugins def setup_omnibus_cache_folder # unfortunately vagrant-omnibus hooks in before our buckets are installed, yet # this is early enough to tell it to download to the vagrant-omnibus pseudo bucket - if omnibus_plugin_detected? && omnibus_plugin_enabled? + if env[:machine].config.cache.auto_detect && omnibus_plugin_detected? && omnibus_plugin_enabled? ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant-omnibus" end end From 03ba78ab26697fed1d6726b67f774ecf91206147 Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 15:17:16 +0100 Subject: [PATCH 4/6] fix missing local variable --- 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 d91beed..1ea59fe 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -34,7 +34,7 @@ module VagrantPlugins def setup_omnibus_cache_folder # unfortunately vagrant-omnibus hooks in before our buckets are installed, yet # this is early enough to tell it to download to the vagrant-omnibus pseudo bucket - if env[:machine].config.cache.auto_detect && omnibus_plugin_detected? && omnibus_plugin_enabled? + if @env[:machine].config.cache.auto_detect && omnibus_plugin_detected? && omnibus_plugin_enabled? ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant-omnibus" end end From edde1730ef354322d4f6a9d9ce75435478347cee Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 15:17:58 +0100 Subject: [PATCH 5/6] adhere to underscore naming convention as used in apt_list bucket --- 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 1ea59fe..5e44f59 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -35,7 +35,7 @@ module VagrantPlugins # unfortunately vagrant-omnibus hooks in before our buckets are installed, yet # this is early enough to tell it to download to the vagrant-omnibus pseudo bucket if @env[:machine].config.cache.auto_detect && omnibus_plugin_detected? && omnibus_plugin_enabled? - ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant-omnibus" + ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant_omnibus" end end From 53a79d90e9452ef3a29fbe9889f18a18a6fdcf04 Mon Sep 17 00:00:00 2001 From: Torben Date: Sat, 8 Mar 2014 15:59:12 +0100 Subject: [PATCH 6/6] create vagrant_omnibus pseudo bucket if not exists, otherwise current version of install.sh would fail --- lib/vagrant-cachier/action/configure_bucket_root.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index 5e44f59..ee855f3 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -35,6 +35,8 @@ module VagrantPlugins # unfortunately vagrant-omnibus hooks in before our buckets are installed, yet # this is early enough to tell it to download to the vagrant-omnibus pseudo bucket if @env[:machine].config.cache.auto_detect && omnibus_plugin_detected? && omnibus_plugin_enabled? + omnibus_pseudo_bucket = host_cache_root.join('vagrant_omnibus') + FileUtils.mkdir(omnibus_pseudo_bucket.to_s) unless omnibus_pseudo_bucket.exist? ENV['OMNIBUS_DOWNLOAD_DIR'] ||= "#{guest_cache_root}/vagrant_omnibus" end end