Modified to work with older docker versions without network support

This commit is contained in:
Timo Santi 2016-02-24 09:04:28 -05:00
parent 55e66d658a
commit 0cb799d251

View file

@ -7,7 +7,11 @@
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
{{ else }}
# {{ .Container.Name }}
server {{ .Network.IP }}:{{ .Address.Port }};
{{ if .Network }}
server {{ .Network.IP }}:{{ .Address.Port }};
{{ else }}
server {{ .Address.IP }}:{{ .Address.Port }};
{{ end }}
{{ end }}
{{ else }}
# {{ .Container.Name }}
@ -75,16 +79,26 @@ server {
upstream {{ $host }} {
{{ range $container := $containers }}
{{ $addrLen := len $container.Addresses }}
{{ $network := index $container.Networks 0 }}
{{ $networkLen := len $container.Networks }}
{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ $address := index $container.Addresses 0 }}
{{ template "upstream" (dict "Container" $container "Network" $network "Address" $address) }}
{{ if gt $networkLen 0 }}
{{ $network := index $container.Networks 0 }}
{{ template "upstream" (dict "Container" $container "Network" $network "Address" $address) }}
{{ else }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{ end }}
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
{{ else }}
{{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
{{ $address := where $container.Addresses "Port" $port | first }}
{{ template "upstream" (dict "Container" $container "Network" $network "Address" $address) }}
{{ if gt $networkLen 0 }}
{{ $network := index $container.Networks 0 }}
{{ template "upstream" (dict "Container" $container "Network" $network "Address" $address) }}
{{ else }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{ end }}
{{ end }}
{{ end }}
}