Skip to content

fix: exclude paused/stopped projects from router's Traefik configuration - #7961

Merged
rfay merged 50 commits into
mainfrom
20251219_rfay_skip_paused_projects
Jan 19, 2026
Merged

rfay merged 50 commits into
mainfrom
20251219_rfay_skip_paused_projects

Conversation

@rfay

@rfay rfay commented Dec 19, 2025 •

Copy link
Copy Markdown
Member

The Issue

When Docker restarts or the system reboots, DDEV projects end up in a "paused" state (containers exist but are stopped). When starting a new project, the router was incorrectly including Traefik routing configuration from these paused projects. This could cause routing conflicts or confusion as the router would have config for projects that weren't actually running.

How This PR Solves The Issue

Two changes were made:

  1. GetActiveProjects() in utils.go now filters out containers that are not in "running" state, ensuring only truly running projects are returned.

  2. PushGlobalTraefikConfig() in traefik.go now:

    • Copies active project configs and certs into the global ~/.ddev/traefik/ directory before pushing to the Docker volume
    • Uses destroyExisting=true when copying to the volume, which clears any stale config files from paused/stopped projects

This ensures the router only has routing configuration for projects that are actually running.

TODO

  • Must be tested with LetsEncrypt, probably after pull

Manual Testing Instructions

  1. Start two DDEV projects (e.g., ddev start in two different directories)
  2. Verify both project configs exist: docker exec ddev-router tree
  3. Restart Docker (e.g., sudo systemctl restart docker or restart Docker Desktop)
  4. Verify projects show as "paused": ddev list
  5. Start only one of the projects: ddev start in one directory
  6. Check router config: docker exec ddev-router tree
  7. Verify only the started project's config is present (along with default_config.yaml)

Automated Testing Overview

No new tests added. The existing test infrastructure doesn't easily support testing Docker restart scenarios. The fix was verified through manual testing.

Release/Deployment Notes

It's unlikely that these features are in use, but the behavior of traefik config is a little tighter as of this PR (actually the changes were in earlier PRs and just caught here:

  • Breaking change: User-generated configuration in ~/.ddev/traefik/config is now ignored (it's cleaned out and rebuilt), and users who want additional global config (unusual) put that in ~/.ddev/traefik/custom-global-config
  • Breaking change: in the project .ddev/traefik/config, only files named <projectname>.yaml are supported.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Dec 19, 2025 •

Copy link
Copy Markdown

@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Dec 19, 2025
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch from 24761b0 to 58939bc Compare December 21, 2025 17:29
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch from 58939bc to ee36733 Compare December 21, 2025 20:43

@rfay rfay left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be OK. It's actually a hard problem that we have only flirted with occasionally, but I think this current implementation tries hard to be rigorous.

It probably has some kind of impact on the quickstart tests though, https://github.com/ddev/ddev/actions/runs/20415550431/job/58669374644

@rfay
rfay marked this pull request as ready for review December 22, 2025 03:19
@rfay
rfay requested a review from a team as a code owner December 22, 2025 03:19
@rfay
rfay requested a review from stasadev December 22, 2025 03:19
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch from ee36733 to d75aa55 Compare December 22, 2025 14:46
@stasadev

Copy link
Copy Markdown
Member

It probably has some kind of impact on the quickstart tests though, ddev/ddev/actions/runs/20415550431/job/58669374644

I don't understand why this change breaks quickstarts, maybe when files are deleted and replaced, Docker runs a healthcheck for Traefik in that exact second, causing DDEV to break.

@rfay

rfay commented Dec 22, 2025

Copy link
Copy Markdown
Member Author

@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch 3 times, most recently from abdf337 to f947238 Compare December 27, 2025 02:48
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch from 869756f to ff3f022 Compare December 28, 2025 00:31
@rfay
rfay marked this pull request as draft December 28, 2025 00:33
@rfay

rfay commented Dec 28, 2025

Copy link
Copy Markdown
Member Author

@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch 4 times, most recently from e84a9fb to 98d42fb Compare January 7, 2026 17:44
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch 2 times, most recently from a8e2326 to d137faa Compare January 8, 2026 17:17

ENV TRAEFIK_MONITOR_PORT=10999
RUN apk add --no-cache bash curl htop jq vim yq
RUN apk add --no-cache bash curl file htop jq openssl vim yq

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional, and I didn't end up using it, but wanted to use file and openssl to chase problems that turned out to be "not ready" problems.

# Only retry if: no routers loaded yet AND we expect some AND no errors yet
if [ "$file_router_count" -eq 0 ] && [ "$expected_router_count" -gt 0 ] && [ "$error_count" -eq 0 ]; then
# How long to wait (seconds) for Traefik to reflect new file-provider config.
# This covers both initial startup and later config pushes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section turned out to be critical to solve problems with the quickstart tests, which (on github) continually push new projects while an existing project is running. Without this, we could end up with the project up and healthy, and the config file pushed into the volume, but traefik not yet having the routers running.

I think it's an important criticism that this healthcheck, even when broken out into functions, is to complex for a bash script to handle properly. Right now I think the build implications of doing it in go would be a bit of trouble, but it may be something we should do anyway. We'd just have to compile the go at image build time, it might not be that bad.

* `certs/default_cert.*` files are the default DDEV-generated certificates, normally created by `mkcert`.
* `config/default_config.yaml` contains global *dynamic* configuration, including pointers to the default certificates. It is possible to add other Traefik configuration in the `config` directory, which will apply to all projects. For example, a `config/router_middlewares.yaml` file might provide middleware implementations that would apply to all projects.
* `config/default_config.yaml` contains global *dynamic* configuration, including pointers to the default certificates.
* `custom-global-config/` is a directory where you can add custom Traefik dynamic configuration files (such as middleware, routers, or services) that will be automatically included for all projects. Files in this directory are copied to the router's config volume on each `ddev start`. For example, a `custom-global-config/global_middlewares.yaml` file might provide middleware implementations that apply to all projects:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a BC break. I doubt anybody uses it. But it allows us to have a specific place for custom global configuration of middlewares or whatever.

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.

Shouldn't we have some example for this in the global ~/.ddev directory, pre-creating ~/.ddev/traefik/custom-global-config with some files like README.md and/or some-file.yaml.example inside?

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.

Or ~/.ddev/traefik/README.md should be updated with this info.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added README and example, thanks.


// GetContainerHealth retrieves the health status of a given container.
// returns status, most-recent-log
// The container is only considered "healthy" if it's also "running", contrary to Docker's normal usage

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this didn't seem to be the primary issue (it was a suspect) we definitely don't want to declare a container "healthy" if its state is not "running".

@rfay
rfay requested a review from Copilot January 8, 2026 18:31
@rfay
rfay marked this pull request as ready for review January 8, 2026 18:31
rfay and others added 23 commits January 19, 2026 10:31
And use that to copy files from custom-global-files to traefik config
Because we only want yaml files copied, not readme, etc.
@rfay
rfay force-pushed the 20251219_rfay_skip_paused_projects branch from 912be14 to 0a41266 Compare January 19, 2026 18:51
@rfay

rfay commented Jan 19, 2026

Copy link
Copy Markdown
Member Author

I pushed an adjustment to report extra traefik files or custom project traefik configuration more accurately, 0a41266 (#7961)

@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.

Looks good to me.

@rfay
rfay merged commit a9e1f52 into main Jan 19, 2026
35 of 37 checks passed
@rfay
rfay deleted the 20251219_rfay_skip_paused_projects branch January 19, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants