Skip to content

feat: add dr docker entity for container/image/volume removal and prune#39

Merged
vitali87 merged 1 commit intomainfrom
feat/dr-docker
Mar 27, 2026
Merged

feat: add dr docker entity for container/image/volume removal and prune#39
vitali87 merged 1 commit intomainfrom
feat/dr-docker

Conversation

@vitali87
Copy link
Copy Markdown
Owner

Summary

  • dr docker container <id> — force remove a container
  • dr docker image <id> — remove an image
  • dr docker volume <name> — remove a volume
  • dr docker prune — system prune with y/n confirmation (dry-run supported)
  • Docker install check before running commands

Test plan

  • u7 dr docker shows usage
  • u7 --dry-run dr docker prune shows dry-run output
  • Run full test suite

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87
Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the dr utility by integrating Docker resource management capabilities. It introduces a new dr docker subcommand, allowing users to efficiently remove containers, images, and volumes, as well as perform a system-wide prune with safety features like confirmation and dry-run. The changes aim to streamline Docker maintenance tasks within the existing utility framework.

Highlights

  • New dr docker command: Introduced a new dr docker subcommand to manage Docker resources directly from the command line.
  • Container removal: Added functionality to force remove a Docker container using dr docker container <id>.
  • Image removal: Implemented the ability to remove a Docker image with dr docker image <id>.
  • Volume removal: Provided a command to remove a Docker volume using dr docker volume <name>.
  • System prune with confirmation: Added dr docker prune for system-wide cleanup, including a y/n confirmation and dry-run support.
  • Docker installation check: Included a check to ensure Docker is installed before executing any dr docker commands.
  • New tests: Added new tests to verify the usage of dr docker and the dry-run functionality of dr docker prune.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds new functionality to the dr command for managing Docker resources, including removing containers, images, and volumes, as well as a system prune option. The changes are well-structured and include new tests. I have a couple of suggestions to improve the user experience of the confirmation prompt and to enhance test coverage for the new Docker commands.

utility.sh Outdated
else
echo "This will remove all stopped containers, unused images, and build cache. Continue? (y/n)"
read -r confirm
if [[ "${confirm,,}" == "y" ]]; then
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This confirmation check only accepts 'y' or 'Y'. It would be more user-friendly to also accept 'yes'. You can use a regular expression for a more robust check.

Suggested change
if [[ "${confirm,,}" == "y" ]]; then
if [[ "${confirm,,}" =~ ^(y|yes)$ ]]; then

Comment on lines +841 to +847
# Test: dr docker without subcommand shows usage
result=$(u7 dr docker 2>&1)
assert_contains "dr docker shows usage" "Usage:" "$result"

# Test: dr docker prune dry-run
result=$(u7 --dry-run dr docker prune 2>&1)
assert_contains "dr docker prune dry-run works" "[dry-run]" "$result"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The added tests for usage and dry-run are a good start. However, they don't cover the core functionality of removing Docker entities (containers, images, volumes) or the interactive prune. Consider adding more comprehensive tests for these cases. These tests could be conditionally run if Docker is available, similar to the existing sh docker containers test.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR adds a new docker entity to the u7 dr (drop) command, supporting force-removal of containers, images, and volumes by ID/name, plus a docker system prune with an interactive confirmation prompt.

All concerns raised in prior review threads have been addressed in this revision:

  • The docker install check is now correctly skipped for dry-run and for the "" usage-display branch.
  • read is redirected from /dev/tty so it always reads from the terminal, not piped stdin.
  • The abort path now returns exit code 1.
  • prune delegates actual execution to _u7_exec, keeping dry-run handling consistent.
  • New tests are written entirely using dry-run or no-subcommand paths, so they pass on machines without Docker installed.

Two minor P2 items remain:

  • The prune confirmation message does not mention unused networks, which docker system prune -af also removes.
  • docker rm -f (force) is used for containers but docker rmi (no -f) is used for images, with no comment explaining the intentional asymmetry.

Confidence Score: 5/5

Safe to merge — all previously raised P0/P1 concerns are resolved; only minor P2 style suggestions remain.

All critical issues from previous review threads (dry-run/install-check ordering, stdin redirect, abort exit code, _u7_exec consistency) are correctly fixed. Remaining findings are P2 style/documentation items that do not block correct operation.

No files require special attention.

Important Files Changed

Filename Overview
lib/drop.sh Adds a docker entity to _u7_drop with container/image/volume removal and system prune. All prior concerns (docker-check ordering, /dev/tty redirect, abort exit code, _u7_exec delegation, dry-run guards) are correctly addressed. Two minor P2 issues remain: the prune confirmation message omits unused networks, and the inconsistent use of -f between docker rm and docker rmi.
test.sh Adds five new docker tests (usage display + four dry-run variants). All tests are correctly crafted to not require docker being installed — dry-run tests bypass the docker check, and the usage test hits the empty-string branch before any docker check.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["u7 dr docker &lt;subcommand&gt; [id]"] --> B{subcommand?}
    B -->|empty| C["print Usage → return 0"]
    B -->|unknown| D["print Usage → return 1"]
    B -->|container / image / volume| E{dry-run?}
    E -->|yes| F["skip docker check"]
    E -->|no| G{docker installed?}
    G -->|no| H["Error: docker not in PATH → return 1"]
    G -->|yes| F
    F --> I{id provided?}
    I -->|no| J["print subcommand Usage → return 1"]
    I -->|yes| K["_u7_exec docker rm -f / rmi / volume rm"]
    B -->|prune| L{dry-run?}
    L -->|yes| M["echo [dry-run] docker system prune -af → return 0"]
    L -->|no| N{docker installed?}
    N -->|no| H
    N -->|yes| O["Prompt: Continue? (y/n) from /dev/tty"]
    O -->|y| P["_u7_exec docker system prune -af"]
    O -->|other| Q["echo Aborted → return 1"]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: lib/drop.sh
Line: 190

Comment:
**Prune confirmation message omits unused networks**

`docker system prune -af` also removes all unused networks, but the confirmation text only mentions stopped containers, unused images, and build cache. Users could be surprised to find their custom Docker networks removed.

```suggestion
          echo "This will remove all stopped containers, unused networks, unused images, and build cache. Continue? (y/n)"
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: lib/drop.sh
Line: 173-180

Comment:
**Inconsistent force-removal flags between `container` and `image`**

`docker rm -f` force-removes a running container, but `docker rmi` (no `-f`) will fail if the image has multiple tags or is referenced by a stopped container. Users who run `u7 dr docker image <id>` on a multi-tagged image will get a confusing Docker error instead of a clear message. Either document this behaviour, or use the modern canonical subcommand forms consistently:

```bash
# container
_u7_exec docker container rm -f "$2"
# image — deliberately no -f to prevent accidental removal of shared images
_u7_exec docker image rm "$2"
# volume
_u7_exec docker volume rm "$2"
```

At minimum, adding a comment to explain that `-f` is intentionally omitted for `image` (to avoid removing images still referenced by other tags) would prevent future confusion.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (8): Last reviewed commit: "feat: add dr docker entity with dry-run ..." | Re-trigger Greptile

@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

2 similar comments
@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

1 similar comment
@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87
Copy link
Copy Markdown
Owner Author

@greptile

@vitali87 vitali87 merged commit c2502cf into main Mar 27, 2026
3 checks passed
@vitali87 vitali87 deleted the feat/dr-docker branch March 27, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant