This commit is contained in:
Niklas Keller 2021-04-20 20:59:15 -05:00 committed by GitHub
commit 4f5c462a91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,11 +8,11 @@
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
{{ if and .Container.Node.ID .Address.HostPort }}
# {{ .Container.Node.Name }}/{{ .Container.Name }}
server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }};
server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }} weight={{ .Weight }};
{{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
{{ else if .Network }}
# {{ .Container.Name }}
server {{ .Network.IP }}:{{ .Address.Port }};
server {{ .Network.IP }}:{{ .Address.Port }} weight={{ .Weight }};
{{ end }}
{{ else if .Network }}
# {{ .Container.Name }}
@ -178,6 +178,7 @@ server {
upstream {{ $upstream_name }} {
{{ range $container := $containers }}
{{ $weight := or ($container.Env.VIRTUAL_WEIGHT) "1" }}
{{ $addrLen := len $container.Addresses }}
{{ range $knownNetwork := $CurrentContainer.Networks }}
@ -188,12 +189,12 @@ upstream {{ $upstream_name }} {
{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ $address := index $container.Addresses 0 }}
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork "Weight" $weight) }}
{{/* 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 "Address" $address "Network" $containerNetwork) }}
{{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork "Weight" $weight) }}
{{ end }}
{{ else }}
# Cannot connect to network of this container