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: make extra docker-compose to always have correct primary hostname, fixes #21 #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FlorentTorregrosa
Copy link

The Issue

When changing a project name in .ddev/config.yaml because a git repository is used as a starterkit for other projects, it is easy to forgot that .ddev/docker-compose.varnish-extras.yaml has a VIRTUAL_HOST hardcoded with the starterkit value.

How This PR Solves The Issue

Replacing the previously generated hostname with VIRTUAL_HOST=novarnish.$DDEV_HOSTNAME avoids to have to change that for every project.

Manual Testing Instructions

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

Automated Testing Overview

Related Issue Link(s)

#21

Release/Deployment Notes

Copy link
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

Hi @FlorentTorregrosa,

Although this approach may work when added to yaml: VIRTUAL_HOST=novarnish.$DDEV_HOSTNAME,
it doesn't work for the install script because $DDEV_HOSTNAME is expanded to its value.

I tried to find a way around this for Go Templates Parse, but no luck.

And on the other hand, $DDEV_HOSTNAME can contain not only one domain, if additional_hostnames is not empty, then $DDEV_HOSTNAME should be set to ${DDEV_HOSTNAME%%,*}, but in this case it doesn't work in yaml.

@FlorentTorregrosa
Copy link
Author

Hi @stasadev,

Thanks for the feedback.

Ok, I am new to ddev, so I don't think I will be able to move this PR more forward.

If at least it will help people and move the issue forward, I will stay with that :)

Copy link
Member

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

When you have additional hostnames:

ddev config --additional-hostnames one,two

The contents of docker-compose.varnish-extras.yaml with this PR will be:

services:
  web:
    environment:
    - VIRTUAL_HOST=novarnish.$DDEV_HOSTNAME,novarnish.one.ddev.site,novarnish.two.ddev.site

And VIRTUAL_HOST will be expanded to novarnish.sitename.ddev.site,one.ddev.site,two.ddev.site,novarnish.one.ddev.site,novarnish.two.ddev.site, so it will have one.ddev.site,two.ddev.site without novarnish. prefix.

I don't know what the implications are for these values ​​in VIRTUAL_HOST, just stating what I see.

Hmm, it doesn't pass the tests, so I guess this change can't work well with additional hostnames.

install.yaml Outdated
@@ -29,7 +29,7 @@ post_install_actions:
{{ $project_tld := "ddev.site" }}
{{ if .DdevGlobalConfig.project_tld }}{{ $project_tld = .DdevGlobalConfig.project_tld }}{{ end }}
{{ if .DdevProjectConfig.project_tld }}{{ $project_tld = .DdevProjectConfig.project_tld }} {{ end }}
{{ $novarnish_hostnames := print "novarnish." .DdevProjectConfig.name "." $project_tld }}
{{ $novarnish_hostnames := print "novarnish.$DDEV_HOSTNAME" }}
Copy link
Member

Choose a reason for hiding this comment

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

I found a way to escape $ with \\$:

Suggested change
{{ $novarnish_hostnames := print "novarnish.$DDEV_HOSTNAME" }}
{{ $novarnish_hostnames := print "novarnish.\\$DDEV_HOSTNAME" }}

@stasadev stasadev changed the title Fix #21: Fix extra docker-compose to always have correct hostname. fix: make extra docker-compose to always have correct primary hostname, fixes #21 Jul 4, 2024
@@ -29,7 +29,7 @@ post_install_actions:
{{ $project_tld := "ddev.site" }}
{{ if .DdevGlobalConfig.project_tld }}{{ $project_tld = .DdevGlobalConfig.project_tld }}{{ end }}
{{ if .DdevProjectConfig.project_tld }}{{ $project_tld = .DdevProjectConfig.project_tld }} {{ end }}
{{ $novarnish_hostnames := print "novarnish." .DdevProjectConfig.name "." $project_tld }}
{{ $novarnish_hostnames := print "novarnish.\\$DDEV_HOSTNAME" }}
Copy link
Member

Choose a reason for hiding this comment

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

An option here is to use sprig's env function I think, https://masterminds.github.io/sprig/os.html

Copy link
Member

Choose a reason for hiding this comment

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

We don't want to expand it (PR is about making it dynamic).

The current behavior (not in this PR) already expands all hostnames, but @FlorentTorregrosa wants it to work even when you change the project name.

The first stopper was that go parser expanded $DDEV_HOSTNAME to it's value. I managed to prevent the expansion with \\$DDEV_HOSTNAME, so the resulting yaml looks like VIRTUAL_HOST=novarnish.$DDEV_HOSTNAME.

Now the problem is that the tests fail, because novarnish. is added only to the first hostname in novarnish.$DDEV_HOSTNAME.

But we can't do any bash manipulation on the resulting yaml file.

Sadly, I don't see a way to make it work.

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