Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ frontend http
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 }}
{{ if not (empty $container.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 }}
{{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 }}
{{ if not (empty $container.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 }}
{{end}}

frontend https
Expand All @@ -52,31 +56,39 @@ frontend https
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 }}
{{ if not (empty $container.Env.AMAZEEIO) }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{ end }}
{{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 }}
{{ if not (empty $container.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 }}
{{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" }}
{{ if not (empty $container.Env.AMAZEEIO) }}
{{/* Allow containers to set their the port for HTTP connections via AMAZEEIO_HTTP_PORT env variable, fallback to Port 80 */}}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
{{$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) }}
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{ end }}
{{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" }}
{{ if not (empty $container.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) }}
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{ end }}
{{end}}