Skip to content

Commit

Permalink
[Docker] Updated bash.sh for MacOS compatibility
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Lunderberg committed Aug 10, 2021
1 parent b1777a4 commit 8c8a5a6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docker/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 8c8a5a6

Please sign in to comment.