Repository navigation
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 8947Or download the artifact for your OS and architecture directly:
See Testing a PR. |
|
Pushed updated container image(s) for this PR:
|
|
Instead of a new volume for each container, could the history live on the host, in the project's That removes most of the Go changes. There's nothing to create, seed, chown, or remove on What it needs:
The 🤖 Developed with assistance from Claude Code |
04224ad to
8270040
Compare
|
Your exact suggestion works OK, with the trade-off about no-bind-mounts not having history, which is OK. The problem I worry about is that some docker providers will mount on the host with the user-id of the in-container user, which can accidentally be root in some cases, especially including the situation of an empty directory in the container causing creation on the host. We definitely don't want root or non-user directories or files created on the host. It's fairly likely we could prevent this situation by making sure to pre-create directories and files on the host. I'll try implementing a safe version of your proposal so we can look at it. Edit: |
… 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]>
…, for ddev#8895 The web and db containers now keep their Bash, MySQL and `psql` history in their own volumes, `ddev-<project>-web-history` and `ddev-<project>-db-history`, mounted at `/mnt/ddev-history`, instead of in the shared `ddev-global-cache` volume. On first start, existing history is copied over from `ddev-global-cache`. - For ddev#8895 History is per-container state, but it lived in `ddev-global-cache`, a volume that every project's web and db containers mount read-write. Giving each container its own volume leaves each with a single writer, as providers like Apple container require, and moves one more thing out of the shared volume. DDEV creates the history volumes along with the project's other volumes, and the existing pre-start chown container gives them the container user's ownership. A history volume created by that start is first seeded from `bashhistory/<project>-<service>` and `mysqlhistory/<project>-<service>` in `ddev-global-cache`. `ddev delete` removes both volumes. The db container gets `HISTFILE` from compose, so its Bash history now survives a restart without a db image change. Both containers get `PSQL_HISTORY`, so `psql` history is kept too. The web image's `bash.bashrc` points `HISTFILE` at the new volume. The db entrypoint still creates the old history directories; that goes away with the next db image change. ```bash ddev utility download-ddev --pr 8947 export PATH="$HOME/tmp/ddev-download-ddev/pr-8947:$PATH" docker run --rm -v ddev-global-cache:/m busybox sh -c 'for s in web db; do mkdir -p /m/bashhistory/histtest-$s; echo old-bash-$s > /m/bashhistory/histtest-$s/bash_history; done' mkdir -p ~/tmp/histtest && cd ~/tmp/histtest ddev config --project-type=php && ddev start docker run --rm -v ddev-histtest-web-history:/h busybox sh -c 'ls -ln /h; cat /h/bash_history' docker run --rm -v ddev-histtest-db-history:/h busybox cat /h/bash_history ddev ssh -s db # run any command, then exit ddev restart ddev exec -s db cat /mnt/ddev-history/bash_history ddev delete -Oy docker volume ls | grep histtest ``` `TestProcessHooks` now expects the new `MYSQL_HISTFILE` path in the db container. The web image changes. Clearing `ddev-global-cache` no longer removes history; `ddev delete` does. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]>
8270040 to
ed20156
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]>
|
Comment by Claude Code, at @rfay's request. Closing in favor of a broader approach agreed on in #8895: each project gets its own cache volumes, What carries over from this PR: setting |
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)
The web and db containers now keep their Bash, MySQL and
psqlhistory in their own volumes,ddev-<project>-web-historyandddev-<project>-db-history, mounted at/mnt/ddev-history, instead of in the sharedddev-global-cachevolume. On first start, existing history is copied over fromddev-global-cache.The Issue
History is per-container state, but it lived in
ddev-global-cache, a volume that every project's web and db containers mount read-write. Giving each container its own volume leaves each with a single writer, as providers like Apple container require, and moves one more thing out of the shared volume.How This PR Solves The Issue
DDEV creates the history volumes along with the project's other volumes, and the existing pre-start chown container gives them the container user's ownership. A history volume created by that start is first seeded from
bashhistory/<project>-<service>andmysqlhistory/<project>-<service>inddev-global-cache.ddev deleteremoves both volumes.The db container gets
HISTFILEfrom compose, so its Bash history now survives a restart without a db image change. Both containers getPSQL_HISTORY, sopsqlhistory is kept too. The web image'sbash.bashrcpointsHISTFILEat the new volume.The db entrypoint still creates the old history directories; that goes away with the next db image change.
Manual Testing Instructions
Automated Testing Overview
TestProcessHooksnow expects the newMYSQL_HISTFILEpath in the db container.Release/Deployment Notes
The web image changes. Clearing
ddev-global-cacheno longer removes history;ddev deletedoes.🤖 Developed with assistance from Claude Code
Co-Authored-By: Claude Opus 5.5 [email protected]