Repository navigation
fix: mount ddev-config read-only in web and db with no_bind_mounts, for #8895 - #9043
Conversation
ddev#8895 ## Short Summary (TL;DR) With `no_bind_mounts`, web and db now mount the `<project>-ddev-config` volume read-only. They only read it, and the volume was the last DDEV-owned volume with two read-write attachments. ## The Issue - For ddev#8895 and ddev#7372 `no_bind_mounts` copies the project's `.ddev` directory into `<project>-ddev-config`, and web and db both mounted it read-write. Apple `container` allows one read-write attachment, or any number of read-only ones. ## How This PR Solves The Issue - Web and db mount `ddev-config` with `:ro`. At runtime they only read it, for example to copy `php/*.ini`, `mysql/*.cnf`, nginx and Apache config, and homeadditions. Database import and snapshot export with `no_bind_mounts` already go through a temporary directory and `docker cp`. - The `ln -sf /var/www/html/.ddev /mnt/ddev_config` exec after start is gone. `/mnt/ddev_config` is a mounted directory, so that `ln` only created an unused `.ddev` symlink inside the volume. With a read-only mount it would print a warning on every start. For discussion: `start()` still runs `CopyIntoVolume` into this volume on every `ddev start`, even when the project is running. On Apple `container` that read-write helper fails while web and db hold the volume. Skipping the copy for a running project would leave containers that compose recreates in that same start with old `.ddev` content, so this PR leaves it as is. ## Manual Testing Instructions ```bash ddev utility download-ddev --pr 9043 export PATH="$HOME/tmp/ddev-download-ddev/pr-9043:$PATH" ddev config global --no-bind-mounts mkdir -p ~/tmp/d1/.ddev/php ~/tmp/d1/.ddev/mysql && cd ~/tmp/d1 ddev config --project-type=php printf "[PHP]\nmemory_limit = 777M\n" > .ddev/php/mem.ini printf "[mysqld]\nmax_connections = 177\n" > .ddev/mysql/conn.cnf ddev start docker inspect -f '{{range .Mounts}}{{.Destination}} RW={{.RW}} {{end}}' ddev-d1-web ddev-d1-db | grep -o '/mnt/ddev_config RW=[a-z]*' # Expect RW=false twice ddev exec php -r 'echo ini_get("memory_limit");' # Expect 777M ddev mysql -N -e 'select @@max_connections' # Expect 177 ddev snapshot && ddev export-db --file=/tmp/d1.sql.gz ddev config global --no-bind-mounts=false ``` A Postgres project also starts, and `/etc/postgresql/postgresql.conf` still links into `/mnt/ddev_config`. ## Automated Testing Overview No new tests. With `DDEV_TEST_NO_BIND_MOUNTS=true`, `TestDdevStart`, `TestDdevImportDB`, `TestDdevExportDB` and `TestDdevRestoreSnapshot` pass. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UrTUMxNNNiQiA9QxsieVTQ
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 9043Or download the artifact for your OS and architecture directly:
See Testing a PR. |
stasadev
left a comment
There was a problem hiding this comment.
Works for me, approving.
Claude Code ran the same steps on this PR and on main with no_bind_mounts, for MariaDB 11.8 and Postgres 17 on Docker. /mnt/ddev_config goes from RW=true to RW=false in both web and db. Custom PHP and MySQL config, the Postgres config link, web and db custom commands, web-entrypoint.d, homeadditions, nginx snippets and xhprof prepend mode all still work. Snapshot, export, import and restore work too. A second ddev start on a running project still picks up .ddev changes, and starting a project created by main removes the old .ddev symlink from the volume.
🤖 Reviewed with assistance from Claude Code
## Short Summary (TL;DR) A new test renders two projects and the router, then fails when a named volume is attached read-write by more than one service, or read-write by one and read-only by another. Docker allows both, but Apple `container` refuses them, so this catches a regression on any provider. ## The Issue - For ddev#8895 and ddev#7372 The work in ddev#8895 moves DDEV toward one writer per volume, but nothing stops a later change from sharing a volume again. Only a run on Apple `container` would show it. ## How This PR Solves The Issue `TestNamedVolumesHaveOneWriter` renders the compose files of two PHP projects and the router, with and without `no_bind_mounts`. It records each service's mounts by the volume's real name, so a volume shared across projects counts once. It needs Docker only to render the router compose file. It starts no containers. `knownSharedVolumes` lists the volumes that are still shared today, each with its reason: - `ddev-global-cache`, until ddev#9045 lands - `<project>-ddev-config` with `no_bind_mounts`, until ddev#9043 lands - `ddev-ssh-agent_socket_dir`, which needs a transport change and its own issue The test also fails when a listed volume is no longer shared. So whichever of ddev#9043, ddev#9045 and this PR merges last has to delete its entry, and the list can't go stale. ## Manual Testing Instructions ```bash make testpkg TESTARGS="-run TestNamedVolumesHaveOneWriter" # Expect PASS sed -i '/"ddev-ssh-agent_socket_dir": /d' pkg/ddevapp/volume_writers_internal_test.go make testpkg TESTARGS="-run TestNamedVolumesHaveOneWriter" # Expect a failure naming ddev-ssh-agent_socket_dir and the two web services ``` ## Automated Testing Overview This PR is the test. With ddev#9043 and ddev#9045 applied, it fails until their two entries come out of `knownSharedVolumes`, then it passes. 🤖 Developed with assistance from [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UrTUMxNNNiQiA9QxsieVTQ
…dev#8895 The agent's own read-write mount of ddev-ssh-agent_socket_dir was invisible to the test, so making web's mount read-only would have passed while the agent still wrote to the volume. ddev-global-cache and <project>-ddev-config are no longer shared since ddev#9045 and ddev#9043, so their entries and the suffix matching go away. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dependencies: none. Interacts with #9046: if #9046 merges first, this PR must delete the
"-ddev-config"entry fromknownSharedVolumes, or that test fails.One of seven PRs for #8895, which can be reviewed separately: #9040, #9041, #9042, #9043, #9044, #9045, #9046.
Short Summary (TL;DR)
With
no_bind_mounts, web and db now mount the<project>-ddev-configvolume read-only. They only read it, and the volume was the last DDEV-owned volume with two read-write attachments.The Issue
no_bind_mountscopies the project's.ddevdirectory into<project>-ddev-config, and web and db both mounted it read-write. Applecontainerallows one read-write attachment, or any number of read-only ones.How This PR Solves The Issue
ddev-configwith:ro. At runtime they only read it, for example to copyphp/*.ini,mysql/*.cnf, nginx and Apache config, and homeadditions. Database import and snapshot export withno_bind_mountsalready go through a temporary directory anddocker cp.ln -sf /var/www/html/.ddev /mnt/ddev_configexec after start is gone./mnt/ddev_configis a mounted directory, so thatlnonly created an unused.ddevsymlink inside the volume. With a read-only mount it would print a warning on every start.For discussion:
start()still runsCopyIntoVolumeinto this volume on everyddev start, even when the project is running. On Applecontainerthat read-write helper fails while web and db hold the volume. Skipping the copy for a running project would leave containers that compose recreates in that same start with old.ddevcontent, so this PR leaves it as is.Manual Testing Instructions
A Postgres project also starts, and
/etc/postgresql/postgresql.confstill links into/mnt/ddev_config.Automated Testing Overview
No new tests. With
DDEV_TEST_NO_BIND_MOUNTS=true,TestDdevStart,TestDdevImportDB,TestDdevExportDBandTestDdevRestoreSnapshotpass.🤖 Developed with assistance from Claude Code
https://claude.ai/code/session_01UrTUMxNNNiQiA9QxsieVTQ
Generated by Claude Code