Use new Network interface to support new overlay network

This commit is contained in:
Baptiste Donaux 2016-01-17 12:29:55 +01:00
parent deb4050fa4
commit a66115f560

View file

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