Repository navigation
feat(docker): auto HTTP/S communication via network aliases instead of external_links - #7642
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
There are two purposes for the external_links:
|
And both of them work with network aliases. |
|
Confirming that this works for me on MacOS (Arm64) using Podman. All testing instructions completed successfully, and I was also able to run a test Drupal 11 project in Podman as well. Output from the testing instructions: Some notes on my setup:
The only significant warning I have when running DDEV in Podman now is the following: That seems expected since Podman has an entirely different versioning scheme from Docker, and is coming from |
This warning definitely needs to be fixed, but in a different PR. |
|
Congrats! Do you think this change has any impact on: |
|
Just almost looked like it was going to work with podman on macOS.
Start podman-desktop (disable k8s) Edit: Today I can get it working using Podman Desktop. I couldn't use ports 80/443, as it doesn't (on first blush) know how to use privileged ports. |
0510b12 to
bb7aae4
Compare
|
Rebased, since we had such big vendor changes. |
rfay
left a comment
There was a problem hiding this comment.
Looks pretty great and pretty surgical to me!
| Let’s say we have two projects, for example: project A, and project B. | ||
|
|
||
| To enable server-side HTTP/S communication (i.e. server-side API calls) between projects you can: | ||
| DDEV v1.24.9+ has built-in support for inter-project HTTP/S communication: |
There was a problem hiding this comment.
No need to make a change now, but this may be getting long-ish for the FAQ, and we may want to find a new home for it and link from FAQ.
There was a problem hiding this comment.
Good idea, I'll do it here.
There was a problem hiding this comment.
I've updated the docs and included more use cases.
|
|
||
| See [Third Party Services May Need To Trust `ddev-webserver`](../extend/custom-compose-files.md#third-party-services-may-need-to-trust-ddev-webserver). | ||
|
|
||
| For DDEV v1.24.8 and earlier, to enable server-side HTTP/S communication (i.e. server-side API calls) between projects you can: |
There was a problem hiding this comment.
IMO we don't have to include this any more. The earlier section says clearly v1.24.9+
| var routerHostnames []string | ||
|
|
||
| for _, app := range GetActiveProjects() { | ||
| err := app.ReadDockerComposeYAML() |
There was a problem hiding this comment.
I don't see a problem with this, since it only happens when we're reconfiguring the router. But it does seem like a lot of reading on some people's systems.
There was a problem hiding this comment.
I thought about this too, but didn't pay much attention.
GetActiveProjects() is called several times in the router, I'll review the logic here.
There was a problem hiding this comment.
I refactored it to use only one call to GetActiveProjects() in StartDdevRouter().
It looks like we read the config of all projects at least 4 times before.
|
TestNetworkAliases did fail on WSL2 DD, https://buildkite.com/ddev/wsl2-docker-desktop/builds/6318#0199739c-c38e-48b5-8d00-5aa627ee6965/1011-1195 Most likely incidental problem but I'm sure you'll look closely. I didn't restart. |
I don't think so, this PR is about hostnames, including everything added to the
I looks like Traefik failed, but I can't say how. I added |
And it didn't fail on the second attempt. I guess we'll know more after this PR lands into |
|
Looks like you can pull when you're happy with tests today! |
…8110 ## The Issue - Fixes ddev#8110 When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication. ## How This PR Solves The Issue This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports: 1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()` 2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic 3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start. ## Manual Testing Instructions Test the exact reproduction scenario from issue ddev#8110: ```bash # Clean slate ddev poweroff mkdir -p /tmp/pruebas && cd /tmp/pruebas # Start first project with adminer mkdir prueba1 && cd prueba1 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Verify works from container ddev exec curl -I https://prueba1.ddev.site:9101 # Should succeed # Start second project with same configuration cd /tmp/pruebas mkdir prueba2 && cd prueba2 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Should see: "Router hostnames have changed, will recreate router" ddev exec curl -I https://prueba2.ddev.site:9101 # Should succeed (this would fail without the fix) # Verify both aliases exist in router docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both prueba1.ddev.site and prueba2.ddev.site # Verify optimization still works ddev restart # Should see: "Router ports and hostnames have not changed, skipping recreation" ``` ## Automated Testing Overview **New Unit Tests:** - `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames) - `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling **Integration Tests:** - Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario) All tests pass. golangci-lint passes with 0 issues. ## Release/Deployment Notes - **Backward compatible:** No breaking changes, existing behavior preserved - **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison - **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons) - **No config changes required:** Fix works automatically on upgrade Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…8110 ## The Issue - Fixes ddev#8110 When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication. ## How This PR Solves The Issue This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports: 1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()` 2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic 3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start. ## Manual Testing Instructions Test the exact reproduction scenario from issue ddev#8110: ```bash # Clean slate ddev poweroff mkdir -p /tmp/pruebas && cd /tmp/pruebas # Start first project with adminer mkdir prueba1 && cd prueba1 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Verify works from container ddev exec curl -I https://prueba1.ddev.site:9101 # Should succeed # Start second project with same configuration cd /tmp/pruebas mkdir prueba2 && cd prueba2 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Should see: "Router hostnames have changed, will recreate router" ddev exec curl -I https://prueba2.ddev.site:9101 # Should succeed (this would fail without the fix) # Verify both aliases exist in router docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both prueba1.ddev.site and prueba2.ddev.site # Verify optimization still works ddev restart # Should see: "Router ports and hostnames have not changed, skipping recreation" ``` ## Automated Testing Overview **New Unit Tests:** - `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames) - `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling **Integration Tests:** - Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario) All tests pass. golangci-lint passes with 0 issues. ## Release/Deployment Notes - **Backward compatible:** No breaking changes, existing behavior preserved - **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison - **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons) - **No config changes required:** Fix works automatically on upgrade Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…8110 ## The Issue - Fixes ddev#8110 When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication. ## How This PR Solves The Issue This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports: 1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()` 2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic 3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start. ## Manual Testing Instructions Test the exact reproduction scenario from issue ddev#8110: ```bash # Clean slate ddev poweroff mkdir -p /tmp/pruebas && cd /tmp/pruebas # Start first project with adminer mkdir prueba1 && cd prueba1 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Verify works from container ddev exec curl -I https://prueba1.ddev.site:9101 # Should succeed # Start second project with same configuration cd /tmp/pruebas mkdir prueba2 && cd prueba2 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Should see: "Router hostnames have changed, will recreate router" ddev exec curl -I https://prueba2.ddev.site:9101 # Should succeed (this would fail without the fix) # Verify both aliases exist in router docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both prueba1.ddev.site and prueba2.ddev.site # Verify optimization still works ddev restart # Should see: "Router ports and hostnames have not changed, skipping recreation" ``` ## Automated Testing Overview **New Unit Tests:** - `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames) - `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling **Integration Tests:** - Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario) All tests pass. golangci-lint passes with 0 issues. ## Release/Deployment Notes - **Backward compatible:** No breaking changes, existing behavior preserved - **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison - **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons) - **No config changes required:** Fix works automatically on upgrade Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
…8110 ## The Issue - Fixes ddev#8110 When starting a second DDEV project with identical port configuration (e.g., both using ddev-adminer on port 9101), the router optimization from PR ddev#7992 prevented recreation because ports matched. However, network aliases in `.router-compose-full.yaml` (required by PR ddev#7642 for inter-container HTTP/S communication) were not updated. This caused the second project's containers to be unable to access their own services via HTTPS, breaking inter-container communication. ## How This PR Solves The Issue This PR extends the router recreation logic to check both ports AND hostnames (network aliases), not just ports: 1. **Added `GetRouterNetworkAliases()`** in `pkg/dockerutil/containers.go` - Extracts network aliases from the running router container's `ddev_default` network configuration, mirroring the pattern of `GetBoundHostPorts()` 2. **Added `HostnamesMatch()`** in `pkg/ddevapp/router.go` - Compares existing vs needed hostnames using subset matching (allows extra hostnames from stopped projects), exactly mirroring `PortsMatch()` logic 3. **Modified `StartDdevRouter()`** in `pkg/ddevapp/router.go` - Now checks both ports and hostnames before deciding to skip recreation. The router is recreated when EITHER ports OR hostnames have changed, while preserving the optimization when neither has changed The fix maintains the performance optimization from PR ddev#7992 (router isn't recreated unnecessarily) while ensuring network aliases are always updated when new projects start. ## Manual Testing Instructions Test the exact reproduction scenario from issue ddev#8110: ```bash # Clean slate ddev poweroff mkdir -p /tmp/pruebas && cd /tmp/pruebas # Start first project with adminer mkdir prueba1 && cd prueba1 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Verify works from container ddev exec curl -I https://prueba1.ddev.site:9101 # Should succeed # Start second project with same configuration cd /tmp/pruebas mkdir prueba2 && cd prueba2 ddev config --auto ddev add-on get ddev/ddev-adminer DDEV_DEBUG=true ddev start # Should see: "Router hostnames have changed, will recreate router" ddev exec curl -I https://prueba2.ddev.site:9101 # Should succeed (this would fail without the fix) # Verify both aliases exist in router docker inspect ddev-router --format '{{json .NetworkSettings.Networks.ddev_default.Aliases}}' | jq # Should show both prueba1.ddev.site and prueba2.ddev.site # Verify optimization still works ddev restart # Should see: "Router ports and hostnames have not changed, skipping recreation" ``` ## Automated Testing Overview **New Unit Tests:** - `TestHostnamesMatch()` in `pkg/ddevapp/router_test.go` - 6 test cases verifying hostname comparison logic mirrors `TestPortsMatch()` behavior (empty slices, identical, different order, missing hostname, extra hostnames) - `TestGetRouterNetworkAliases()` in `pkg/dockerutil/containers_test.go` - Verifies alias extraction from containers, error handling **Integration Tests:** - Existing `TestNetworkAliases()` in `pkg/dockerutil/networks_test.go` will verify the fix works end-to-end (can be enhanced with same-port scenario) All tests pass. golangci-lint passes with 0 issues. ## Release/Deployment Notes - **Backward compatible:** No breaking changes, existing behavior preserved - **Performance:** Minimal impact - one additional Docker API call (`ContainerInspect` for network aliases) when router already exists, same O(n+m) complexity as port comparison - **User impact:** Fixes broken inter-container communication for users with multiple projects using identical port configurations (common with add-ons) - **No config changes required:** Fix works automatically on upgrade Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
The Issue
Communication between two ddev projects - this is one of the most popular questions about DDEV.
How This PR Solves The Issue
Forget about manual configuration with
external_linksand.ddev/docker-compose.communicate.yaml, DDEV will do everything automatically.This PR:
external_linksfrom the project's.ddev/.ddev-docker-compose-base.yamlfileddev_defaultnetwork to~/.ddev/.router-compose.yamlTestNetworkAliasesTestNetworkAmbiguitytodockerutils, because it's a proper place to test Docker networksManual Testing Instructions
Review updated https://ddev--7642.org.readthedocs.build/en/7642/users/usage/faq/#can-different-projects-communicate-with-each-other
Repeat the same using different router ports:
Automated Testing Overview
See the new test:
TestNetworkAliasesRelease/Deployment Notes
StackOverflow answer needs an update.
Bonus: Podman is not compatible with
external_links, removing them will fixddev starton Podman.