Skip to content

Commit

Permalink
Merge pull request #156 from buildkite-plugins/expand-local-volume-pa…
Browse files Browse the repository at this point in the history
…ths-in-volume-option

Expand local volume paths
  • Loading branch information
toolmantim authored Jun 13, 2018
2 parents 3c1e578 + b940bda commit fc41171
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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/}"
}
2 changes: 1 addition & 1 deletion tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fc41171

Please sign in to comment.