Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for multiple hostnames #54

Merged

Conversation

stasadev
Copy link
Contributor

@stasadev stasadev commented Dec 20, 2024

The Issue

From Discord: https://discord.com/channels/664580571770388500/1319240207521939476

external_links don't work properly when you have additional_hostnames or additional_fqdns.

external_links:
# Resolve links via DDEV router
- "ddev-router:${DDEV_HOSTNAME}"

 external_links: 
   - "ddev-router:${DDEV_HOSTNAME}"

It is expanded with an invalid syntax:

 external_links: 
   - "ddev-router:primary.ddev.site,secondary.ddev.site"

It should look like this:

 external_links: 
   - "ddev-router:primary.ddev.site"
   - "ddev-router:secondary.ddev.site"

How This PR Solves The Issue

Uses go templates to create the correct external_links in .ddev/docker-compose.cypress_extras.yaml

Manual Testing Instructions

This allows for example to have Mailpit to work automatically without any port change.

mkdir cypress-test && cd cypress-test
ddev config --additional-fqdns="hello.test" --additional-hostnames "extra1,extra2,more.extra"
echo '<?php echo "Hello World;"; ?>' > index.php
ddev add-on get https://github.com/stasadev/ddev-cypress/tarball/20241220_stasadev_support_multiple_hostnames

cat .ddev/docker-compose.cypress_extras.yaml
#ddev-generated
services:
  cypress:
    external_links:
      - "ddev-router:${DDEV_PROJECT}.${DDEV_TLD}"
      - "ddev-router:extra1.${DDEV_TLD}"
      - "ddev-router:extra2.${DDEV_TLD}"
      - "ddev-router:hello.test"
      - "ddev-router:more.extra.${DDEV_TLD}"

ddev start

cat .ddev/.ddev-docker-compose-full.yaml
        external_links:
            - ddev-router:cypress-test.ddev.site
            - ddev-router:extra1.ddev.site
            - ddev-router:extra2.ddev.site
            - ddev-router:hello.test
            - ddev-router:more.extra.ddev.site

Related Issue Link(s)

This is really close to this PR:

@tyler36
Copy link
Owner

tyler36 commented Dec 24, 2024

Thank you for the PR.

Tested as follows; passes using this PR but fails when using tyler36/ddev-cypress

Test

  1. Follow instructions listed in PR description
  2. Run ddev cypress-open to generate Cypress config files
  3. Create cypress/e2e/spec.cy.js
describe('support for multiple hostnames', () => {
  it('can use DDEV_PRIMARY_URL', () => {
    cy.visit('/')
    cy.get('body').should('contain', 'Hello World')
  })

  it('can use additional hostname', () => {
    cy.visit('https://extra2.ddev.site')
    cy.get('body').should('contain', 'Hello World')
  })

  it('can use additional fqdns', () => {
    cy.visit('https://hello.test')
    cy.get('body').should('contain', 'Hello World')
  })
})
  1. Run test from Cypress UI or via CLI
$ ddev cypress-run
...
✔  All specs passed!                        00:02        3        3        -        -        - 

@rfay
Copy link
Contributor

rfay commented Dec 24, 2024

Please approve the tests to let them run @tyler36 , thanks.

Copy link
Contributor

@rfay rfay left a comment

Choose a reason for hiding this comment

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

I don't have an easy way to check out cypress, but this looks right to me. It's ugly of course, and we could wish for better.

The README needs to say "If you change additional_hostnames or additional_fqdns, you have to re-run ddev add-on get

@stasadev
Copy link
Contributor Author

@tyler36, it's ready to pull.

@tyler36
Copy link
Owner

tyler36 commented Jan 6, 2025

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants