Skip to content

Commit 83cbd31

Browse files
authored
refactor: clarify Bash guards in Docker and CI scripts (#105)
Signed-off-by: Billy Okal <bokal@nvidia.com>
1 parent bbc3008 commit 83cbd31

3 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎docker/run_docker.sh‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CUROBO_VERSION_TAG='sim-6.1.0-curobo'
1515
# Resolve TORCH_CUDA_ARCH_LIST for the cuRobo build. Honour an explicit override if set, else
1616
# auto-detect the host GPU's compute capability via nvidia-smi (e.g. "12.0" -> "12.0+PTX").
1717
detect_cuda_arch() {
18-
if [ -n "${TORCH_CUDA_ARCH_LIST:-}" ]; then
18+
if [[ -n "${TORCH_CUDA_ARCH_LIST:-}" ]]; then
1919
echo "${TORCH_CUDA_ARCH_LIST}"
2020
return 0
2121
fi
@@ -75,12 +75,13 @@ while getopts ":d:crRvh" OPTION; do
7575
;;
7676
\?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
7777
:) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
78+
*) echo "Unhandled option: -$OPTION" >&2; exit 1 ;;
7879
esac
7980
done
8081
shift $((OPTIND - 1))
8182

8283
# Set separate tag for cuRobo image.
83-
if [ "$INSTALL_CUROBO" = "true" ]; then
84+
if [[ "$INSTALL_CUROBO" == true ]]; then
8485
DOCKER_VERSION_TAG="${CUROBO_VERSION_TAG}"
8586
fi
8687

@@ -89,11 +90,11 @@ CONTAINER_NAME="${DOCKER_IMAGE_NAME}-${DOCKER_VERSION_TAG}"
8990
echo "Using Docker image: ${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG} (base: ${BASE_IMAGE})"
9091

9192
# Build the image if it doesn't exist yet, or if a rebuild was requested.
92-
if [ "$(docker images -q "${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG}" 2>/dev/null)" ] && [ "$FORCE_REBUILD" = false ]; then
93+
if [[ -n "$(docker images -q "${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG}" 2>/dev/null)" && "$FORCE_REBUILD" == false ]]; then
9394
echo "Image ${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG} already exists. Use -r to force a rebuild."
9495
else
9596
BUILD_ARGS=("--build-arg" "WORKDIR=${WORKDIR}" "--build-arg" "BASE_IMAGE=${BASE_IMAGE}")
96-
if [ "$INSTALL_CUROBO" = "true" ]; then
97+
if [[ "$INSTALL_CUROBO" == true ]]; then
9798
# Detect the host GPU arch so cuRobo's kernels are compiled for it.
9899
ARCH_LIST=$(detect_cuda_arch) || exit 1
99100
echo "cuRobo enabled — building for TORCH_CUDA_ARCH_LIST=${ARCH_LIST}"
@@ -109,18 +110,18 @@ else
109110
fi
110111

111112
# Remove a previously-exited container of the same name so we can recreate it.
112-
if [ "$(docker ps -a --quiet --filter status=exited --filter "name=^${CONTAINER_NAME}$")" ]; then
113+
if [[ -n "$(docker ps -a --quiet --filter status=exited --filter "name=^${CONTAINER_NAME}$")" ]]; then
113114
docker rm "${CONTAINER_NAME}" >/dev/null
114115
fi
115116

116117
# Reuse a running container only if it uses the selected image.
117-
if [ "$(docker container inspect -f '{{.State.Running}}' "${CONTAINER_NAME}" 2>/dev/null)" = "true" ]; then
118-
if [ "$(docker inspect -f '{{.Image}}' "${CONTAINER_NAME}")" != \
119-
"$(docker image inspect -f '{{.Id}}' "${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG}")" ]; then
118+
if test "$(docker container inspect -f '{{.State.Running}}' "${CONTAINER_NAME}" 2>/dev/null)" = true; then
119+
if test "$(docker inspect -f '{{.Image}}' "${CONTAINER_NAME}")" != \
120+
"$(docker image inspect -f '{{.Id}}' "${DOCKER_IMAGE_NAME}:${DOCKER_VERSION_TAG}")"; then
120121
echo "error: ${CONTAINER_NAME} uses an older image. Stop it and rerun this command." >&2
121122
exit 1
122123
fi
123-
if [ "$#" -gt 0 ]; then
124+
if [[ $# -gt 0 ]]; then
124125
printf -v AUTODATA_COMMAND '%q ' "$@"
125126
docker exec --user "$(id -un)" --workdir "${WORKDIR}" "${CONTAINER_NAME}" \
126127
bash -ic "${AUTODATA_COMMAND}"
@@ -132,15 +133,15 @@ if [ "$(docker container inspect -f '{{.State.Running}}' "${CONTAINER_NAME}" 2>/
132133
fi
133134

134135
add_volume_if_it_exists() {
135-
[ -d "$1" ] && echo "-v $1:$2"
136+
[[ -d "$1" ]] && echo "-v $1:$2"
136137
}
137138

138139
# Create it as the host user before Docker can create a root-owned bind source.
139140
mkdir -p "${CACHE_HOST_MOUNT_DIRECTORY}"
140141

141142
# Forward the host SSH agent if available (so git over SSH works in-container).
142143
SSH_DOCKER_ARGS=()
143-
if [ -n "${SSH_AUTH_SOCK:-}" ] && [ -S "$SSH_AUTH_SOCK" ]; then
144+
if [[ -n "${SSH_AUTH_SOCK:-}" && -S "$SSH_AUTH_SOCK" ]]; then
144145
SSH_DOCKER_ARGS+=("-v" "$SSH_AUTH_SOCK:/ssh-agent" "--env" "SSH_AUTH_SOCK=/ssh-agent")
145146
fi
146147

@@ -183,7 +184,7 @@ fi
183184
# Only allocate a TTY when stdin is a terminal. CI has no TTY, and passing --tty
184185
# there fails with "cannot attach stdin to a TTY-enabled container".
185186
TTY_ARGS=()
186-
if [ -t 0 ]; then
187+
if [[ -t 0 ]]; then
187188
TTY_ARGS+=("--tty")
188189
fi
189190

‎docker/setup/entrypoint.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ chown "$DOCKER_RUN_USER_NAME:$DOCKER_RUN_GROUP_NAME" "/home/$DOCKER_RUN_USER_NAM
3636

3737
# Isaac Lab rejects a binary Sim link with an active virtual environment.
3838
ISAACLAB_DIR="$WORKDIR/submodules/IsaacLab-Arena/submodules/IsaacLab"
39-
if [ -e "$ISAACLAB_DIR/_isaac_sim" ] || [ -L "$ISAACLAB_DIR/_isaac_sim" ]; then
39+
if [[ -e "$ISAACLAB_DIR/_isaac_sim" || -L "$ISAACLAB_DIR/_isaac_sim" ]]; then
4040
echo "error: $ISAACLAB_DIR/_isaac_sim selects a binary Isaac Sim installation." >&2
4141
echo "Remove the link from the host checkout before using the locked Docker environment." >&2
4242
exit 1
4343
fi
4444

4545
# Run the command as the dev user with the image's shell environment.
46-
if [ $# -ge 1 ]; then
46+
if [[ $# -ge 1 ]]; then
4747
# Quote each argument before passing it to the interactive shell so shell
4848
# preserves paths, marker expressions, and Python code.
4949
printf -v AUTODATA_COMMAND '%q ' "$@"

‎scripts/ci/run_tests.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cd "${REPO_ROOT}"
4949

5050
# cuRobo (-c) is required for the SkillGen tests; one image covers the whole suite.
5151
RUN_DOCKER_ARGS=(-c)
52-
if [ "${FORCE_REBUILD}" = "true" ]; then
52+
if test "${FORCE_REBUILD}" = true; then
5353
RUN_DOCKER_ARGS+=(-r)
5454
fi
5555

@@ -66,12 +66,12 @@ PYTEST_ARGS=(
6666
"WARP_CACHE_PATH=${CONTAINER_CACHE_DIR}/warp"
6767
python -m pytest -sv --durations=0
6868
)
69-
if [ -n "${RESULTS_DIR}" ]; then
69+
if [[ -n "${RESULTS_DIR}" ]]; then
7070
# Pre-create on the host so the container can write into the bind-mounted dir.
7171
mkdir -p "${RESULTS_DIR}"
7272
PYTEST_ARGS+=("--junitxml=${RESULTS_DIR}/junit.xml")
7373
fi
74-
if [ -n "${PYTEST_MARK}" ]; then
74+
if [[ -n "${PYTEST_MARK}" ]]; then
7575
PYTEST_ARGS+=(-m "${PYTEST_MARK}")
7676
fi
7777
# TEST_PATH may list multiple paths; split on whitespace into separate args.

0 commit comments

Comments
 (0)