Skip to content

Commit d390a79

Browse files
committed
refactor(scripts): address PR NVIDIA#22 review feedback
Create shared shell library: - Add tasks/scripts/lib/common.sh with read_lines_into_array function - Update cluster-deploy-fast.sh to source shared library - Update scripts/bin/openshell to source shared library - Eliminates duplicate function definitions across scripts Remove redundant documentation and scripts: - Remove "Rebuilding After Code Changes" section from CONTRIBUTING.md (mise run cluster already documented in Main Tasks table) - Remove scripts/rebuild-cluster.sh (redundant with mise tasks) Add clarifying comments: - Document why Podman multi-arch cannot delegate to docker-build-image.sh - Explain TAGS_TO_APPLY array construction in docker-publish-multiarch.sh
1 parent cf18042 commit d390a79

6 files changed

Lines changed: 39 additions & 84 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,6 @@ These are the primary `mise` tasks for day-to-day development:
176176
| `mise run docs` | Build and serve documentation locally |
177177
| `mise run clean` | Clean build artifacts |
178178

179-
## Rebuilding After Code Changes
180-
181-
When developing OpenShell core components (gateway, router, sandbox supervisor), you need to rebuild the cluster to test your changes:
182-
183-
```bash
184-
bash scripts/rebuild-cluster.sh
185-
```
186-
187-
This script stops the cluster, rebuilds the image with your changes, and restarts it.
188-
189-
**After rebuilding:**
190-
- Providers need to be recreated (gateway database was reset)
191-
- Inference routing needs to be reconfigured
192-
- Sandboxes need to be recreated
193-
194-
For a complete cleanup, see the cleanup scripts in the `scripts/` directory.
195-
196179
## Project Structure
197180

198181
| Path | Purpose |

‎scripts/bin/openshell‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,8 @@ STATE_FILE="$PROJECT_ROOT/.cache/openshell-build.state"
1010
# Bash version compatibility helper
1111
# ---------------------------------------------------------------------------
1212

13-
# Read lines into an array variable (bash 3 & 4 compatible)
14-
# Usage: read_lines_into_array array_name < <(command)
15-
read_lines_into_array() {
16-
local array_name=$1
17-
if ((BASH_VERSINFO[0] >= 4)); then
18-
# Bash 4+: use mapfile (faster)
19-
mapfile -t "$array_name"
20-
else
21-
# Bash 3: use while loop
22-
local line
23-
eval "$array_name=()"
24-
while IFS= read -r line; do
25-
eval "$array_name+=(\"\$line\")"
26-
done
27-
fi
28-
}
13+
# shellcheck source=tasks/scripts/lib/common.sh
14+
source "$PROJECT_ROOT/tasks/scripts/lib/common.sh"
2915

3016
# ---------------------------------------------------------------------------
3117
# Fingerprint-based rebuild check

‎scripts/rebuild-cluster.sh‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎tasks/scripts/cluster-deploy-fast.sh‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,8 @@ log_duration() {
2828
echo "${label} took $((end - start))s"
2929
}
3030

31-
# Read lines into an array variable (bash 3 & 4 compatible)
32-
# Usage: read_lines_into_array array_name < <(command)
33-
read_lines_into_array() {
34-
local array_name=$1
35-
if ((BASH_VERSINFO[0] >= 4)); then
36-
# Bash 4+: use mapfile (faster)
37-
mapfile -t "$array_name"
38-
else
39-
# Bash 3: use while loop
40-
local line
41-
eval "$array_name=()"
42-
while IFS= read -r line; do
43-
eval "$array_name+=(\"\$line\")"
44-
done
45-
fi
46-
}
31+
# shellcheck source=lib/common.sh
32+
source "$(dirname "$0")/lib/common.sh"
4733

4834
if ! $CONTAINER_RUNTIME ps -q --filter "name=^${CONTAINER_NAME}$" --filter "health=healthy" | grep -q .; then
4935
echo "Error: Cluster container '${CONTAINER_NAME}' is not running or not healthy."

‎tasks/scripts/docker-publish-multiarch.sh‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
3030
echo "Note: Podman builds platforms sequentially (slower than Docker buildx)"
3131
export DOCKER_BUILDER=""
3232

33-
# Podman: build each platform separately and create manifest
33+
# Podman implements multi-arch via explicit manifest creation + per-platform
34+
# builds. Cannot use docker-build-image.sh here because it builds single
35+
# images, not manifests. Docker buildx handles multi-arch internally, so the
36+
# Docker path below can delegate to docker-build-image.sh.
3437
IFS=',' read -ra PLATFORM_ARRAY <<< "${PLATFORMS}"
3538

3639
for component in gateway cluster; do
@@ -98,6 +101,8 @@ else
98101
tasks/scripts/docker-build-image.sh cluster
99102
fi
100103

104+
# Build list of additional tags to apply (beyond IMAGE_TAG which is already set).
105+
# Combines EXTRA_TAGS with optional "latest" tag without modifying EXTRA_TAGS.
101106
TAGS_TO_APPLY=(${EXTRA_TAGS[@]+"${EXTRA_TAGS[@]}"})
102107
if [[ "${TAG_LATEST}" == "true" ]]; then
103108
TAGS_TO_APPLY+=("latest")

‎tasks/scripts/lib/common.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Common shell functions shared across task scripts
7+
8+
# Read lines into an array variable (bash 3 & 4 compatible)
9+
# Usage: read_lines_into_array array_name < <(command)
10+
#
11+
# Example:
12+
# read_lines_into_array my_files < <(ls *.txt)
13+
# for file in "${my_files[@]}"; do
14+
# echo "$file"
15+
# done
16+
read_lines_into_array() {
17+
local array_name=$1
18+
if ((BASH_VERSINFO[0] >= 4)); then
19+
# Bash 4+: use mapfile (faster)
20+
mapfile -t "$array_name"
21+
else
22+
# Bash 3: use while loop (macOS default bash is 3.x)
23+
local line
24+
eval "$array_name=()"
25+
while IFS= read -r line; do
26+
eval "$array_name+=(\"\$line\")"
27+
done
28+
fi
29+
}

0 commit comments

Comments
 (0)