Skip to content

feat: implement OpenRAG image management and cleanup functionality#1056

Merged
ricofurtado merged 4 commits intomainfrom
1015-factory-reset-deletes-other-docker-images
Mar 9, 2026
Merged

feat: implement OpenRAG image management and cleanup functionality#1056
ricofurtado merged 4 commits intomainfrom
1015-factory-reset-deletes-other-docker-images

Conversation

@ricofurtado
Copy link
Collaborator

@ricofurtado ricofurtado commented Mar 2, 2026

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:

  • Added a single source of truth for OpenRAG image repositories as OPENRAG_IMAGE_REPOS in both the Makefile and Python modules, ensuring consistent identification of relevant images across all tooling.

Makefile improvements:

  • Introduced a new remove-openrag-images Makefile target that removes only OpenRAG images, and updated the clean and factory-reset targets to use this safer cleanup method instead of running a full system prune.

Python utility enhancements:

  • Added functions in startup_checks.py for extracting repositories, checking if an image is OpenRAG-related, and removing only OpenRAG images, replacing the previous broad docker system prune approach.

TUI (Terminal UI) container management updates:

  • Refactored the TUI's ContainerManager to 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:

  • Updated user prompts and status messages throughout the CLI/TUI and Makefile to clearly indicate when only OpenRAG images are being removed, reducing confusion and risk.

@github-actions github-actions bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) tests enhancement 🔵 New feature or request labels Mar 2, 2026
@ricofurtado ricofurtado self-assigned this Mar 2, 2026
@ricofurtado ricofurtado requested review from Copilot and mpawlow March 2, 2026 21:35
@github-actions github-actions bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Mar 2, 2026
@ricofurtado ricofurtado requested a review from lucaseduoli March 2, 2026 21:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1332 to 1343
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)",
)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 1475 to 1481
"""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
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Makefile Outdated
Comment on lines +452 to +458
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)); \
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering...

Comment on lines +3 to +6
from unittest.mock import MagicMock, patch

from src.tui.utils import startup_checks

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +130
result = subprocess.run(
[runtime, "images", "--format", "{{.Repository}}:{{.Tag}}\t{{.ID}}"],
capture_output=True,
text=True,
)
if result.returncode != 0:
return 0, 0

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Mar 5, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Mar 5, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions github-actions bot added enhancement 🔵 New feature or request and removed enhancement 🔵 New feature or request labels Mar 5, 2026
Copy link
Collaborator

@mpawlow mpawlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricofurtado

Code Review 1

  • ✅ LGTM / Approved
  • See PR comment: (1a)
    • Minor severity issue

else:
yield False, f"Failed to prune dangling images: {stderr}"

yield True, "All OpenRAG images removed successfully"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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_remove branch 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

@github-actions github-actions bot added the lgtm label Mar 9, 2026
@ricofurtado ricofurtado merged commit 2d506e9 into main Mar 9, 2026
11 checks passed
@github-actions github-actions bot deleted the 1015-factory-reset-deletes-other-docker-images branch March 9, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) enhancement 🔵 New feature or request lgtm tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants