This repository has been archived by the owner on Dec 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCaddyfile.tmpl
61 lines (56 loc) · 1.87 KB
/
Caddyfile.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
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
{{ define "proxy_vhost" }}
{{ if .Address }}
{{ if and .Container.Node.ID .Address.HostPort }}
## Using container IP:PORT
proxy / {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }} {
transparent
}
{{ else if .Network }}
## Using Network IP:PORT
proxy / {{ .Network.IP }}:{{ .Address.Port }} {
transparent
}
{{ end }}
{{ else if .Network }}
## Using fallback to Network IP:80
## "{{ .Container.Name }}"
proxy / {{ .Network.IP }} {
transparent
}
{{ end }}
{{ end }}
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{ $host }} {
{{ range $container := $containers }}
## $container.Name: "{{ $container.Name }}"
{{ $addrLen := len $container.Addresses }}
{{ range $knownNetwork := $CurrentContainer.Networks }}
{{ range $containerNetwork := $container.Networks }}
{{ if eq $knownNetwork.Name $containerNetwork.Name }}
{{ $basicauth := $container.Env.VIRTUAL_HOST_BASIC_AUTH }}
{{ if $basicauth }}
basicauth {{ $basicauth }}
{{ end }}
{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ $address := index $container.Addresses 0 }}
{{ template "proxy_vhost" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
{{/* 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 "proxy_vhost" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
{{ end }}
{{ $extraconfig := $container.Env.VIRTUAL_HOST_EXTRA_CONFIG }}
{{ if $extraconfig }}
{{ $extraconfig }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
log stdout
errors stdout
}
{{ end }}