Skip to content

Commit d45c1a7

Browse files
fix(scripts): eliminate xargs subshell dependency in docker-cleanup.sh (ai-openshell#1207)
Replace xargs usage with native docker/podman multi-argument inspect calls. The previous implementation failed because xargs spawns subshells that don't inherit the ce() function from container-engine.sh. Instead of piping container IDs through xargs, collect them into an array and pass them directly to `ce inspect`, which accepts multiple IDs. This eliminates the subshell issue entirely and simplifies the code. Fixes the docker:cleanup mise task that was failing with: xargs: ce: No such file or directory Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent fb472f5 commit d45c1a7

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎scripts/docker-cleanup.sh‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ info "Removing stale tagged images..."
177177

178178
# Collect image IDs that are directly used by running containers so we never
179179
# touch them regardless of tag matching.
180-
running_image_ids=$(ce ps -q 2>/dev/null | xargs -r ce inspect --format '{{.Image}}' 2>/dev/null | sort -u)
180+
container_ids=($(ce ps -q 2>/dev/null))
181+
if [[ ${#container_ids[@]} -gt 0 ]]; then
182+
running_image_ids=$(ce inspect --format '{{.Image}}' "${container_ids[@]}" 2>/dev/null | sort -u)
183+
else
184+
running_image_ids=""
185+
fi
181186

182187
stale_images=()
183188
while IFS=$'\t' read -r repo tag id; do
@@ -215,9 +220,13 @@ echo
215220
info "Removing unused volumes..."
216221

217222
# Identify volumes in use by running containers
218-
in_use_volumes=$(ce ps -q 2>/dev/null \
219-
| xargs -r ce inspect --format '{{range .Mounts}}{{.Name}} {{end}}' 2>/dev/null \
220-
| tr ' ' '\n' | sort -u | grep -v '^$' || true)
223+
container_ids=($(ce ps -q 2>/dev/null))
224+
if [[ ${#container_ids[@]} -gt 0 ]]; then
225+
in_use_volumes=$(ce inspect --format '{{range .Mounts}}{{.Name}} {{end}}' "${container_ids[@]}" 2>/dev/null \
226+
| tr ' ' '\n' | sort -u | grep -v '^$' || true)
227+
else
228+
in_use_volumes=""
229+
fi
221230

222231
unused_volumes=()
223232
while read -r vol; do

0 commit comments

Comments
 (0)