-
Notifications
You must be signed in to change notification settings - Fork 2
/
haproxy.tmpl
82 lines (74 loc) · 3.76 KB
/
haproxy.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{{ define "upstream" }}
{{ if .Address }}
{{/* If port is not published on host, use container's IP:PORT */}}
{{ if .Address.IP }}
# {{ .Container.Name }}
server {{ .Address.IP }}:{{ .Address.Port }} {{ .Address.IP }}:{{ .Address.Port }} check
{{ else }}
# {{ .Container.Name }}
server {{ .Container.Name }}:{{ .Address.Port }} {{ .Container.Name }}:{{ .Address.Port }} check
{{ end }}
{{ end }}
{{ end }}
global
daemon
maxconn 1024
pidfile /var/run/haproxy.pid
defaults
balance roundrobin
timeout client 600s
timeout connect 600s
timeout server 600s
option http-server-close
frontend http
mode http
bind :80
option forwardfor
stats enable
stats refresh 30s
stats show-node
stats uri /stats
{{/* We are only interested in containers that have the environment variable AMAZEEIO set */}}
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{/* Allow containers to set their hostname via the env variable AMAZEEIO_URL if not set, fall bback to the container name */}}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{/* We are only interested in containers that have the environment variable LAGOON_LOCALDEV_HTTP_PORT set */}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{/* Allow containers to set their hostname via the env variable LAGOON_ROUTE if not set, fall back to the container name and projectname. Also remove http:// and https:// */}}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
frontend https
mode http
bind *:443 ssl crt /app/server.pem
http-request add-header X-Forwarded-Proto https
option socket-stats
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{/* Allow containers to set their hostname via the env variable LAGOON_ROUTE if not set, fall back to the container name and projectname. Also remove http:// and https:// */}}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
{{/* Allow containers to set their the port for HTTP connections via AMAZEEIO_HTTP_PORT env variable, fallback to Port 80 */}}
{{$http_port := coalesce $container.Env.AMAZEEIO_HTTP_PORT "80" }}
backend http_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
{{/* Allow containers to set their the port for HTTP connections via LAGOON_LOCALDEV_HTTP_PORT env variable, fallback to Port 8080 */}}
{{$http_port := coalesce $container.Env.LAGOON_LOCALDEV_HTTP_PORT "8080" }}
backend http_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{end}}