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 always have correct primary hostname, fixes #21 #25

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Then restart your project
ddev restart
```

> [!NOTE]
> If you change `additional_hostnames` or `additional_fqdns`, you have to re-run `ddev add-on get ddev/ddev-varnish`

## Explanation

The Varnish service inserts itself between ddev-router and the web container, so that calls
Expand Down
19 changes: 6 additions & 13 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,29 @@ pre_install_actions:
post_install_actions:
- |
#ddev-nodisplay
#ddev-description:Checking docker-compose.varnish_extras.yaml for changes
if [ -f docker-compose.varnish_extras.yaml ] && ! grep -q '#ddev-generated' docker-compose.varnish_extras.yaml; then
echo "Existing docker-compose.varnish_extras.yaml does not have #ddev-generated, so can't be updated"
exit 2
fi
- |
#ddev-nodisplay
#ddev-description:Replacing all hostnames in the web container by adding "novarnish" subdomain prefix
cat <<-END >docker-compose.varnish_extras.yaml
#ddev-generated
# This is the second half of the trick that puts varnish "in front of" the web
# container, just by switching the names.
{{- $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 -}}
{{- $sep := print "." $project_tld ",novarnish." -}}
{{- if .DdevProjectConfig.additional_hostnames }}
{{- $novarnish_hostnames = print $novarnish_hostnames "," "novarnish." (.DdevProjectConfig.additional_hostnames | join $sep) "." $project_tld -}}
{{- end }}
{{- if .DdevProjectConfig.additional_fqdns }}
{{- $novarnish_hostnames = print $novarnish_hostnames "," "novarnish." ( .DdevProjectConfig.additional_fqdns | join ",novarnish." ) -}}
{{- end }}
# container, by switching all hostnames with "novarnish" subdomain prefix.
services:
web:
environment:
- VIRTUAL_HOST={{ $novarnish_hostnames }}
{{- $novarnish_hostnames := splitList "," (env "DDEV_HOSTNAME") }}
- VIRTUAL_HOST={{ range $i, $n := $novarnish_hostnames }}novarnish.{{ replace (env "DDEV_TLD") "\\${DDEV_TLD}" (replace (env "DDEV_PROJECT") "\\${DDEV_PROJECT}" $n) }}{{ if lt (add1 $i) (len $novarnish_hostnames) }},{{ end }}{{ end }}
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment here to explain what this is doing and why. It looks great and should completely solve this problem.

The README needs to explain that if additional_hostnames or additional_fqdns changes, the ddev add-on get needs to be re-run.

It will need a new release as well.

Copy link
Member

Choose a reason for hiding this comment

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

The comment was already here above the services:

I'm not very clear on how it works, but I've added more explanations there.

END

removal_actions:
- |
#ddev-nodisplay
#ddev-description:Remove docker-compose.varnish_extras.yaml file
if [ -f docker-compose.varnish_extras.yaml ]; then
if grep -q '#ddev-generated' docker-compose.varnish_extras.yaml; then
rm -f docker-compose.varnish_extras.yaml
Expand Down
Loading