From cca458cfcd4b69f1a2bc916daac607aee041f635 Mon Sep 17 00:00:00 2001 From: Nicholas Allen Date: Wed, 24 Apr 2024 14:38:07 +1000 Subject: [PATCH] fix: improve run_macaron.sh bash and docker version compatibility Signed-off-by: Nicholas Allen --- scripts/release_scripts/run_macaron.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/release_scripts/run_macaron.sh b/scripts/release_scripts/run_macaron.sh index 7d5cbb088..8c3146799 100755 --- a/scripts/release_scripts/run_macaron.sh +++ b/scripts/release_scripts/run_macaron.sh @@ -524,6 +524,11 @@ fi USER_UID="$(id -u)" USER_GID="$(id -g)" +# Disable unset variable errors from here on to support older bash versions +# where "${array[*]}" and "${array[@]}" expressions throw errors (in set -u mode) +# when the array is empty despite otherwise having the correct behaviour. +set +u + if [[ -z "${entrypoint[*]}" ]]; then entrypoint=("macaron") @@ -564,8 +569,22 @@ fi # Reference: https://docs.podman.io/en/v4.4/markdown/options/userns.container.html. export PODMAN_USERNS=keep-id +# Pull image based on DOCKER_PULL setting, emulating behaviour of +# docker run --pull ${DOCKER_PULL} ... +# to support older versions of docker that do not support the "--pull" argument. +if [[ "${DOCKER_PULL}" == "always" ]]; then + docker image pull "${IMAGE}:${MACARON_IMAGE_TAG}" +elif [[ "${DOCKER_PULL}" == "missing" ]]; then + docker image inspect "${IMAGE}:${MACARON_IMAGE_TAG}" &> /dev/null || docker image pull "${IMAGE}:${MACARON_IMAGE_TAG}" +else + # "${DOCKER_PULL}" == "never" + if ! docker image inspect "${IMAGE}:${MACARON_IMAGE_TAG}" &> /dev/null; then + echo "Docker image '${IMAGE}:${MACARON_IMAGE_TAG}' not found locally and DOCKER_PULL == never, aborting" + exit 1 + fi +fi + docker run \ - --pull "${DOCKER_PULL}" \ --network=host \ --rm -i "${tty[@]}" \ -e "USER_UID=${USER_UID}" \