Browse Source

fix: [compose] prevent stalling when ``docker inspect`` stalls on a container.

Improve ``is_volume_used`` implementation largely and doesn't require
``docker inspect`` call anymore.

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
cache-relation
Valentin Lab 2 years ago
parent
commit
7a475500b2
  1. 29
      bin/compose
  2. 14
      bin/compose-core

29
bin/compose

@ -309,30 +309,13 @@ list_compose_vars() {
}
get_running_compose_containers() {
## XXXvlab: docker bug: there will be a final newline anyway
docker ps --filter label="compose.service" --format='{{.ID}}'
}
get_volumes_for_container() {
local container="$1"
docker inspect \
--format '{{range $mount := .Mounts}}{{$mount.Source}}{{"\x00"}}{{$mount.Destination}}{{"\x00"}}{{end}}' \
"$container"
}
is_volume_used() {
local volume="$1"
while read container_id; do
while read-0 src dst; do
[ "$src" == "$volume" ] && return 0
done < <(get_volumes_for_container "$container_id")
done < <(get_running_compose_containers)
return 1
local volume="$1" out
if ! out=$(docker ps --filter volume="$volume" --format {{.ID}}); then
err "Couldn't query containers by volumes."
return 0
fi
[ -n "$out" ]
}

14
bin/compose-core

@ -3325,14 +3325,12 @@ get_volumes_for_container() {
export -f get_volumes_for_container
is_volume_used() {
local volume="$1" container_id src dst
while read -r container_id; do
while read-0 src dst; do
[[ "$src/" == "$volume"/* ]] && return 0
done < <(get_volumes_for_container "$container_id")
done < <(get_running_compose_containers)
return 1
local volume="$1" out
if ! out=$(docker ps --filter volume="$volume" --format {{.ID}}); then
err "Couldn't query containers by volumes."
return 0
fi
[ -n "$out" ]
}
export -f is_volume_used

Loading…
Cancel
Save