@ -101,6 +101,36 @@ postgres:container:version() {
echo "$image_version"
echo "$image_version"
}
}
## XXXvlab: there's an issue with using ``docker stop ..``, then
## ``docker rmi ..`` on the stopped container's image. It can fail on
## some VPS (and on dev platform) saying the image is still in use.
docker:container:stop() {
local container=$1 timeout=${2:-60}
## Stop the container
if ! out=$(docker stop "$container"); then
err "Failed to stop container $container"
echo "$out" | prefix " | " >&2
return 1
fi
local start=$SECONDS
# Wait for the container to stop
while [ -n "$(
curl -s --unix-socket /var/run/docker.sock \
http://localhost/containers/json?all=1 |
jq -r '.[] | .Id[:12] , .Id , ( .Names | .[] | ltrimstr("/"))' | grep ^"$container"$)" ]; do
if [ $(($SECONDS - start)) -ge $timeout ]; then
err "Timeout waiting for container '$container' to stop." >&2
return 1
fi
sleep 0.1
done
return 0
}
postgres:container:psql () {
postgres:container:psql () {
local container="$1"
local container="$1"
docker exec -i "$container" psql 2>&1
docker exec -i "$container" psql 2>&1
@ -290,9 +320,8 @@ while [[ "${#upgrade_path[@]}" != 0 ]]; do
break
break
fi
fi
out=$(docker stop "$migration_container" 2>&1) || {
err "Failed to stop the dump container $migration_container for $current_image_version:"
printf "%s\n" "$out" | prefix " ${GRAY}|${NORMAL} "
docker:container:stop "$migration_container" || {
err "Failed to stop the dump container $migration_container for $current_image_version"
break 3
break 3
}
}
expected_stop="1"
expected_stop="1"
@ -328,6 +357,8 @@ while [[ "${#upgrade_path[@]}" != 0 ]]; do
out=$(docker rmi "$current_image" 2>&1) || {
out=$(docker rmi "$current_image" 2>&1) || {
err "Failed to remove image $current_image"
err "Failed to remove image $current_image"
printf "%s\n" "$out" | prefix " ${GRAY}|${NORMAL} "
printf "%s\n" "$out" | prefix " ${GRAY}|${NORMAL} "
sleep 2
docker start "$migration_container" >&2
break 2
break 2
}
}
}
}
@ -390,9 +421,8 @@ while [[ "${#upgrade_path[@]}" != 0 ]]; do
current_image="$next_image"
current_image="$next_image"
current_image_version="$image_version"
current_image_version="$image_version"
out=$(docker stop "$migration_container" 2>&1) || {
docker:container:stop "$migration_container" || {
err "Failed to stop the migration container $migration_container for $image_version:"
err "Failed to stop the migration container $migration_container for $image_version:"
printf "%s\n" "$out" | prefix " ${GRAY}|${NORMAL} "
break 3
break 3
}
}
expected_stop="1"
expected_stop="1"