Browse Source

fix: [compose,compose-core] revert detection of used volume

This is not iso-functional and can't detect if a subvolume was mounted.

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

28
bin/compose

@ -308,14 +308,30 @@ list_compose_vars() {
done < <(declare -p | grep "^declare -x COMPOSE_[A-Z_]\+=\"") done < <(declare -p | grep "^declare -x COMPOSE_[A-Z_]\+=\"")
} }
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() { is_volume_used() {
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" ]
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
} }

14
bin/compose-core

@ -3325,12 +3325,14 @@ get_volumes_for_container() {
export -f get_volumes_for_container export -f get_volumes_for_container
is_volume_used() { is_volume_used() {
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" ]
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
} }
export -f is_volume_used export -f is_volume_used

Loading…
Cancel
Save