-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 :) |
There was a problem hiding this 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" }} |
There was a problem hiding this comment.
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 \\$
:
{{ $novarnish_hostnames := print "novarnish.$DDEV_HOSTNAME" }} | |
{{ $novarnish_hostnames := print "novarnish.\\$DDEV_HOSTNAME" }} |
@@ -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" }} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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