From b940bda19ea5cfc6c366e5f8a647386f9567f82e Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Tue, 12 Jun 2018 15:01:53 +1000 Subject: [PATCH] Expand local volume paths --- commands/run.sh | 2 +- lib/run.bash | 9 +++++++++ tests/run.bats | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/commands/run.sh b/commands/run.sh index 67125d6e..c90725fb 100755 --- a/commands/run.sh +++ b/commands/run.sh @@ -92,7 +92,7 @@ done <<< "$(printf '%s\n%s' \ "$(plugin_read_list ENVIRONMENT)")" while IFS=$'\n' read -r vol ; do - [[ -n "${vol:-}" ]] && run_params+=("-v" "${vol}") + [[ -n "${vol:-}" ]] && run_params+=("-v" "$(expand_relative_volume_path "$vol")") done <<< "$(plugin_read_list VOLUMES)" # Optionally disable allocating a TTY diff --git a/lib/run.bash b/lib/run.bash index 6a43778b..de52c868 100644 --- a/lib/run.bash +++ b/lib/run.bash @@ -40,3 +40,12 @@ check_linked_containers_and_save_logs() { fi done } + +# docker-compose's -v arguments don't do local path expansion like the .yml +# versions do. So we add very simple support, for the common and basic case. +# +# "./foo:/foo" => "/buildkite/builds/.../foo:/foo" +expand_relative_volume_path() { + local path="$1" + echo "${path/.\//$PWD/}" +} \ No newline at end of file diff --git a/tests/run.bats b/tests/run.bats index 95be5cbe..8ce7939f 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -350,7 +350,7 @@ export BUILDKITE_JOB_ID=1111 stub docker-compose \ "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v ./dist:/app/dist -v ./pkg:/app/pkg myservice pwd : echo ran myservice with volumes" + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v $PWD/dist:/app/dist -v $PWD/pkg:/app/pkg myservice pwd : echo ran myservice with volumes" stub buildkite-agent \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"