Skip to content

Commit 3f53cf1

Browse files
committed
fix: abort run-demo.sh on Docker build failure
set -e does not catch failures inside && lists, so a failed docker build would silently continue and print the success banner. Split build and up into separate steps with an explicit exit on build failure, tearing down any partial containers.
1 parent c55fb76 commit 3f53cf1

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

demos/moveit_pick_place/run-demo.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,23 @@ if [[ "$DETACH_MODE" == "true" ]]; then
137137
fi
138138

139139
if docker compose version &> /dev/null; then
140-
# shellcheck disable=SC2086
141-
docker compose ${COMPOSE_ARGS} build ${BUILD_ARGS} && \
142-
docker compose ${COMPOSE_ARGS} up ${DETACH_FLAG}
140+
COMPOSE_CMD="docker compose"
143141
else
142+
COMPOSE_CMD="docker-compose"
143+
fi
144+
145+
# shellcheck disable=SC2086
146+
if ! ${COMPOSE_CMD} ${COMPOSE_ARGS} build ${BUILD_ARGS}; then
147+
echo ""
148+
echo "❌ Docker build failed! Stopping any partially created containers..."
144149
# shellcheck disable=SC2086
145-
docker-compose ${COMPOSE_ARGS} build ${BUILD_ARGS} && \
146-
docker-compose ${COMPOSE_ARGS} up ${DETACH_FLAG}
150+
${COMPOSE_CMD} ${COMPOSE_ARGS} down 2>/dev/null || true
151+
exit 1
147152
fi
148153

154+
# shellcheck disable=SC2086
155+
${COMPOSE_CMD} ${COMPOSE_ARGS} up ${DETACH_FLAG}
156+
149157
if [[ "$DETACH_MODE" == "true" ]]; then
150158
echo ""
151159
echo "✅ Demo started in background!"

demos/sensor_diagnostics/run-demo.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,22 @@ if [[ "$DETACH_MODE" == "true" ]]; then
9393
fi
9494

9595
if docker compose version &> /dev/null; then
96-
# shellcheck disable=SC2086
97-
docker compose build ${BUILD_ARGS} && docker compose up ${DETACH_FLAG}
96+
COMPOSE_CMD="docker compose"
9897
else
99-
# shellcheck disable=SC2086
100-
docker-compose build ${BUILD_ARGS} && docker-compose up ${DETACH_FLAG}
98+
COMPOSE_CMD="docker-compose"
10199
fi
102100

101+
# shellcheck disable=SC2086
102+
if ! ${COMPOSE_CMD} build ${BUILD_ARGS}; then
103+
echo ""
104+
echo "❌ Docker build failed! Stopping any partially created containers..."
105+
${COMPOSE_CMD} down 2>/dev/null || true
106+
exit 1
107+
fi
108+
109+
# shellcheck disable=SC2086
110+
${COMPOSE_CMD} up ${DETACH_FLAG}
111+
103112
if [[ "$DETACH_MODE" == "true" ]]; then
104113
echo ""
105114
echo "✅ Demo started in background!"

demos/turtlebot3_integration/run-demo.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,23 @@ if [[ "$DETACH_MODE" == "true" ]]; then
144144
fi
145145

146146
if docker compose version &> /dev/null; then
147-
# shellcheck disable=SC2086
148-
docker compose ${COMPOSE_ARGS} build ${BUILD_ARGS} && \
149-
docker compose ${COMPOSE_ARGS} up ${DETACH_FLAG}
147+
COMPOSE_CMD="docker compose"
150148
else
149+
COMPOSE_CMD="docker-compose"
150+
fi
151+
152+
# shellcheck disable=SC2086
153+
if ! ${COMPOSE_CMD} ${COMPOSE_ARGS} build ${BUILD_ARGS}; then
154+
echo ""
155+
echo "❌ Docker build failed! Stopping any partially created containers..."
151156
# shellcheck disable=SC2086
152-
docker-compose ${COMPOSE_ARGS} build ${BUILD_ARGS} && \
153-
docker-compose ${COMPOSE_ARGS} up ${DETACH_FLAG}
157+
${COMPOSE_CMD} ${COMPOSE_ARGS} down 2>/dev/null || true
158+
exit 1
154159
fi
155160

161+
# shellcheck disable=SC2086
162+
${COMPOSE_CMD} ${COMPOSE_ARGS} up ${DETACH_FLAG}
163+
156164
if [[ "$DETACH_MODE" == "true" ]]; then
157165
echo ""
158166
echo "✅ Demo started in background!"

0 commit comments

Comments
 (0)