Skip to content

feat: keep shell and client history in bind-mounted .ddev/.history, for #8895 - #8964

Closed
rfay wants to merge 4 commits into
mainfrom
20261017_rfay_history_bind_mounts
Closed

rfay wants to merge 4 commits into
mainfrom
20261017_rfay_history_bind_mounts

Conversation

@rfay

@rfay rfay commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

This is an alternate implementation of #8947, following @stasadev's suggestion there to use a bind mount instead of a volume per container. Every service that can safely use it, not only web and db, keeps its shell and database client history in .ddev/.history/<service> on the host, bind-mounted at /mnt/ddev-history. Only one of this PR and #8947 should be merged.

The Issue

History lived in ddev-global-cache, which every project's containers mount read-write, so it doesn't fit providers like Apple container that need a single writer per volume. A bind mount avoids that limit, but it can leave root-owned files in the project that the user can't remove without sudo, so this has to prevent that without any escalation on the host.

How This PR Solves The Issue

Services beyond web and db. While generating the compose file, DDEV checks every service, including custom services and add-ons, and adds the history mount to any service that runs as the uid the host user maps to. That uid is the host uid on rootful Docker and on Podman with keep-id, 0 on rootless Docker, and any uid on macOS and Windows providers, which map ownership. In practice that means web, db, and custom services with user: "${DDEV_UID}:${DDEV_GID}" with rootful Docker or Podman on Linux, and every service on macOS and Windows. A third-party service running as root there gets no mount, because its files would be root-owned on the host. Rootless Docker is the reverse: container root is the host user, so web (which already runs as root there) and root-running services get the mount, while db does not. Each mounted service gets HISTFILE, MYSQL_HISTFILE, PSQL_HISTORY, REDISCLI_HISTFILE, SQLITE_HISTORY, NODE_REPL_HISTORY and PYTHON_HISTORY, unless it already sets them, so tools like redis-cli or sqlite3 in an add-on keep history too. x-ddev.omit-history: true leaves a service out.

Preventing root-owned files. DDEV creates .ddev/.history/<service> as the host user before compose up, with a .gitignore of * so history never reaches Git. The mount uses create_host_path: false, so Docker can't create the directory as root. In the web image, a shell running as another uid, such as a root shell, keeps its history in the container instead. On Linux, anything root writes there anyway is given back to the host user by the existing chown container on ddev start, and by a chown container on ddev delete, both through Docker so no sudo is needed.

Nothing is kept with no_bind_mounts. The db image is unchanged, so a root shell in db still writes to the mount until the db image next changes, and the chown on start and delete covers that.

Compared with #8947, there are no volumes to create, seed, or remove, and history survives docker system prune --volumes and switching Docker providers. The cost is the ownership handling above, which #8947 doesn't need because volume contents never reach the host.

Manual Testing Instructions

On Linux with rootful Docker:

ddev utility download-ddev --pr 8964
export PATH="$HOME/tmp/ddev-download-ddev/pr-8964:$PATH"
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php
cat > .ddev/docker-compose.extra.yaml <<'EOF'
services:
  asroot:
    container_name: ddev-${DDEV_SITENAME}-asroot
    image: busybox:stable
    command: sleep infinity
  asuser:
    container_name: ddev-${DDEV_SITENAME}-asuser
    image: busybox:stable
    command: sleep infinity
    user: "${DDEV_UID}:${DDEV_GID}"
EOF
ddev start
ls -la .ddev/.history
# Expect .gitignore, web, db and asuser owned by you, and no asroot
ddev exec -u root "bash -ic 'echo \$HISTFILE'"
# Expect /root/.bash_history
ddev exec "bash -ic 'echo \$HISTFILE'"
# Expect /mnt/ddev-history/bash_history
ddev exec -u root 'mkdir /mnt/ddev-history/rootdir && touch /mnt/ddev-history/rootdir/f'
rm -rf .ddev/.history/web/rootdir
# Expect Permission denied
ddev restart
rm -rf .ddev/.history/web/rootdir
# Expect success
ddev delete -Oy && rm -rf .ddev/.history
# Expect success without sudo

See the Shell and Client History docs.

Automated Testing Overview

TestHistoryBindMount checks the history environment in web and db, that a write lands in .ddev/.history/web, and that a root-owned directory is removable by the host user after a restart. TestProcessHooks expects the new MYSQL_HISTFILE path.

Release/Deployment Notes

The web image changes. Existing history in ddev-global-cache isn't migrated, so users start with empty history once. Mutagen ignores /.ddev/.history, which changes the generated mutagen.yml and recreates the sync session on the next start.

🤖 Generated with Claude Code

@rfay
rfay requested review from a team as code owners October 18, 2026 13:35
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file enhancement labels Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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

ddev utility download-ddev --pr 8964

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:e63091d4d6
  • ddev/ddev-webserver:e63091d4d6

@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:6ca16cfd48
  • ddev/ddev-webserver:6ca16cfd48

rfay and others added 4 commits October 21, 2026 16:08
… for #8895

Each service now keeps its shell and database client history in `.ddev/.history/<service>` on the host, bind-mounted at `/mnt/ddev-history`, instead of in the shared `ddev-global-cache` volume. This is an alternative to #8947, which uses a volume per container, following @stasadev's suggestion there.

- For #8895

History lived in `ddev-global-cache`, which every project's containers mount read-write, so it doesn't fit providers like Apple container that need a single writer per volume. A bind mount avoids that limit, but it can leave root-owned files in the project that the user can't remove without sudo, which has to be prevented without any escalation on the host.

DDEV creates `.ddev/.history/<service>` as the host user before `compose up`, with a `.gitignore` of `*` so history never reaches git, and mounts it with `create_host_path: false` so Docker can't create it as root. The mount goes only into services that run as the uid the host user maps to: the host uid on rootful Docker and Podman with `keep-id`, `0` on rootless Docker, and any uid on providers that map ownership. That covers `web`, `db`, and custom services running as `${DDEV_UID}`, which get `HISTFILE`, `MYSQL_HISTFILE`, `PSQL_HISTORY`, `REDISCLI_HISTFILE`, `SQLITE_HISTORY`, `NODE_REPL_HISTORY` and `PYTHON_HISTORY`. `x-ddev.omit-history: true` leaves a service out.

In the web image, a shell running as another uid, like a root shell, keeps its history in the container instead. Anything root writes anyway is given back to the host user on Linux by the existing chown container on `ddev start`, and by a chown container on `ddev delete`, both through Docker so no sudo is needed. Nothing is kept with `no_bind_mounts`.

The db image is unchanged, so a root shell in `db` still writes to the mount until its next image change; the chown on start and delete covers it.

On Linux with rootful Docker:

```bash
ddev utility download-ddev --pr 8964
export PATH="$HOME/tmp/ddev-download-ddev/pr-8964:$PATH"
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php && ddev start
ls -la .ddev/.history          # .gitignore, web, db, all owned by you
ddev exec -u root "bash -ic 'echo \$HISTFILE'"   # /root/.bash_history
ddev exec "bash -ic 'echo \$HISTFILE'"           # /mnt/ddev-history/bash_history
ddev exec -u root 'mkdir /mnt/ddev-history/rootdir && touch /mnt/ddev-history/rootdir/f'
rm -rf .ddev/.history/web/rootdir   # Permission denied
ddev restart
rm -rf .ddev/.history/web/rootdir   # succeeds
ddev delete -Oy && rm -rf .ddev/.history   # succeeds without sudo
```

See the [Shell and Client History](https://ddev--8964.org.readthedocs.build/en/8964/users/usage/architecture/#shell-and-client-history) docs.

`TestHistoryBindMount` checks the history environment in `web` and `db`, that a write lands in `.ddev/.history/web`, and that a root-owned directory is removable by the host user after a restart. `TestProcessHooks` expects the new `MYSQL_HISTFILE` path.

The web image changes. Existing history in `ddev-global-cache` isn't migrated, so users start with empty history once. Mutagen ignores `/.ddev/.history`, which changes the generated `mutagen.yml` and recreates the sync session on the next start.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On rootless Docker, db runs as DDEV_UID, which maps to a subuid on the host, so it gets no history mount. TestHistoryBindMount now expects that there, and the docs say which services keep history with rootless Docker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rfay
rfay force-pushed the 20261017_rfay_history_bind_mounts branch from 662d4c9 to e9dff02 Compare October 22, 2026 15:12
@stasadev

Copy link
Copy Markdown
Member

Thank you for working on this. Although we agreed on an alternative approach with per-container caching, this PR is still a good step forward.

@rfay

rfay commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Comment by Claude Code, at @rfay's request.

Closing in favor of the per-project cache volume approach agreed on in #8895: <project>-web-cache and <project>-db-cache, mounted at /mnt/ddev-project-cache, which hold history and the per-project package caches (composer, npm, yarn, corepack, pip, terminus, n_prefix).

A named volume avoids what made this PR complicated: files owned by root or a subuid on a Linux host, per-provider uid logic, the .gitignore and Mutagen exclusion, and having no history with no_bind_mounts. The list of history variables here (NODE_REPL_HISTORY, PYTHON_HISTORY, REDISCLI_HISTFILE, SQLITE_HISTORY, and the rest) carries over to the new branch.

@rfay rfay closed this Oct 27, 2026
rfay added a commit to rfay/ddev that referenced this pull request Oct 28, 2026
Each project now gets `<project>-web-cache` and `<project>-db-cache` volumes, mounted at `/mnt/ddev-project-cache`. Shell history and the package caches move there from `ddev-global-cache`, and DDEV no longer chowns the shared volume.

- For ddev#8895

Sharing caches across projects caused accidental problems. For example, the terminus cache carried one project's Pantheon login into other projects. Every project start also ran `chown -R` on the whole shared volume, so two users or user namespaces fought over its ownership.

- The web volume holds `history/`, `composer`, `npm`, `yarn`, `corepack`, `pip`, `terminus/cache`, and `n_prefix`. The db volume holds `history/` and a copy of the db global commands.
- db no longer mounts `ddev-global-cache`. Start copies `global-commands/db` into the db volume, and `ddev mysql`, `ddev psql`, and other db global commands run from there.
- Start sets `ddev-global-cache` to mode 1777 and never chowns it. It chowns only the project volumes.
- When a cache volume is first created, start copies the old bash and MySQL history into it. Caches start cold.
- `ddev delete` removes both volumes.
- Web still mounts `ddev-global-cache` at the same path, so add-ons that use it keep working.

This replaces ddev#8947 and ddev#8964, which moved only history.

```bash
ddev utility download-ddev --pr 9024
export PATH="$HOME/tmp/ddev-download-ddev/pr-9024:$PATH"
ddev config --project-type=drupal11 --docroot=web
ddev start
docker volume ls | grep -- -cache
ddev exec 'echo $COMPOSER_CACHE_DIR $npm_config_cache'
ddev mysql -e 'select 1'
ddev exec -s db 'grep ddev-global-cache /proc/mounts || echo none'
ddev delete -Oy
docker volume ls | grep -- -cache
```

Changed docs: https://ddev--9024.org.readthedocs.build/en/9024/users/usage/architecture/#project-cache-volumes

`TestProjectCacheVolumes` checks the volumes, the env paths, history migration and persistence, the db global commands, and the removal by `ddev delete`.

The first Composer or npm install in each project downloads everything again. Old caches stay in `ddev-global-cache` until the user removes that volume.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 28, 2026
Each project now gets `<project>-web-cache` and `<project>-db-cache` volumes, mounted at `/mnt/ddev-project-cache`. Shell history and the package caches move there from `ddev-global-cache`, and DDEV no longer chowns the shared volume.

- For ddev#8895

Sharing caches across projects caused accidental problems. For example, the terminus cache carried one project's Pantheon login into other projects. Every project start also ran `chown -R` on the whole shared volume, so two users or user namespaces fought over its ownership.

- The web volume holds `history/`, `composer`, `npm`, `yarn`, `corepack`, `pip`, `terminus/cache`, and `n_prefix`. The db volume holds `history/` and a copy of the db global commands.
- db no longer mounts `ddev-global-cache`. Start copies `global-commands/db` into the db volume, and `ddev mysql`, `ddev psql`, and other db global commands run from there.
- Start sets `ddev-global-cache` to mode 1777 and never chowns it. It chowns only the project volumes.
- When a cache volume is first created, start copies the old bash and MySQL history into it. Caches start cold.
- `ddev delete` removes both volumes.
- Web still mounts `ddev-global-cache` at the same path, so add-ons that use it keep working.

This replaces ddev#8947 and ddev#8964, which moved only history.

```bash
ddev utility download-ddev --pr 9024
export PATH="$HOME/tmp/ddev-download-ddev/pr-9024:$PATH"
ddev config --project-type=drupal11 --docroot=web
ddev start
docker volume ls | grep -- -cache
ddev exec 'echo $COMPOSER_CACHE_DIR $npm_config_cache'
ddev mysql -e 'select 1'
ddev exec -s db 'grep ddev-global-cache /proc/mounts || echo none'
ddev delete -Oy
docker volume ls | grep -- -cache
```

Changed docs: https://ddev--9024.org.readthedocs.build/en/9024/users/usage/architecture/#project-cache-volumes

`TestProjectCacheVolumes` checks the volumes, the env paths, history migration and persistence, the db global commands, and the removal by `ddev delete`.

The first Composer or npm install in each project downloads everything again. Old caches stay in `ddev-global-cache` until the user removes that volume.

🤖 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

Labels

dependencies Pull requests that update a dependency file enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants