From c7c47782cb9445868bb0bfeae23a397851cb4a6c Mon Sep 17 00:00:00 2001 From: John Barbuto Date: Tue, 22 Jul 2014 22:53:29 -0700 Subject: [PATCH] Use image for bucket name with docker, if box is unset This allows multiple machines using the image to share the cache and avoids the following error: /Applications/Vagrant/embedded/lib/ruby/2.0.0/pathname.rb:389:in `initialize': no implicit conversion of nil into String (TypeError) --- lib/vagrant-cachier/action/configure_bucket_root.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb index e1b5480..86e87c2 100644 --- a/lib/vagrant-cachier/action/configure_bucket_root.rb +++ b/lib/vagrant-cachier/action/configure_bucket_root.rb @@ -33,7 +33,14 @@ module VagrantPlugins def cache_root @cache_root ||= case @env[:machine].config.cache.scope.to_sym when :box - @env[:home_path].join('cache', box_name) + @box_name = box_name + # Box is optional with docker provider, so use image name if unset + if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker + bucket_name = image_name.gsub(':', '-') + else + bucket_name = @box_name + end + @env[:home_path].join('cache', bucket_name) when :machine @env[:machine].data_dir.parent.join('cache') else @@ -44,6 +51,10 @@ module VagrantPlugins def box_name @env[:machine].config.vm.box end + + def image_name + @env[:machine].provider_config.image + end end end end