Skip to content

Commit

Permalink
fix: make extra docker-compose always have correct primary hostname, f…
Browse files Browse the repository at this point in the history
…ixes #21 (#25)

Co-authored-by: Stanislav Zhuk <[email protected]>
  • Loading branch information
FlorentTorregrosa and stasadev authored Dec 26, 2024
1 parent 9b7ee3a commit 053aa16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
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 }}
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

0 comments on commit 053aa16

Please sign in to comment.