From 3eed4e2a55fd21f75873ed4970bc7e9581cef189 Mon Sep 17 00:00:00 2001 From: Luca Berneking Date: Tue, 14 Sep 2021 17:41:04 +0200 Subject: [PATCH] Swap incorrect key and value of BindMounts and VolumeMounts It is currently not possible to mount a local path to multiple paths in the container. BindMounts are currently stored in a `map[string]string` with the hostPath being the key and containerPath as the value. This prevents me from mounting a hostPath to multiple paths in the container. Using a map actually makes sense because it is not possible to mount multiple host paths to the same path in the container. Key and value are just swapped. Same with VolumeMounts. Yes, i know, this a huge breaking change and probably not the best fix. We could also add an additional map like `BindMountsFixed` and deprecate the old one. But as this library is still in version 0, a breaking change might not be a problem? --- docker.go | 4 ++-- docker_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker.go b/docker.go index efb324aa54..17e20de694 100644 --- a/docker.go +++ b/docker.go @@ -679,14 +679,14 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque // prepare mounts mounts := []mount.Mount{} - for hostPath, innerPath := range req.BindMounts { + for innerPath, hostPath := range req.BindMounts { mounts = append(mounts, mount.Mount{ Type: mount.TypeBind, Source: hostPath, Target: innerPath, }) } - for volumeName, innerPath := range req.VolumeMounts { + for innerPath, volumeName := range req.VolumeMounts { mounts = append(mounts, mount.Mount{ Type: mount.TypeVolume, Source: volumeName, diff --git a/docker_test.go b/docker_test.go index 9349c4fedc..71039e863e 100644 --- a/docker_test.go +++ b/docker_test.go @@ -1279,8 +1279,8 @@ func TestContainerCreationWithBindAndVolume(t *testing.T) { bashC, err := GenericContainer(ctx, GenericContainerRequest{ ContainerRequest: ContainerRequest{ Image: "bash", - BindMounts: map[string]string{absPath: "/hello.sh"}, - VolumeMounts: map[string]string{volumeName: "/data"}, + BindMounts: map[string]string{"/hello.sh": absPath}, + VolumeMounts: map[string]string{"/data": volumeName}, Cmd: []string{"bash", "/hello.sh"}, WaitingFor: wait.ForLog("done"), },