Repository navigation
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 8964Or download the artifact for your OS and architecture directly:
See Testing a PR. |
|
Pushed updated container image(s) for this PR:
|
057d29e to
662d4c9
Compare
|
Pushed updated container image(s) for this PR:
|
… 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]>
662d4c9 to
e9dff02
Compare
|
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. |
|
Comment by Claude Code, at @rfay's request. Closing in favor of the per-project cache volume approach agreed on in #8895: 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 |
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]>
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]>
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
webanddb, 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
webanddb. 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 withkeep-id,0on rootless Docker, and any uid on macOS and Windows providers, which map ownership. In practice that meansweb,db, and custom services withuser: "${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, soweb(which already runs as root there) and root-running services get the mount, whiledbdoes not. Each mounted service getsHISTFILE,MYSQL_HISTFILE,PSQL_HISTORY,REDISCLI_HISTFILE,SQLITE_HISTORY,NODE_REPL_HISTORYandPYTHON_HISTORY, unless it already sets them, so tools likeredis-cliorsqlite3in an add-on keep history too.x-ddev.omit-history: trueleaves a service out.Preventing root-owned files. DDEV creates
.ddev/.history/<service>as the host user beforecompose up, with a.gitignoreof*so history never reaches Git. The mount usescreate_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 onddev start, and by a chown container onddev 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 indbstill 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 --volumesand 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:
See the Shell and Client History docs.
Automated Testing Overview
TestHistoryBindMountchecks the history environment inwebanddb, that a write lands in.ddev/.history/web, and that a root-owned directory is removable by the host user after a restart.TestProcessHooksexpects the newMYSQL_HISTFILEpath.Release/Deployment Notes
The web image changes. Existing history in
ddev-global-cacheisn't migrated, so users start with empty history once. Mutagen ignores/.ddev/.history, which changes the generatedmutagen.ymland recreates the sync session on the next start.🤖 Generated with Claude Code