-
Notifications
You must be signed in to change notification settings - Fork 0
chore(cli): clean up old container images and stale binaries after update #581
Description
Summary
synthorg update pulls new container images but never removes old ones. Over multiple updates, stale images accumulate and waste disk space -- especially since images are digest-pinned (each version is a distinct layer set). Additionally, on Windows the old CLI binary is renamed to .old.*.tmp before replacement but cleanup relies on os.Remove in the same process; if the re-exec happens before that remove, or if the remove fails silently, stale .old.*.tmp files may persist.
Scope
1. Container image cleanup (uninstall)
PR #590 adds image cleanup to synthorg uninstall:
- Lists
ghcr.io/aureliolo/synthorg-*images with sizes - Prompts user for confirmation
- Removes via
docker rmi --forceby image ID
2. Windows binary auto-deletion (uninstall)
PR #590 replaces the manual PowerShell instruction with automatic cleanup:
- Writes a temp
.batfile that pollstasklistuntil the CLI PID exits - Deletes the binary, empty parent dirs, and the
.batitself - Falls back to manual PowerShell instruction if spawn fails
3. Container image cleanup (update) -- REMAINING
After pullAndPersist succeeds and before restartIfRunning, offer to prune the previous version's images:
- Track the previous image tag/digests (from
state.ImageTag/state.VerifiedDigestsbefore update) - After successful pull + persist, remove the old images (
docker rmithe previous digest-pinned refs) - Prompt user for confirmation in interactive mode; auto-accept in non-interactive
- Optionally run
docker image prune --filter dangling=trueto clean up any orphaned layers - Report disk space reclaimed
4. Windows stale .old.*.tmp cleanup on next invocation -- REMAINING
The selfupdate.ReplaceAt function on Windows:
- Creates a
.old.*.tmptemp file - Renames the current binary to that temp path
- Renames the new binary into place
- Calls
os.Remove(oldPath)-- best-effort
Remaining work:
- On next
synthorginvocation, scan the binary's directory for*.old.*.tmpfiles and remove them - Add a test that verifies no stale
.old.*.tmpfiles remain after a simulated update cycle
Acceptance Criteria
- Old container images are removed during uninstall (with user confirmation) -- PR fix(cli): auto-delete binary on Windows, prune images, fix GoReleaser #590
- Old container images are removed after successful update (with user confirmation)
- Disk space savings reported to user
- On Windows, binary auto-deleted after uninstall via temp .bat -- PR fix(cli): auto-delete binary on Windows, prune images, fix GoReleaser #590
- On Windows, stale
.old.*.tmpbinary files are cleaned up on next invocation - Tests cover both cleanup paths
- Non-interactive mode auto-accepts cleanup (no leftover images in CI)
Context
Discovered during PR #576 (CLI update compose refresh). The update flow was audited and this gap identified.