From 1c763cf5e6fa8831703c9dbf95fad8a3a3ad9c39 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 31 Jul 2017 14:56:51 -0700 Subject: [PATCH] Expand relative volume paths for compose on current cwd --- plugins/providers/docker/driver/compose.rb | 6 +++--- .../plugins/providers/docker/driver_compose_test.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/providers/docker/driver/compose.rb b/plugins/providers/docker/driver/compose.rb index deb77034e..3313d28d2 100644 --- a/plugins/providers/docker/driver/compose.rb +++ b/plugins/providers/docker/driver/compose.rb @@ -94,16 +94,16 @@ module VagrantPlugins ports = Array(params[:ports]) volumes = Array(params[:volumes]).map do |v| v = v.to_s + host, guest = v.split(":", 2) if v.include?(":") && (Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.wsl?) - host, guest = v.split(":", 2) host = Vagrant::Util::Platform.windows_path(host) # NOTE: Docker does not support UNC style paths (which also # means that there's no long path support). Hopefully this # will be fixed someday and the gsub below can be removed. host.gsub!(/^[^A-Za-z]+/, "") - v = [host, guest].join(":") end - v + host = @machine.env.cwd.join(host).to_s + "#{host}:#{guest}" end cmd = Array(params.fetch(:cmd)) env = Hash[*params.fetch(:env).flatten.map(&:to_s)] diff --git a/test/unit/plugins/providers/docker/driver_compose_test.rb b/test/unit/plugins/providers/docker/driver_compose_test.rb index d49ee8e54..3aebb7ff3 100644 --- a/test/unit/plugins/providers/docker/driver_compose_test.rb +++ b/test/unit/plugins/providers/docker/driver_compose_test.rb @@ -41,6 +41,7 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do allow(Vagrant::Util::Which).to receive(:which).and_return("/dev/null/docker-compose") allow(env).to receive(:lock).and_yield allow(Pathname).to receive(:new).with(local_data_path).and_return(local_data_path) + allow(Pathname).to receive(:new).with('/host/path').and_call_original allow(local_data_path).to receive(:join).and_return(data_directory) allow(data_directory).to receive(:mkpath) allow(FileUtils).to receive(:mv) @@ -93,6 +94,18 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do end end + context 'with relative path in share folders' do + before do + params[:volumes] = './path:guest/path' + allow(Pathname).to receive(:new).with('./path').and_call_original + allow(Pathname).to receive(:new).with('/compose/cwd/path').and_call_original + end + + it 'should expand the relative host directory' do + expect(docker_yml).to receive(:write).with(%r{/compose/cwd/path}) + end + end + it 'links containers' do params[:links].each do |link| expect(docker_yml).to receive(:write).with(/#{link}/)