Browse Source

new: dev: provide ``get_host_path`` to find host path of a local directory.

This is useful when preparing to launch a docker container from
a ``compose`` in docker command.
test
Valentin Lab 6 years ago
parent
commit
e37864afc3
  1. 36
      bin/compose-core

36
bin/compose-core

@ -2444,6 +2444,42 @@ get_master_services() {
export -f get_master_services
get_current_docker_container_id() {
local line
line=$(cat "/proc/self/cpuset") || return 1
[[ "$line" == *docker* ]] || return 1
echo "${line##*/}"
}
export -f get_current_docker_container_id
## if we are in a docker compose, we might want to know what is the
## real host path of some local paths.
get_host_path() {
local path="$1"
path=$(realpath "$path") || return 1
container_id=$(get_current_docker_container_id) || {
print "%s" "$path"
return 0
}
biggest_dst=
current_src=
while read-0 src dst; do
[[ "$path" == "$dst"* ]] || continue
if [[ "${#biggest_dst}" < "${#dst}" ]]; then
biggest_dst="$dst"
current_src="$src"
fi
done < <(get_volumes_for_container "$container_id")
if [ "$current_src" ]; then
printf "%s" "$current_src"
else
return 1
fi
}
export -f get_host_path
_setup_state_dir() {
export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
#debug "Creating temporary state directory in '$state_tmpdir'."

Loading…
Cancel
Save