Fixes #10798: Enhance how docker compose driver path expands
Prior to this commit, the docker compose driver would _always_ path expand a host volume no matter what. This is not always the correct option, for example if that host volume is actually a reference to a key inside a `volumes` hash instead of a path on disk. This commit changes that by looking to see if the requested host volume is actually a defined key inside the compose config, and if not, it will path expand it like before. Otherwise it will leave the key "as is".
This commit is contained in:
parent
c22a145c59
commit
ca0fd64ded
|
@ -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))
|
||||
|
|
|
@ -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: |-
|
||||
|
|
|
@ -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}/)
|
||||
|
|
Loading…
Reference in New Issue