From b63baf9fcab017da7dd8e1cb56010431e8094d0a Mon Sep 17 00:00:00 2001 From: Stanislav Zhuk Date: Fri, 20 Dec 2024 16:33:20 +0200 Subject: [PATCH 1/2] Make extra docker-compose work with env variables --- install.yaml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/install.yaml b/install.yaml index 495dafa..38f7c53 100644 --- a/install.yaml +++ b/install.yaml @@ -38,21 +38,11 @@ post_install_actions: #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 }} 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: From 02ec998a9985d7b86550f4d3dfd4f5c48d167a25 Mon Sep 17 00:00:00 2001 From: Stanislav Zhuk Date: Fri, 27 Dec 2024 00:03:17 +0200 Subject: [PATCH 2/2] Update descriptions, add a note --- README.md | 3 +++ install.yaml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 84c16d7..8081eff 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/install.yaml b/install.yaml index 38f7c53..f21c951 100644 --- a/install.yaml +++ b/install.yaml @@ -28,16 +28,18 @@ 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. + # container, by switching all hostnames with "novarnish" subdomain prefix. services: web: environment: @@ -48,6 +50,7 @@ post_install_actions: 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