This commit is contained in:
Alexander Zigelski 2022-01-10 01:11:03 +09:00 committed by GitHub
commit f4a5b6a31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,31 @@
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }} {{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
{{ define "upstream" }}
{{ $rancherIP := or (index .Container.Labels "io.rancher.container.ip") "" }}
{{ if .Address }}
{{/* 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 }};
{{/* 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 }};
{{ end }}
{{ else if $rancherIP }}
# rancher: {{ index .Container.Labels "io.rancher.container.name" }} {{ printf "%s" $rancherIP }}
{{ $port := coalesce .Container.Env.VIRTUAL_PORT "80" }}
server {{ printf "%s" (index (splitN $rancherIP "/" 2) 0) }}:{{ printf "%s" $port }};
{{ else if .Network }}
# {{ .Container.Name }}
{{ if .Network.IP }}
server {{ .Network.IP }} down;
{{ else }}
server 127.0.0.1 down;
{{ end }}
{{ end }}
{{ end }}
{{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }} {{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }}
{{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }} {{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }}
{{ $debug_all := $.Env.DEBUG }} {{ $debug_all := $.Env.DEBUG }}