From 8c8a5a62ce6d8882a274d171c12ed54ddc327b19 Mon Sep 17 00:00:00 2001 From: Eric Lunderberg Date: Tue, 10 Aug 2021 09:05:43 -0500 Subject: [PATCH] [Docker] Updated bash.sh for MacOS compatibility MacOS has an older version of bash that handles arrays slightly differently. All instances of array expansion `"${ARRAY[@]}"` should instead be written as `${ARRAY[@]+"${ARRAY[@]}"}`. Otherwise, `set -u` will erroneously complain about an undefined variable. See https://stackoverflow.com/a/61551944 for details. Even though this is an older version of bash (observed in version 3.2.57), this is the last major version available under GPLv2 and is therefore the default version on MacOSX. At some point, the `docker/bash.sh` could be migrated to python for ease of maintenance/testing. --- docker/bash.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker/bash.sh b/docker/bash.sh index beff864522dd5..702cfa0f671b6 100755 --- a/docker/bash.sh +++ b/docker/bash.sh @@ -222,7 +222,7 @@ if [[ -z "${DOCKER_IMAGE_NAME}" ]]; then show_usage >&2 fi -if [[ "${COMMAND[@]}" = bash ]]; then +if [[ ${COMMAND[@]+"${COMMAND[@]}"} = bash ]]; then INTERACTIVE=true USE_NET_HOST=true fi @@ -297,7 +297,7 @@ if ${INTERACTIVE}; then fi # Expose external directories to the docker container -for MOUNT_DIR in "${MOUNT_DIRS[@]}"; do +for MOUNT_DIR in ${MOUNT_DIRS[@]+"${MOUNT_DIRS[@]}"}; do DOCKER_MOUNT+=( --volume "${MOUNT_DIR}:${MOUNT_DIR}" ) done @@ -369,20 +369,20 @@ echo "REPO_DIR: ${REPO_DIR}" echo "DOCKER CONTAINER NAME: ${DOCKER_IMAGE_NAME}" echo "" -echo "Running '${COMMAND[@]}' inside ${DOCKER_IMAGE_NAME}..." +echo Running \'${COMMAND[@]+"${COMMAND[@]}"}\' inside ${DOCKER_IMAGE_NAME}... DOCKER_CMD=(${DOCKER_BINARY} run - "${DOCKER_FLAGS[@]}" - "${DOCKER_ENV[@]}" - "${DOCKER_MOUNT[@]}" - "${DOCKER_DEVICES[@]}" + ${DOCKER_FLAGS[@]+"${DOCKER_FLAGS[@]}"} + ${DOCKER_ENV[@]+"${DOCKER_ENV[@]}"} + ${DOCKER_MOUNT[@]+"${DOCKER_MOUNT[@]}"} + ${DOCKER_DEVICES[@]+"${DOCKER_DEVICES[@]}"} "${DOCKER_IMAGE_NAME}" bash --login /docker/with_the_same_user - "${COMMAND[@]}" + ${COMMAND[@]+"${COMMAND[@]}"} ) if ${DRY_RUN}; then - echo "${DOCKER_CMD[@]}" + echo ${DOCKER_CMD[@]+"${DOCKER_CMD[@]}"} else - "${DOCKER_CMD[@]}" + ${DOCKER_CMD[@]+"${DOCKER_CMD[@]}"} fi