Skip to content

feat: add ddev utility delete-volume to remove a project's Docker volume, fixes #6961 - #8756

Merged
stasadev merged 2 commits into
ddev:mainfrom
rfay:20260827_delete_volume
Aug 28, 2026
Merged

stasadev merged 2 commits into
ddev:mainfrom
rfay:20260827_delete_volume

Conversation

@rfay

@rfay rfay commented Aug 27, 2026

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

This PR adds ddev utility delete-volume, which deletes a Docker volume belonging to the current project by its short docker-compose name or full Docker name, or lets you pick one from an interactive list.

The Issue

Add-ons like ddev-solr create their own named Docker volumes, and there was no built-in way to remove one without reaching for raw docker volume rm and guessing at the actual volume name.

How This PR Solves The Issue

The command resolves the requested name against the project's own rendered docker-compose config (app.ComposeYaml.Volumes), so it correctly handles both the short compose-file key (solr) and whatever actual Docker volume name an add-on gives it (name:/external: overrides included), instead of guessing a naming convention. If no name is given, it shows an interactive picker (the same promptui used by ddev snapshot restore), with the database volume sorted last since it's normally the most destructive one to lose. Shared volumes used by every project (ddev-global-cache, ddev-ssh-agent_socket_dir) are excluded, since deleting them would affect other projects, not just the current one. If the project is running, the command asks to stop it first, since Docker won't remove a volume that's still mounted by a container; both that and the final deletion prompt are skippable with --yes.

Manual Testing Instructions

  1. In a project with an add-on that declares its own volume (e.g. ddev-solr), run ddev utility delete-volume with no arguments and confirm you get an interactive list with the database volume listed last.
  2. Run ddev utility delete-volume <short-name> and ddev utility delete-volume <full-docker-name> and confirm both resolve to the same volume.
  3. Run ddev utility delete-volume ddev-global-cache and confirm it's refused.
  4. Start the project, then delete one of its volumes; confirm you're prompted to stop the project first and that it does so before deleting.

Automated Testing Overview

TestDebugDeleteVolumeCmd in cmd/ddev/cmd/debug-delete-volume_test.go covers: rejecting an unknown volume name (and listing known volumes in the error), rejecting a shared/global volume name, stopping a running project and deleting its volume by short name, and deleting by full Docker name.

Release/Deployment Notes

None.

@rfay
rfay requested review from a team as code owners August 27, 2026 17:38
@rfay rfay changed the title feat: add ddev utility delete-volume to remove a project's Docker volume feat: add ddev utility delete-volume to remove a project's Docker volume, fixes #6961 Aug 27, 2026
…olume, fixes ddev#6961

This PR adds `ddev utility delete-volume`, which deletes a Docker volume belonging to the current project by its short docker-compose name or full Docker name, or lets you pick one from an interactive list.

- Fixes ddev#6961

Add-ons like ddev-solr create their own named Docker volumes, and there was no built-in way to remove one without reaching for raw `docker volume rm` and guessing at the actual volume name.

The command resolves the requested name against the project's own rendered docker-compose config (`app.ComposeYaml.Volumes`), so it correctly handles both the short compose-file key (`solr`) and whatever actual Docker volume name an add-on gives it (`name:`/`external:` overrides included), instead of guessing a naming convention. If no name is given, it shows an interactive picker (the same `promptui` used by `ddev snapshot restore`), with the database volume sorted last since it's normally the most destructive one to lose. Shared volumes used by every project (`ddev-global-cache`, `ddev-ssh-agent_socket_dir`) are excluded, since deleting them would affect other projects, not just the current one. If the project is running, the command asks to stop it first, since Docker won't remove a volume that's still mounted by a container; both that and the final deletion prompt are skippable with `--yes`.

1. In a project with an add-on that declares its own volume (e.g. ddev-solr), run `ddev utility delete-volume` with no arguments and confirm you get an interactive list with the database volume listed last.
2. Run `ddev utility delete-volume <short-name>` and `ddev utility delete-volume <full-docker-name>` and confirm both resolve to the same volume.
3. Run `ddev utility delete-volume ddev-global-cache` and confirm it's refused.
4. Start the project, then delete one of its volumes; confirm you're prompted to stop the project first and that it does so before deleting.

`TestDebugDeleteVolumeCmd` in `cmd/ddev/cmd/debug-delete-volume_test.go` covers: rejecting an unknown volume name (and listing known volumes in the error), rejecting a shared/global volume name, stopping a running project and deleting its volume by short name, and deleting by full Docker name.

None.
@rfay
rfay force-pushed the 20260827_delete_volume branch from 96d7f5c to add64b0 Compare August 27, 2026 17:40
@rfay
rfay requested a review from stasadev August 27, 2026 17:40
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8756

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great!

Two things I noticed that I'd like to improve:

  • When I deleted the volume and ran ddev utility delete-volume again, it still appeared in the list, even though it no longer exists.
  • It would also be great if autocompletion worked here: ddev utility delete-volume <TAB>

…tion

Addresses review feedback on ddev#8756 (review 5044336433):
- Only list/match volumes that still exist in Docker, so a volume already
  deleted no longer shows up in the interactive picker or the "unknown name"
  error listing.
- Add shell tab completion for the volume-name argument, sourced from the
  same existing-volumes list.
@rfay

rfay commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

Done! Pretty fancy for an off-beat utility function :)

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

@stasadev
stasadev merged commit 908d4e4 into ddev:main Aug 28, 2026
44 checks passed
@stasadev
stasadev deleted the 20260827_delete_volume branch August 28, 2026 10:11
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 7, 2026
…hand

## Short Summary (TL;DR)

The all-project-types job is the only CI job that runs tests with `GOTEST_SHORT` unset, and it ran a hand-kept list that had fallen behind, so 16 tests that skip or shrink under `GOTEST_SHORT` never ran in full anywhere. The list is now generated from the tests themselves, so it can't fall behind again.

## The Issue

Found while working on ddev#7904, which changes `TestDebugRebuildCmd`: CI logs show `--- SKIP: TestDebugRebuildCmd` in every job, because Buildkite and `test-reusable.yml` set `GOTEST_SHORT=16` and apache-fpm sets `5`.

The list came from ddev#6693 and broke in three ways:

- ddev#7027 renamed `TestComposerCreateCmd` to `TestComposerCreateProjectCmd`, so that entry has matched nothing since.
- ddev#8028 added `GOTEST_SHORT` skips to `TestDebugRebuildCmd`, `TestDdevImportDB`, `TestDdevRestoreSnapshot`, `TestProcessHooks`, and `TestWebserverMariaMySQLDBClient`, and later PRs did the same for `TestEphemeralPortsReusedOnRestart` (ddev#7992), `TestRouterPortSubstitutionPersistsAcrossProjects` (ddev#8653), `TestSnapshotUncompressed` (ddev#8704), `TestDebugDeleteVolumeCmd` (ddev#8756), and `TestDdevExportDB` (ddev#8798), none of them updating the list.
- `TestComposerVersionConfig`, `TestHttpsRedirection`, `TestMysqlCommand`, `TestDdevStartMultipleHostnames`, and `TestProjectAutocompletionForExecCmd` already did less under `GOTEST_SHORT` when ddev#6693 wrote the list, and weren't on it.

## How This PR Solves The Issue

Tests use three `testcommon` helpers instead of reading `GOTEST_SHORT`: `SkipIfGotestShort(t)`, `IsGotestShort(t)`, and `UsesAllTestSites(t)`, a marker for tests that loop over every test site. `.github/workflows/all-project-types-tests.sh` finds the tests that call them and prints the `-run` pattern, and fails if a test other than `TestMain` reads `GOTEST_SHORT` itself.

The pattern is anchored, so prefix matches such as every `TestCmdStart*` test or `TestAutocompleteServiceForServiceFlag` no longer ride along; like `TestAppdirAlreadyInUse` and `TestConfigValidate`, which also leave the list, they don't depend on `GOTEST_SHORT` and run in every job. The `GOTEST_SHORT` branches that ddev#8028 made unreachable in `TestComposerCreateProjectCmd` and `TestDdevAllDatabases` are removed.

## Manual Testing Instructions

```bash
.github/workflows/all-project-types-tests.sh
# Expect ^(TestAutocompletionForDescribeCmd|...|TestWriteDrushConfig)\b with the 42 tests below
```

Adding `if os.Getenv("GOTEST_SHORT") != "" { t.Skip() }` to any test makes the script print that file and line and exit non-zero.

## Automated Testing Overview

In the all-project-types job, the "Compute TESTARGS" step of `prepare-testargs` should print a `-run '^(...)\b'` pattern with exactly these 42 tests, and the test log should show each of them running, none skipped because of `GOTEST_SHORT`:

```text
TestAutocompletionForDescribeCmd TestAutocompletionForStartCmd TestAutocompletionForStopCmd
TestAvailableUpdates TestCmdDescribe TestCmdDescribeAppFunction TestCmdDescribeAppUsingSitename
TestCmdList TestCmdStart TestCmdStop TestComposerCreateProjectCmd TestComposerVersionConfig
TestConfigDatabaseVersion TestDdevAllDatabases TestDdevExportDB TestDdevFullSiteSetup
TestDdevImportDB TestDdevImportFiles TestDdevImportFilesCustomUploadDir TestDdevImportFilesDir
TestDdevRestoreSnapshot TestDdevStartMultipleHostnames TestDdevUploadDirNoPackage
TestDdevXdebugEnabled TestDdevXhprofPrependEnabled TestDdevXhprofXhguiEnabled
TestDebugDeleteVolumeCmd TestDebugRebuildCmd TestEphemeralPortsReusedOnRestart TestGetApps
TestGetAppsEmpty TestHardenedStart TestHttpsRedirection TestMysqlCommand TestPHPConfig
TestPHPWebserverType TestProcessHooks TestProjectAutocompletionForExecCmd
TestRouterPortSubstitutionPersistsAcrossProjects TestSnapshotUncompressed
TestWebserverMariaMySQLDBClient TestWriteDrushConfig
```

Some of the 16 tests that never ran in full may fail after being skipped this long; this PR's run is where that should show up.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 8, 2026
…hand

## Short Summary (TL;DR)

The all-project-types job is the only CI job that runs tests with `GOTEST_SHORT` unset, and it ran a hand-kept list that had fallen behind, so 16 tests that skip or shrink under `GOTEST_SHORT` never ran in full anywhere. The list is now generated from the tests themselves, so it can't fall behind again.

## The Issue

Found while working on ddev#7904, which changes `TestDebugRebuildCmd`: CI logs show `--- SKIP: TestDebugRebuildCmd` in every job, because Buildkite and `test-reusable.yml` set `GOTEST_SHORT=16` and apache-fpm sets `5`.

The list came from ddev#6693 and broke in three ways:

- ddev#7027 renamed `TestComposerCreateCmd` to `TestComposerCreateProjectCmd`, so that entry has matched nothing since.
- ddev#8028 added `GOTEST_SHORT` skips to `TestDebugRebuildCmd`, `TestDdevImportDB`, `TestDdevRestoreSnapshot`, `TestProcessHooks`, and `TestWebserverMariaMySQLDBClient`, and later PRs did the same for `TestEphemeralPortsReusedOnRestart` (ddev#7992), `TestRouterPortSubstitutionPersistsAcrossProjects` (ddev#8653), `TestSnapshotUncompressed` (ddev#8704), `TestDebugDeleteVolumeCmd` (ddev#8756), and `TestDdevExportDB` (ddev#8798), none of them updating the list.
- `TestComposerVersionConfig`, `TestHttpsRedirection`, `TestMysqlCommand`, `TestDdevStartMultipleHostnames`, and `TestProjectAutocompletionForExecCmd` already did less under `GOTEST_SHORT` when ddev#6693 wrote the list, and weren't on it.

## How This PR Solves The Issue

Tests use three `testcommon` helpers instead of reading `GOTEST_SHORT`: `SkipIfGotestShort(t)`, `IsGotestShort(t)`, and `UsesAllTestSites(t)`, a marker for tests that loop over every test site. `.github/workflows/all-project-types-tests.sh` finds the tests that call them and prints the `-run` pattern, and fails if a test other than `TestMain` reads `GOTEST_SHORT` itself.

The pattern is anchored, so prefix matches such as every `TestCmdStart*` test or `TestAutocompleteServiceForServiceFlag` no longer ride along; like `TestAppdirAlreadyInUse` and `TestConfigValidate`, which also leave the list, they don't depend on `GOTEST_SHORT` and run in every job. The `GOTEST_SHORT` branches that ddev#8028 made unreachable in `TestComposerCreateProjectCmd` and `TestDdevAllDatabases` are removed.

## Manual Testing Instructions

```bash
.github/workflows/all-project-types-tests.sh
# Expect ^(TestAutocompletionForDescribeCmd|...|TestWriteDrushConfig)\b with the 42 tests below
```

Adding `if os.Getenv("GOTEST_SHORT") != "" { t.Skip() }` to any test makes the script print that file and line and exit non-zero.

## Automated Testing Overview

In the all-project-types job, the "Compute TESTARGS" step of `prepare-testargs` should print a `-run '^(...)\b'` pattern with exactly these 42 tests, and the test log should show each of them running, none skipped because of `GOTEST_SHORT`:

```text
TestAutocompletionForDescribeCmd TestAutocompletionForStartCmd TestAutocompletionForStopCmd
TestAvailableUpdates TestCmdDescribe TestCmdDescribeAppFunction TestCmdDescribeAppUsingSitename
TestCmdList TestCmdStart TestCmdStop TestComposerCreateProjectCmd TestComposerVersionConfig
TestConfigDatabaseVersion TestDdevAllDatabases TestDdevExportDB TestDdevFullSiteSetup
TestDdevImportDB TestDdevImportFiles TestDdevImportFilesCustomUploadDir TestDdevImportFilesDir
TestDdevRestoreSnapshot TestDdevStartMultipleHostnames TestDdevUploadDirNoPackage
TestDdevXdebugEnabled TestDdevXhprofPrependEnabled TestDdevXhprofXhguiEnabled
TestDebugDeleteVolumeCmd TestDebugRebuildCmd TestEphemeralPortsReusedOnRestart TestGetApps
TestGetAppsEmpty TestHardenedStart TestHttpsRedirection TestMysqlCommand TestPHPConfig
TestPHPWebserverType TestProcessHooks TestProjectAutocompletionForExecCmd
TestRouterPortSubstitutionPersistsAcrossProjects TestSnapshotUncompressed
TestWebserverMariaMySQLDBClient TestWriteDrushConfig
```

Some of the 16 tests that never ran in full may fail after being skipped this long; this PR's run is where that should show up.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a command to delete a volume by name

2 participants