feat: implement OpenRAG image management and cleanup functionality#1056
feat: implement OpenRAG image management and cleanup functionality#1056ricofurtado merged 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refines Docker/Podman cleanup behavior so “reset/cleanup” operations remove only OpenRAG-related images (instead of pruning the entire container runtime), reducing the risk of deleting unrelated images.
Changes:
- Add OpenRAG image repository allow-lists and helper logic to identify/remove only matching images.
- Update TUI container management reset/prune flows to use OpenRAG-only image listing/removal (no
system prune). - Add unit tests covering OpenRAG-only image filtering and ensuring Docker “storage corruption” fixes don’t call
system prune.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_startup_checks_cleanup.py | Adds tests for OpenRAG-only image removal and avoiding Docker system prune. |
| tests/unit/test_container_manager_cleanup.py | Adds tests for ContainerManager OpenRAG-only image listing and reset behavior. |
| src/tui/utils/startup_checks.py | Introduces OpenRAG repo allow-list + Docker-safe cleanup path for storage corruption handling. |
| src/tui/managers/container_manager.py | Adds OpenRAG image discovery helper and updates reset/prune routines to avoid global pruning. |
| Makefile | Adds remove-openrag-images target and routes clean/factory-reset through OpenRAG-only image removal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| removed = 0 | ||
| for image_id, image_tag in image_ids: | ||
| success, _, stderr = await self._run_runtime_command(["rmi", image_id]) | ||
| if success: | ||
| removed += 1 | ||
| else: | ||
| yield False, f"Could not remove {image_tag}: {stderr.strip()}" | ||
|
|
||
| yield ( | ||
| True, | ||
| "System reset completed - all containers, volumes, and local images removed", | ||
| f"System reset completed - removed {removed} OpenRAG image(s)", | ||
| ) |
There was a problem hiding this comment.
reset_services() yields error updates when an image removal fails, but it still yields a final (True, ...) success message unconditionally. Track whether any removals failed and make the final status reflect partial/total failure (or return early on the first failure).
| """Prune old OpenRAG images and dependencies, keeping only the latest versions. | ||
|
|
||
| This method: | ||
| 1. Lists all images | ||
| 2. Identifies OpenRAG-related images (openrag-backend, openrag-frontend, langflow, opensearch, dashboards) | ||
| 3. For each repository, keeps only the latest/currently used image | ||
| 4. Removes old images |
There was a problem hiding this comment.
The docstring says this method "Lists all images", but the implementation now calls _list_openrag_images(...) which filters to OpenRAG-related repositories only. Update the numbered steps so the documentation matches the behavior.
Makefile
Outdated
| remove-openrag-images: ## Remove OpenRAG images only (safe for other projects) | ||
| @echo "$(YELLOW)Removing OpenRAG images only...$(NC)" | ||
| @removed=0; total=0; \ | ||
| for repo in $(OPENRAG_IMAGE_REPOS); do \ | ||
| ids=$$($(CONTAINER_RUNTIME) images "$$repo" -q 2>/dev/null | sort -u); \ | ||
| for id in $$ids; do \ | ||
| total=$$((total+1)); \ |
There was a problem hiding this comment.
remove-openrag-images only queries docker images "$$repo", so it may miss images tagged with an explicit registry prefix (e.g. docker.io/langflowai/openrag-frontend) even though the Python cleanup logic handles that case. Consider expanding the repo patterns (or using a single images --format scan like the Python implementation) so Makefile cleanup is consistent.
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from src.tui.utils import startup_checks | ||
|
|
There was a problem hiding this comment.
The unit tests import/patch src.tui..., but src/ is not a Python package in this repo (no src/__init__.py). Existing tests import from tui..., so these imports will fail during test collection. Update the import and patch targets to use the installed package path (e.g., tui.utils.startup_checks).
| result = subprocess.run( | ||
| [runtime, "images", "--format", "{{.Repository}}:{{.Tag}}\t{{.ID}}"], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| if result.returncode != 0: | ||
| return 0, 0 | ||
|
|
There was a problem hiding this comment.
remove_openrag_images() returns (0, 0) when docker/podman images fails, which is indistinguishable from “no OpenRAG images found”. That makes callers treat failures as success. Consider returning a success flag / error message (or raising) so failures can be surfaced and handled.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| else: | ||
| yield False, f"Failed to prune dangling images: {stderr}" | ||
|
|
||
| yield True, "All OpenRAG images removed successfully" |
There was a problem hiding this comment.
(1a) [Minor] prune_all_images emits a misleading "All OpenRAG images removed successfully" message even when no images were found
- i.e. The
if not images_to_removebranch yields "No OpenRAG images found to remove" but lacks a return, so execution always falls through to the unconditional final yield. - Note: This is Minor severity. Please feel free to optionally implement or ignore
Bug Description
When experimenting with the first setup, I tried to factory reset my OpenRAG from TUI. To my surprise, all other dockers were gone from Docker desktop app, not only those OpenRAGs, but ALL OF THEM. This is certainly not something one would expect
Solution
This pull request refines how OpenRAG-related Docker/Podman images are identified and removed throughout the codebase, making image cleanup safer and more targeted. It introduces a centralized list of OpenRAG image repositories, implements dedicated logic for removing only relevant images (instead of pruning all system images), and updates both the Makefile and Python utilities/TUI to use this logic. This reduces the risk of accidentally deleting unrelated images and improves maintainability.
Centralized OpenRAG image repository management:
OPENRAG_IMAGE_REPOSin both theMakefileand Python modules, ensuring consistent identification of relevant images across all tooling.Makefile improvements:
remove-openrag-imagesMakefile target that removes only OpenRAG images, and updated thecleanandfactory-resettargets to use this safer cleanup method instead of running a fullsystem prune.Python utility enhancements:
startup_checks.pyfor extracting repositories, checking if an image is OpenRAG-related, and removing only OpenRAG images, replacing the previous broaddocker system pruneapproach.TUI (Terminal UI) container management updates:
ContainerManagerto use the new OpenRAG image identification logic for image listing, removal, and pruning, ensuring only relevant images are affected and removing duplicated logic.User experience and messaging: