Cascade two else blocks into one using coalesce on VIRTUAL_PORT and 80
This also takes care of the case when VIRTUAL_PORT is not actually exposed.
This commit is contained in:
parent
c4923d1f58
commit
784507df1a
1 changed files with 4 additions and 16 deletions
20
nginx.tmpl
20
nginx.tmpl
|
@ -54,29 +54,17 @@ upstream {{ $host }} {
|
||||||
# {{$container.Name}}
|
# {{$container.Name}}
|
||||||
server {{ $address.IP }}:{{ $address.Port }};
|
server {{ $address.IP }}:{{ $address.Port }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
|
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
|
||||||
{{ else if $container.Env.VIRTUAL_PORT }}
|
|
||||||
{{ range $address := .Addresses }}
|
|
||||||
{{ if eq $address.Port $container.Env.VIRTUAL_PORT }}
|
|
||||||
{{ if and $container.Node $address.HostPort }}
|
|
||||||
# {{ $container.Node.Name }}/{{$container.Name}}
|
|
||||||
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
|
||||||
{{ else }}
|
{{ else }}
|
||||||
# {{$container.Name}}
|
{{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
|
||||||
server {{ $address.IP }}:{{ $address.Port }};
|
{{ $address := where $container.Addresses "Port" $port | first }}
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
|
||||||
{{/* Else default to standard web port 80 */}}
|
|
||||||
{{ else }}
|
|
||||||
{{ $address := where $container.Addresses "Port" "80" | first }}
|
|
||||||
{{ if $address }}
|
{{ if $address }}
|
||||||
{{ if and $container.Node $address.HostPort }}
|
{{ if and $container.Node $address.HostPort }}
|
||||||
# {{ $container.Node.Name }}/{{$container.Name}}
|
# {{ $container.Node.Name }}/{{$container.Name}}
|
||||||
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
server {{ $container.Node.Address.IP }}:{{ $address.HostPort }};
|
||||||
{{ else }}
|
{{ else }}
|
||||||
# {{$container.Name}}
|
# {{$container.Name}}
|
||||||
server {{ $address.IP }}:80;
|
server {{ $address.IP }}:{{ $address.Port }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
# {{$container.Name}}
|
# {{$container.Name}}
|
||||||
|
|
Reference in a new issue