Skip to content

Commit 31d2e67

Browse files
committed
refactor(scripts): array-expand COMPOSE_FLAGS for SC2086 + glob safety
validate.sh, dream-preflight.sh, and validate-compose-stack.sh expanded $COMPOSE_FLAGS (and $ENV_FILE_FLAG) unquoted when invoking docker compose. Convert to bash-array expansion via `read -ra flags <<< "$COMPOSE_FLAGS"` followed by `"${flags[@]}"`, matching the established pattern in dream-cli. Benefits: - Eliminates 4 SC2086 shellcheck warnings. - Prevents accidental glob expansion of flag values. - Aligns three more consumer scripts with the project-canonical compose-flags consumption pattern. Note: resolve-compose-stack.sh emits relative paths only, so absolute install paths with spaces (the "Jane Smith" scenario sometimes raised on reports) do not appear in COMPOSE_FLAGS by design. This refactor does not fix that scenario — it is shellcheck/glob hardening and convention alignment. Two sites in validate.sh (L64/65) previously passed a compose invocation as a string to a check() helper running `bash -c "$cmd"`; those are inlined as direct if/grep pipelines so array expansion applies correctly without refactoring check() itself. Other check() callers are untouched.
1 parent d5154c3 commit 31d2e67

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

dream-server/scripts/dream-preflight.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ if [[ -x "$SCRIPT_DIR/scripts/resolve-compose-stack.sh" ]]; then
2222
COMPOSE_FLAGS=$("$SCRIPT_DIR/scripts/resolve-compose-stack.sh" \
2323
--script-dir "$SCRIPT_DIR" --tier "${TIER:-1}" --gpu-backend "${GPU_BACKEND:-nvidia}")
2424
fi
25+
# Split COMPOSE_FLAGS into an array so paths with spaces survive expansion
26+
read -ra COMPOSE_FLAGS_ARR <<< "$COMPOSE_FLAGS"
2527

2628
# Colors
2729
RED='\033[0;31m'
@@ -53,7 +55,7 @@ fi
5355

5456
# Check containers are up
5557
echo -n "Core containers... "
56-
if docker compose $COMPOSE_FLAGS ps | grep -q "$LLM_CONTAINER"; then
58+
if docker compose "${COMPOSE_FLAGS_ARR[@]}" ps | grep -q "$LLM_CONTAINER"; then
5759
echo -e "${GREEN}✓ running${NC}"
5860
else
5961
echo -e "${RED}✗ not running${NC}"
@@ -94,7 +96,7 @@ fi
9496
for sid in "${SERVICE_IDS[@]}"; do
9597
[[ "${SERVICE_CATEGORIES[$sid]}" == "core" ]] && continue
9698
container="${SERVICE_CONTAINERS[$sid]}"
97-
docker compose $COMPOSE_FLAGS ps 2>/dev/null | grep -q "$container" || continue
99+
docker compose "${COMPOSE_FLAGS_ARR[@]}" ps 2>/dev/null | grep -q "$container" || continue
98100

99101
port="${SERVICE_PORTS[$sid]:-0}"
100102
health="${SERVICE_HEALTH[$sid]:-/}"

dream-server/scripts/validate-compose-stack.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ if [[ -z "$COMPOSE_FLAGS" ]]; then
3939
fi
4040

4141
# Build env-file flag if provided (allows compose to resolve required variable references)
42-
ENV_FILE_FLAG=""
42+
ENV_FILE_FLAG_ARR=()
4343
if [[ -n "$ENV_FILE" && -f "$ENV_FILE" ]]; then
44-
ENV_FILE_FLAG="--env-file $ENV_FILE"
44+
ENV_FILE_FLAG_ARR=(--env-file "$ENV_FILE")
4545
fi
4646

47+
# Split COMPOSE_FLAGS into an array so paths with spaces survive expansion
48+
read -ra COMPOSE_FLAGS_ARR <<< "$COMPOSE_FLAGS"
49+
4750
# Check if docker/docker compose is available
4851
if command -v docker &>/dev/null && docker compose version &>/dev/null; then
4952
DOCKER_COMPOSE_CMD="docker compose"
@@ -67,7 +70,7 @@ fi
6770
# - Circular dependencies
6871
# - Invalid environment variable references
6972
validation_output=$(mktemp)
70-
if $DOCKER_COMPOSE_CMD $ENV_FILE_FLAG $COMPOSE_FLAGS config > "$validation_output" 2>&1; then
73+
if $DOCKER_COMPOSE_CMD "${ENV_FILE_FLAG_ARR[@]}" "${COMPOSE_FLAGS_ARR[@]}" config > "$validation_output" 2>&1; then
7174
if ! $QUIET; then
7275
echo "Compose stack validation passed"
7376
# Show summary of services

dream-server/scripts/validate.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ if [[ -x "$PROJECT_DIR/scripts/resolve-compose-stack.sh" ]]; then
3535
COMPOSE_FLAGS=$("$PROJECT_DIR/scripts/resolve-compose-stack.sh" \
3636
--script-dir "$PROJECT_DIR" --tier "${TIER:-1}" --gpu-backend "${GPU_BACKEND:-nvidia}")
3737
fi
38+
# Split COMPOSE_FLAGS into an array so paths with spaces survive expansion
39+
read -ra COMPOSE_FLAGS_ARR <<< "$COMPOSE_FLAGS"
3840

3941
echo ""
4042
echo "╔═══════════════════════════════════════════╗"
@@ -61,8 +63,24 @@ check() {
6163

6264
echo "1. Container Status"
6365
echo "───────────────────"
64-
check "llama-server running" "docker compose $COMPOSE_FLAGS ps llama-server 2>/dev/null | grep -qE 'Up|running'"
65-
check "Open WebUI running" "docker compose $COMPOSE_FLAGS ps open-webui 2>/dev/null | grep -qE 'Up|running'"
66+
# Compose-flag checks use array expansion directly (check() runs via bash -c
67+
# which can't preserve array boundaries across string handoff)
68+
printf " %-30s " "llama-server running..."
69+
if docker compose "${COMPOSE_FLAGS_ARR[@]}" ps llama-server 2>/dev/null | grep -qE 'Up|running'; then
70+
echo -e "${GREEN}✓ PASS${NC}"
71+
((PASSED++))
72+
else
73+
echo -e "${RED}✗ FAIL${NC}"
74+
((FAILED++))
75+
fi
76+
printf " %-30s " "Open WebUI running..."
77+
if docker compose "${COMPOSE_FLAGS_ARR[@]}" ps open-webui 2>/dev/null | grep -qE 'Up|running'; then
78+
echo -e "${GREEN}✓ PASS${NC}"
79+
((PASSED++))
80+
else
81+
echo -e "${RED}✗ FAIL${NC}"
82+
((FAILED++))
83+
fi
6684

6785
echo ""
6886
echo "2. Health Endpoints"
@@ -118,7 +136,7 @@ for sid in "${SERVICE_IDS[@]}"; do
118136
[[ -z "$_health" || "$_port" == "0" ]] && continue
119137

120138
# Check if container is running
121-
if docker compose $COMPOSE_FLAGS ps "$sid" 2>/dev/null | grep -qE "Up|running"; then
139+
if docker compose "${COMPOSE_FLAGS_ARR[@]}" ps "$sid" 2>/dev/null | grep -qE "Up|running"; then
122140
check "$_name" "curl -sf --max-time 10 http://localhost:${_port}${_health}"
123141
else
124142
printf " %-30s ${YELLOW}○ SKIP (not enabled)${NC}\n" "$_name..."

0 commit comments

Comments
 (0)