From 364beed773e7f70274341a2c5a5e2e58e8fe08fe Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 10 Mar 2023 05:05:21 -0500 Subject: [PATCH] fix: Don't error if `$globals.CurrentContainer` is `nil` Also: * Note when there are no networks. * Fix "networks available" comment. --- nginx.tmpl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index 902f82d..6f84eb7 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -20,10 +20,26 @@ {{- $_ := set $globals "enable_ipv6" (parseBool (coalesce $globals.Env.ENABLE_IPV6 "false")) }} {{- $_ := set $globals "ssl_policy" (or ($globals.Env.SSL_POLICY) "Mozilla-Intermediate") }} {{- $_ := set $globals "networks" (dict) }} -# networks available to nginx-proxy: -{{- range sortObjectsByKeysAsc $globals.CurrentContainer.Networks "Name" }} - {{- $_ := set $globals.networks .Name . }} +# Networks available to the container running docker-gen (which are assumed to +# match the networks available to the container running nginx): +{{- /* + * Note: $globals.CurrentContainer may be nil in some circumstances due to + * . For more context + * see . + */}} +{{- if $globals.CurrentContainer }} + {{- range sortObjectsByKeysAsc $globals.CurrentContainer.Networks "Name" }} + {{- $_ := set $globals.networks .Name . }} # {{ .Name }} + {{- else }} +# (none) + {{- end }} +{{- else }} +# /!\ WARNING: Failed to find the Docker container running docker-gen. All +# upstream (backend) application containers will appear to be +# unreachable. Try removing the -only-exposed and -only-published +# arguments to docker-gen if you pass either of those. See +# . {{- end }} {{- /*