diff --git a/docker b/docker index a91002e..e6ddda0 100755 --- a/docker +++ b/docker @@ -45,13 +45,15 @@ function fix_volume_arg() { else local mode_suffix="" fi - elif [[ "${volume_arg}" =~ ,?type\=bind,? ]]; then + elif [[ "${volume_arg}" =~ (^|,)type\=bind(,|$) ]]; then # There must be a better way of doing this - if [[ "${volume_arg}" =~ ,?source\=(/[^,]+),? ]]; then - local source="${BASH_REMATCH[1]}" - if [[ "${volume_arg}" =~ ,?destination\=(/[^,]+),? ]]; then + if [[ "${volume_arg}" =~ (^|,)((source|src)\=(/[^,]+))(,|$) ]]; then + local source_key="${BASH_REMATCH[3]}" + local source="${BASH_REMATCH[4]}" + if [[ "${volume_arg}" =~ (^|,)((destination|dst|target)\=(/[^,]+))(,|$) ]]; then local arg_type="mount" - local destination="${BASH_REMATCH[1]}" + local destination_key="${BASH_REMATCH[3]}" + local destination="${BASH_REMATCH[4]}" else # Leave it as it is if it does not match the pattern return @@ -100,8 +102,8 @@ function fix_volume_arg() { if [[ "${arg_type}" == "volume" ]]; then extra_args+=(--volume "${container_volume_source}:${destination}/${container_volume_destination#"${source}/"}${mode_suffix}") elif [[ "${arg_type}" == "mount" ]]; then - local fixed_arg="${volume_arg//"source=${source}"/"source=${container_volume_source}"}" - fixed_arg="${fixed_arg//"destination=${destination}"/"destination=${destination}/${container_volume_destination#"${source}/"}"}" + local fixed_arg="${volume_arg//"${source_key}=${source}"/"${source_key}=${container_volume_source}"}" + fixed_arg="${fixed_arg//"${destination_key}=${destination}"/"${destination_key}=${destination}/${container_volume_destination#"${source}/"}"}" extra_args+=(--mount "${fixed_arg}") else echo "Unexpected arg_type: ${arg_type}" >&2 @@ -116,7 +118,7 @@ function fix_volume_arg() { if [[ "${arg_type}" == "volume" ]]; then volume_arg="${fixed_source}:${destination}${mode_suffix}" elif [[ "${arg_type}" == "mount" ]]; then - volume_arg="${volume_arg//"source=${source}"/"source=${fixed_source}"}" + volume_arg="${volume_arg//"${source_key}=${source}"/"${source_key}=${fixed_source}"}" else echo "Unexpected arg_type: ${arg_type}" >&2 exit 1 diff --git a/test.sh b/test.sh index b95a3ad..252f799 100755 --- a/test.sh +++ b/test.sh @@ -42,10 +42,10 @@ for docker_version in "${docker_versions[@]}"; do docker --host test run --volume /wd:/wd:ro --volume /test:/test:ro alpine --volume /wd:/wd | grep --quiet "^docker.orig --host test run --volume ${PWD}:/wd:ro --volume /container-root/test:/test:ro --volume ${PWD}/testfile:/test/testfile:ro alpine --volume /wd:/wd$" - echo "Same as above (with --mount), but retaining read only mode on auto added volume" + echo "Same as above (with --mount src and target, dst), but retaining read only mode on auto added volume" "${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --env DOND_SHIM_MOCK_CONTAINER_ROOT_DIR=/container-root --volume "${PWD}:/wd" --volume "${PWD}/testfile:/test/testfile" "${image_id}" \ - docker --host test run --mount type=bind,source=/wd,destination=/wd,readonly --mount type=bind,source=/test,destination=/test,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly | - grep --quiet "^docker.orig --host test run --mount type=bind,source=${PWD},destination=/wd,readonly --mount type=bind,source=/container-root/test,destination=/test,readonly --mount type=bind,source=${PWD}/testfile,destination=/test/testfile,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly$" + docker --host test run --mount type=bind,src=/wd,target=/wd,readonly --mount type=bind,source=/test,dst=/test,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly | + grep --quiet "^docker.orig --host test run --mount type=bind,src=${PWD},target=/wd,readonly --mount type=bind,source=/container-root/test,dst=/test,readonly --mount type=bind,source=${PWD}/testfile,dst=/test/testfile,readonly alpine --mount type=bind,source=/wd,destination=/wd,readonly$" echo "Same but for container run" "${docker_args[@]}" --env DOND_SHIM_PRINT_COMMAND=true --volume "${PWD}:/wd" "${image_id}" \