Merge pull request #10820 from briancain/docker-compose-volumes

Fixes #10798: Enhance how docker compose driver path expands
This commit is contained in:
Brian Cain 2019-05-08 09:14:33 -07:00 committed by GitHub
commit a613044baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -102,7 +102,19 @@ module VagrantPlugins
# will be fixed someday and the gsub below can be removed.
host.gsub!(/^[^A-Za-z]+/, "")
end
host = @machine.env.cwd.join(host).to_s
# if host path is a volume key, don't expand it.
# if both exist (a path and a key) show warning and move on
# otherwise assume it's a realative path and expand the host path
compose_config = get_composition
if compose_config["volumes"] && compose_config["volumes"].keys.include?(host)
if File.directory?(@machine.env.cwd.join(host).to_s)
@machine.env.ui.warn(I18n.t("docker_provider.volume_path_not_expanded",
host: host))
end
else
@logger.debug("Path expanding #{host} to current Vagrant working dir instead of docker-compose config file directory")
host = @machine.env.cwd.join(host).to_s
end
"#{host}:#{guest}"
end
cmd = Array(params.fetch(:cmd))

View File

@ -104,6 +104,12 @@ en:
destroy the container and recreate it.
waiting_for_running: |-
Waiting for container to enter "running" state...
volume_path_not_expanded: |-
Host path `%{host}` exists as a `volumes` key and is a folder on disk. Vagrant
will not expand this key like it used to and instead leave it as is defined.
If this folder is intended to be used, make sure its full path is defined
in your `volumes` config. More information can be found on volumes in the
docker compose documentation.
messages:
destroying: |-

View File

@ -106,6 +106,22 @@ describe VagrantPlugins::DockerProvider::Driver::Compose do
end
end
context 'with a volumes key in use for mounting' do
let(:compose_config) { {"volumes"=>{"my_volume_key"=>"data"}} }
before do
params[:volumes] = 'my_volume_key:my/guest/path'
allow(Pathname).to receive(:new).with('./path').and_call_original
allow(Pathname).to receive(:new).with('my_volume_key').and_call_original
allow(Pathname).to receive(:new).with('/compose/cwd/my_volume_key').and_call_original
allow(subject).to receive(:get_composition).and_return(compose_config)
end
it 'should not expand the relative host directory' do
expect(docker_yml).to receive(:write).with(%r{my_volume_key})
end
end
it 'links containers' do
params[:links].each do |link|
expect(docker_yml).to receive(:write).with(/#{link}/)