Skip to content

fix(router): seed ddev-router-traefik before web starts, for #8895 - #9044

Closed
rfay wants to merge 1 commit into
ddev:mainfrom
rfay:20261101_rfay_seed_router_traefik_early
Closed

rfay wants to merge 1 commit into
ddev:mainfrom
rfay:20261101_rfay_seed_router_traefik_early

Conversation

@rfay

@rfay rfay commented Nov 1, 2026

Copy link
Copy Markdown
Member

Dependencies: none, but this PR and #9042 both add a test at the end of pkg/ddevapp/router_test.go. Whichever merges second needs a small rebase.

One of seven PRs for #8895, which can be reviewed separately: #9040, #9041, #9042, #9043, #9044, #9045, #9046.

Short Summary (TL;DR)

ddev start now creates and seeds the ddev-router-traefik volume before it creates the project's containers, so the seed runs before web holds ddev-global-cache.

The Issue

ensureRouterTraefikVolume creates ddev-router-traefik and copies ddev-global-cache/traefik into it, so an existing acme.json keeps its Let's Encrypt certificates. It ran only when the router started, which is after web. Web holds ddev-global-cache read-write, and Apple container then refuses the seed container's read-only attachment. The seed failed, the new volume was removed, and the same happened at every router start.

How This PR Solves The Issue

start() calls ensureRouterTraefikVolume right after it creates the project's volumes, unless the router is disabled. This is before start-chown and before compose creates web. The call in PushGlobalTraefikConfig stays for the other paths that start the router. When the volume exists, the call is one VolumeExists check.

This fixes the first project to start. When another project already runs, its web still holds ddev-global-cache, but then the router normally runs too and the volume already exists.

Manual Testing Instructions

ddev utility download-ddev --pr 9044
export PATH="$HOME/tmp/ddev-download-ddev/pr-9044:$PATH"
ddev poweroff
docker volume rm ddev-router-traefik
mkdir -p ~/tmp/e1 && cd ~/tmp/e1
ddev config --project-type=php
ddev start
docker volume inspect -f '{{.CreatedAt}}' ddev-router-traefik
docker inspect -f '{{.Created}}' ddev-e1-web
# Expect the volume to be created before the web container

Automated Testing Overview

New TestRouterTraefikVolumeSeededBeforeWeb removes the volume and plants a file in ddev-global-cache/traefik. It then starts a project and checks that the router sees the file and that the volume is older than the web container. Without this change it fails on the ordering check.

🤖 Developed with assistance from Claude Code

https://claude.ai/code/session_01UrTUMxNNNiQiA9QxsieVTQ


Generated by Claude Code

## Short Summary (TL;DR)

`ddev start` now creates and seeds the `ddev-router-traefik` volume before it creates the project's containers, so the seed runs before web holds `ddev-global-cache`.

## The Issue

- For ddev#8895 and ddev#7372

`ensureRouterTraefikVolume` creates `ddev-router-traefik` and copies `ddev-global-cache/traefik` into it, so an existing `acme.json` keeps its Let's Encrypt certificates. It ran only when the router started, which is after web. Web holds `ddev-global-cache` read-write, and Apple `container` then refuses the seed container's read-only attachment. The seed failed, the new volume was removed, and the same happened at every router start.

## How This PR Solves The Issue

`start()` calls `ensureRouterTraefikVolume` right after it creates the project's volumes, unless the router is disabled. This is before `start-chown` and before compose creates web. The call in `PushGlobalTraefikConfig` stays for the other paths that start the router. When the volume exists, the call is one `VolumeExists` check.

This fixes the first project to start. When another project already runs, its web still holds `ddev-global-cache`, but then the router normally runs too and the volume already exists.

## Manual Testing Instructions

```bash
ddev utility download-ddev --pr 9044
export PATH="$HOME/tmp/ddev-download-ddev/pr-9044:$PATH"
ddev poweroff
docker volume rm ddev-router-traefik
mkdir -p ~/tmp/e1 && cd ~/tmp/e1
ddev config --project-type=php
ddev start
docker volume inspect -f '{{.CreatedAt}}' ddev-router-traefik
docker inspect -f '{{.Created}}' ddev-e1-web
# Expect the volume to be created before the web container
```

## Automated Testing Overview

New `TestRouterTraefikVolumeSeededBeforeWeb` removes the volume and plants a file in `ddev-global-cache/traefik`. It then starts a project and checks that the router sees the file and that the volume is older than the web container. Without this change it fails on the ordering check.

🤖 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
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

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

ddev utility download-ddev --pr 9044

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.

Works for me, with a small note.

Claude Code compared this PR with the latest main build on Docker 29: remove ddev-router-traefik, put a marker in ddev-global-cache/traefik, then ddev start a new project. On main the volume is created 6s after web, with this PR 8s before, and the router sees the marker in both. The new test fails on the ordering check when only the ddevapp.go change is reverted. Apple container wasn't tested.

🤖 Reviewed with assistance from Claude Code

Comment thread pkg/ddevapp/ddevapp.go
// Seed the router volume before web holds ddev-global-cache, since some
// providers refuse to attach a volume another container holds read-write.
if !IsRouterDisabled(app) {
if err = ensureRouterTraefikVolume(); err != nil {

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.

Optional: this call runs without the ddev-router setup lock that the call in StartDdevRouter has. If two projects start at once while the volume is missing, one can see the volume half-seeded, push its config and start the router, and then the cp -a overwrites that config with the older files from ddev-global-cache. It's a small window, but the lock is cheap:

if !IsRouterDisabled(app) {
	unlock := dockerutil.AcquireGlobalLock("ddev-router setup")
	err = ensureRouterTraefikVolume()
	unlock()
	if err != nil {
		util.Warning("%v", err)
	}
}

@rfay

rfay commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

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

Moving this to draft: it will change completely after #9045.

This PR exists because web mounts ddev-global-cache read-write (app_compose_template.yaml), so on Apple container the router's seed container can't attach it read-only once web is up. #9045 copies the mkcert CA into web and drops the ddev-global-cache mount from web and db, so that conflict goes away.

There's also no need for this code to touch or copy from ddev-global-cache at all. Once #9045 lands, this PR will be reworked on that basis rather than moving the seed earlier in start(). @stasadev's lock suggestion is moot until then.

@rfay

rfay commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

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

Closing this. #9045 stopped web and db from mounting ddev-global-cache, so nothing in DDEV holds that volume read-write when the router starts. ensureRouterTraefikVolume can attach it read-only at router start on Apple container too, and seeding it earlier in start() no longer fixes anything.

  • No service in app_compose_template.yaml mounts ddev-global-cache any more. Only the top-level volumes: declaration is left, for add-ons.
  • The only other user is the start-chown helper. It exits before the router starts, and it skips the mount when a running container holds the volume.

That leaves one case: on Apple container, an add-on service that mounts ddev-global-cache read-write would hold it during the one-time migration, before ddev-router-traefik exists. If the seed fails then, the old acme.json is lost and Let's Encrypt certificates get issued again. That doesn't justify the extra call in start(). @stasadev's lock suggestion was about that call, so it goes too.

The test's marker check is the only test of seeding ddev-router-traefik from ddev-global-cache/traefik, and it passes without this change. It may come back on its own as a test: PR, without the ordering check.

@rfay rfay closed this Nov 3, 2026
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 3, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 4, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 5, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Nov 6, 2026
…nd prune rebase notes, for ddev#7372 [skip ci]

ddev#9040 is now upstream, so the branch no longer carries the
FindImagesByLabels re-check. Record ddev#9044 as closed unmerged, and drop
the sections reviewing past rebases.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants