Skip to content

Commit

Permalink
fix: remove empty lines from docker-compose.varnish_extras.yaml, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stasadev authored Aug 2, 2024
1 parent ecb0113 commit a3ee718
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ This repository allows you to quickly install the Varnish reverse proxy into a [
## Explanation

The Varnish service inserts itself between ddev-router and the web container, so that calls
to the web container are routed through Varnish first. The [docker-compose.varnish.yaml](https://github.com/ddev/ddev-contrib/blob/master/docker-compose-services/varnish/docker-compose.varnish.yml)
installs Varnish and uses the default domain as its own host name. A docker-compose.varnish-extras.yaml file is generated on install which replaces the ```VIRTUAL_HOST``` variable of the web container with a sub-domain of the website URL. For example, mysite.ddev.site, would be accessible via Varnish on mysite.ddev.site and directly on novarnish.mysite.ddev.site.
to the web container are routed through Varnish first. The [docker-compose.varnish.yaml](docker-compose.varnish.yaml)
installs Varnish and uses the default domain as its own host name. A `docker-compose.varnish_extras.yaml` file is generated on install which replaces the `VIRTUAL_HOST` variable of the web container with a sub-domain of the website URL. For example, `mysite.ddev.site`, would be accessible via Varnish on `mysite.ddev.site` and directly on `novarnish.mysite.ddev.site`.

If you use a project_tld other than ddev.site or additional_fqdns DDEV will help add hosts entries for the hostnames automagically; however, you'll need to add entries for the novarnish.* sub-domains yourself, e.g. `ddev hostname novarnish.testaddfqdn.random.tld 127.0.0.1`.
If you use a `project_tld` other than `ddev.site` or `additional_fqdns` DDEV will help add hosts entries for the hostnames automagically; however, you'll need to add entries for the `novarnish.*` sub-domains yourself, e.g. `ddev hostname novarnish.testaddfqdn.random.tld 127.0.0.1`.

Run `ddev get ddev/ddev-varnish` after changes to name, additional_hostnames, additional_fqdns, or project_tld in .ddev/config.yml so that .ddev/docker-compose.varnish-extras.yaml is regenerated.
Run `ddev get ddev/ddev-varnish` after changes to `name`, `additional_hostnames`, `additional_fqdns`, or `project_tld` in `.ddev/config.yaml` so that `.ddev/docker-compose.varnish_extras.yaml` is regenerated.

## Helper commands

Expand All @@ -38,8 +38,8 @@ See [The Varnish Reference Manual](https://varnish-cache.org/docs/6.5/reference/

## Additional Configuration

* You may want to edit the `.ddev/varnish/default.vcl` to meet your needs. Remember to remove '#ddev-generated' from the file if you want your changes to the file preserved.
* You may want to edit the `.ddev/varnish/default.vcl` to meet your needs. Remember to remove `#ddev-generated` from the file if you want your changes to the file preserved.

**Maintained by [@jedebois](https://github.com/jedubois) and [@rfay](https://github.com/rfay)**
**Maintained by [@jedubois](https://github.com/jedubois) and [@rfay](https://github.com/rfay)**

**Based on the original [ddev-contrib recipe](https://github.com/ddev/ddev-contrib/tree/master/docker-compose-services/varnish) pioneered by [rikwillems](https://github.com/rikwillems)**
54 changes: 38 additions & 16 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,56 @@ pre_install_actions:
#ddev-nodisplay
#ddev-description:Checking DDEV version
(ddev debug capabilities | grep ddev-get-yaml-interpolation >/dev/null) || (echo "Please upgrade DDEV to v1.21.4+ for appropriate capabilities" && false)
# Make sure we have a ddev version that can support what we do here
- |
#ddev-nodisplay
#ddev-description:Removing old docker-compose.varnish-extras.yaml
if [ -f ${DDEV_APPROOT}/.ddev/docker-compose.varnish-extras.yaml ]; then
if grep -q '#ddev-generated' ${DDEV_APPROOT}/.ddev/docker-compose.varnish-extras.yaml; then
rm -f ${DDEV_APPROOT}/.ddev/docker-compose.varnish-extras.yaml
else
echo "${DDEV_APPROOT}/.ddev/docker-compose.varnish-extras.yaml needs to be removed but has been modified by the user. Please check it and remove it"
exit 2
fi
fi
post_install_actions:
- |
#ddev-nodisplay
if [ -f .ddev/docker-compose.varnish-extras.yaml ] && ! grep '#ddev-generated' .ddev/config.varnish-extras.yaml; then
echo "Existing docker-compose.varnish-extras.yaml does not have #ddev-generated, so can't be updated"
exit 2
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
cat <<-END >docker-compose.varnish-extras.yaml
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 }}
{{- $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 }}
services:
web:
environment:
- VIRTUAL_HOST={{ $novarnish_hostnames }}
END
removal_actions:
- |
#ddev-nodisplay
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
else
echo "Unwilling to remove '$DDEV_APPROOT/.ddev/docker-compose.varnish_extras.yaml' because it does not have #ddev-generated in it; you can manually delete it if it is safe to delete."
fi
fi

0 comments on commit a3ee718

Please sign in to comment.