Skip to content

fix: replace broken http and https port lookup, fixes #7246 - #7259

Merged
rfay merged 1 commit into
ddev:mainfrom
AkibaAT:20250504_akibaat_fix_port_detection
May 13, 2025
Merged

rfay merged 1 commit into
ddev:mainfrom
AkibaAT:20250504_akibaat_fix_port_detection

Conversation

@AkibaAT

@AkibaAT AkibaAT commented May 4, 2025 •

Copy link
Copy Markdown
Contributor

The Issue

How This PR Solves The Issue

Fix up GetWebContainerDirectHTTPPort and GetWebContainerHTTPSPublicPort to preferably use app.GetPublishedPortForPrivatePort("web", 80) and app.GetPublishedPortForPrivatePort("web", 443), and fall back only for generic type projects.

Manual Testing Instructions

Have ngrok set up and authenticated as per https://ngrok.com/docs/getting-started/

mkdir share_test
cd share_test
ddev config --project-type=php --omit-containers=db

Add web_extra_exposed_ports to .ddev/config.yaml:

web_extra_exposed_ports:
  - name: vite
    container_port: 5173
    http_port: 5172
    https_port: 5173
ddev start
ddev share

Verify that ddev share maps to the expected port, instead of the web_extra_exposed_ports it did before.

Additionally, test the same with https://ddev.readthedocs.io/en/stable/users/quickstart/#generic-frankenphp to verify that generic projects also behave correctly.

Automated Testing Overview

Added new tests:

  • TestGetWebContainerDirectURLs tests the GetWebContainerDirectHTTPURL and GetWebContainerDirectHTTPSURL functions
  • TestGetWebContainerDirectURLsErrorHandling tests error handling in GetWebContainerDirectHTTPURL and GetWebContainerDirectHTTPSURL
  • TestGetWebContainerDirectURLsWithDockerIPError tests behavior when GetDockerIP returns an error

Release/Deployment Notes

n/a

@github-actions github-actions Bot added the bugfix label May 4, 2025
@AkibaAT
AkibaAT force-pushed the 20250504_akibaat_fix_port_detection branch from 45410b1 to f8d1480 Compare May 4, 2025 08:50
@github-actions

github-actions Bot commented May 4, 2025 •

Copy link
Copy Markdown

@AkibaAT
AkibaAT force-pushed the 20250504_akibaat_fix_port_detection branch from f8d1480 to 26838a7 Compare May 4, 2025 10:08
@AkibaAT

AkibaAT commented May 4, 2025

Copy link
Copy Markdown
Contributor Author

TestDdevFullSiteSetup for site TestPkgSveltekit is failing.

Project setup:

webserver_type: generic
web_extra_exposed_ports:
    - name: svelte
      container_port: 3000
      http_port: 80
      https_port: 443

Ports at time of check:
image

@AkibaAT

AkibaAT commented May 4, 2025 •

Copy link
Copy Markdown
Contributor Author

So app.GetPublishedPortForPrivatePort("web", 80) is too simple after all, because for generic project type, the private port doesn't have to be 80. But the intended routing port is 80, and same for 443.

@AkibaAT
AkibaAT force-pushed the 20250504_akibaat_fix_port_detection branch from 26838a7 to 1cc5ec7 Compare May 4, 2025 17:00
@rfay

rfay commented May 5, 2025

Copy link
Copy Markdown
Member

Thanks for studying it so carefully!

@AkibaAT

AkibaAT commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for studying it so carefully!

Before I clean up and declare this ready for review, there's one remaining question about the priority and fallback logic, and if it's sufficient this way:

  • Prefer app.GetPublishedPortForPrivatePort("web", 80)
  • If generic type, look for a web_extra_exposed_ports with http_port: 80
  • Throw error

Should it fall back further and return the first http port like the current code does?
Is there a different mapping way we have to take into account here? (e.g. docker compose config)

@rfay
rfay requested a review from stasadev May 5, 2025 13:51
@rfay

rfay commented May 5, 2025 •

Copy link
Copy Markdown
Member

This looks like a great strategy to me, and wow, thanks for the tests too!

Could you rework the manual testing instructions (or add to) using ddev describe instead of or in addition to the less direct ddev share technique? ddev describe should show the detected port clearly I hope.

Edit: Missed the questions:

Should it fall back further and return the first http port like the current code does?

It seems to me like your code here has done all that should be done, but great question and worthy of conversation.

Is there a different mapping way we have to take into account here? (e.g. docker compose config)

In this case, we're letting Docker choose an ephemeral port unless host_webserver_port or host_https_port is set, but IMO on both of those cases you're still catching exactly what should be caught.

However, related issue about the db port,

Longer term it would probably be nice to not use ephemeral port by default but have static port for http/https. However, this kind of optmization always leads to new bugs and frictions.

@rfay

rfay commented May 7, 2025

Copy link
Copy Markdown
Member

This should be on a good path, thanks for undertaking it. Move to "ready for review" when you're satisfied.

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

Nice work on this issue (how did I never catch it in the wild? 🙂)

Comment thread pkg/ddevapp/ddevapp.go Resolved

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

Thanks for the great manual testing instructions and the new tests!

The code looks good to me, and I don't think it involves any risks.

Manual testing works out fine with both scenarios, thanks!

@rfay

rfay commented May 12, 2025

Copy link
Copy Markdown
Member

If you like this now @AkibaAT please move to ready for review

@rfay
rfay requested a review from stasadev May 12, 2025 16:50
@AkibaAT
AkibaAT marked this pull request as ready for review May 12, 2025 19:37
@AkibaAT
AkibaAT requested a review from a team as a code owner May 12, 2025 19:37
@AkibaAT
AkibaAT force-pushed the 20250504_akibaat_fix_port_detection branch from 1cc5ec7 to 79b179e Compare May 12, 2025 19:45

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

Thank you! Looks good to me.

@rfay

rfay commented May 13, 2025

Copy link
Copy Markdown
Member

Thanks so much for the careful and thoughtful work on this @AkibaAT !

@rfay
rfay merged commit f034459 into ddev:main May 13, 2025
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 7, 2026
…t HTTPS URL

TestDdevStartMultipleHostnames failed in the all-project-types job on four sites, each for a different reason:

- sveltekit and nodejs: for `webserver_type: generic`, GetWebContainerDirectHTTPSPort fell back to the published `web_extra_exposed_ports` container port. The router reaches that port over plain HTTP, so `ddev describe` and GetAllURLs listed an `https://127.0.0.1:<port>` URL that answers with HTTP. The fallback was added in ddev#7259 alongside the HTTP one, which was the fallback that PR needed; the FrankenPHP add-on publishes 443 itself and never reached it. TestGetWebContainerDirectURLsWithGenericWebserver only checked the format of that URL, so it now requests every URL GetAllURLs reports; against the old code the direct HTTPS URL fails with EOF.
- typo3: its static test file comes from the files tarball, which the test never imported, so it only passed when an earlier test had imported files for the first site.
- silverstripe: it had no static test URL, so the test requested `/`, which redirects to `/dev/build` until a database is imported. It now uses a theme stylesheet that ships with the source.

SkipIfGotestShort now runs the test anyway when DDEV_RUN_TEST_ANYWAY=true, and `.claude/settings.json` presets that and the opt-in test switches CI sets, so Claude Code can run any test locally against a single site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stasadev added a commit to stasadev/ddev that referenced this pull request Oct 8, 2026
…t HTTPS URL

TestDdevStartMultipleHostnames failed in the all-project-types job on four sites, each for a different reason:

- sveltekit and nodejs: for `webserver_type: generic`, GetWebContainerDirectHTTPSPort fell back to the published `web_extra_exposed_ports` container port. The router reaches that port over plain HTTP, so `ddev describe` and GetAllURLs listed an `https://127.0.0.1:<port>` URL that answers with HTTP. The fallback was added in ddev#7259 alongside the HTTP one, which was the fallback that PR needed; the FrankenPHP add-on publishes 443 itself and never reached it. TestGetWebContainerDirectURLsWithGenericWebserver only checked the format of that URL, so it now requests every URL GetAllURLs reports; against the old code the direct HTTPS URL fails with EOF.
- typo3: its static test file comes from the files tarball, which the test never imported, so it only passed when an earlier test had imported files for the first site.
- silverstripe: it had no static test URL, so the test requested `/`, which redirects to `/dev/build` until a database is imported. It now uses a theme stylesheet that ships with the source.

SkipIfGotestShort now runs the test anyway when DDEV_RUN_TEST_ANYWAY=true, and `.claude/settings.json` presets that and the opt-in test switches CI sets, so Claude Code can run any test locally against a single site.

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