From c7c47782cb9445868bb0bfeae23a397851cb4a6c Mon Sep 17 00:00:00 2001
From: John Barbuto <john.barbuto@venmo.com>
Date: Tue, 22 Jul 2014 22:53:29 -0700
Subject: [PATCH 1/2] 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

From b7b3bcb3ede9fa7f42ed358ec9f1d2faba297b5a Mon Sep 17 00:00:00 2001
From: John Barbuto <john.barbuto@venmo.com>
Date: Thu, 24 Jul 2014 23:17:32 -0700
Subject: [PATCH 2/2] Check if image is set with docker provider

If build_dir is set instead for building images on demand, there's no way to
know what to set the bucket name to, except perhaps parsing it from Dockerfile.
---
 lib/vagrant-cachier/action/configure_bucket_root.rb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/vagrant-cachier/action/configure_bucket_root.rb b/lib/vagrant-cachier/action/configure_bucket_root.rb
index 86e87c2..4bd8e67 100644
--- a/lib/vagrant-cachier/action/configure_bucket_root.rb
+++ b/lib/vagrant-cachier/action/configure_bucket_root.rb
@@ -34,9 +34,15 @@ module VagrantPlugins
           @cache_root ||= case @env[:machine].config.cache.scope.to_sym
             when :box
               @box_name = box_name
-              # Box is optional with docker provider, so use image name if unset
+              # Box is optional with docker provider
               if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker
-                bucket_name = image_name.gsub(':', '-')
+                @image_name = image_name
+                # Use the image name if it's set
+                if @image_name
+                  bucket_name = @image_name.gsub(':', '-')
+                else
+                  raise "Cachier plugin only supported with docker provider when image is used"
+                end
               else
                 bucket_name = @box_name
               end