Skip to content

Commit 65b0db4

Browse files
MohammedTariggtw93
andauthored
feat(clean): add opt-in Docker unused data pruning (#554)
* feat(clean): add opt-in Docker unused data pruning * fix(clean): make docker prune default --------- Co-authored-by: Tw93 <hitw93@gmail.com>
1 parent 2f627ac commit 65b0db4

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

lib/clean/dev.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,18 @@ clean_dev_docker() {
198198
fi
199199
stop_section_spinner
200200
if [[ "$docker_running" == "true" ]]; then
201-
clean_tool_cache "Docker build cache" docker builder prune -af
201+
# Remove unused images, stopped containers, unused networks, and
202+
# anonymous volumes in one pass. This maps better to the large
203+
# reclaimable "docker system df" buckets users typically see.
204+
clean_tool_cache "Docker unused data" docker system prune -af --volumes
202205
else
206+
echo -e " ${GRAY}${ICON_WARNING}${NC} Docker unused data · skipped (daemon not running)"
207+
note_activity
203208
debug_log "Docker daemon not running, skipping Docker cache cleanup"
204209
fi
205210
else
206211
note_activity
207-
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Docker build cache · would clean"
212+
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Docker unused data · would clean"
208213
fi
209214
fi
210215
safe_clean ~/.docker/buildx/cache/* "Docker BuildX cache"

tests/clean_dev_caches.bats

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,50 @@ EOF
160160
}
161161

162162
@test "clean_dev_docker skips when daemon not running" {
163-
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" MO_DEBUG=1 DRY_RUN=false bash --noprofile --norc <<'EOF'
163+
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
164164
set -euo pipefail
165165
source "$PROJECT_ROOT/lib/core/common.sh"
166166
source "$PROJECT_ROOT/lib/clean/dev.sh"
167167
start_section_spinner() { :; }
168168
stop_section_spinner() { :; }
169169
run_with_timeout() { return 1; }
170-
clean_tool_cache() { echo "$1"; }
171170
safe_clean() { echo "$2"; }
172-
debug_log() { echo "$*"; }
171+
debug_log() { :; }
173172
docker() { return 1; }
174173
export -f docker
175174
clean_dev_docker
176175
EOF
177176

178177
[ "$status" -eq 0 ]
179-
[[ "$output" == *"Docker daemon not running"* ]]
180-
[[ "$output" != *"Docker build cache"* ]]
178+
[[ "$output" == *"Docker unused data · skipped (daemon not running)"* ]]
179+
[[ "$output" == *"Docker BuildX cache"* ]]
180+
[[ "$output" != *"Docker unused data|Docker unused data docker system prune -af --volumes"* ]]
181+
}
182+
183+
@test "clean_dev_docker prunes unused docker data when daemon is running" {
184+
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
185+
set -euo pipefail
186+
source "$PROJECT_ROOT/lib/core/common.sh"
187+
source "$PROJECT_ROOT/lib/clean/dev.sh"
188+
start_section_spinner() { :; }
189+
stop_section_spinner() { :; }
190+
run_with_timeout() { shift; "$@"; }
191+
clean_tool_cache() { echo "$1|$*"; }
192+
safe_clean() { :; }
193+
note_activity() { :; }
194+
debug_log() { :; }
195+
docker() {
196+
if [[ "$1" == "info" ]]; then
197+
return 0
198+
fi
199+
return 0
200+
}
201+
export -f docker
202+
clean_dev_docker
203+
EOF
204+
205+
[ "$status" -eq 0 ]
206+
[[ "$output" == *"Docker unused data|Docker unused data docker system prune -af --volumes"* ]]
181207
}
182208

183209
@test "clean_developer_tools runs key stages" {

0 commit comments

Comments
 (0)