init enhanced templating for the nginx config
This commit is contained in:
parent
77aa76d7f2
commit
bf2e81ca34
@ -11,5 +11,6 @@ RUN echo "Building for '${OS}/${ARCH}'..." \
|
||||
COPY templates /etc/confd/templates/
|
||||
COPY conf.d /etc/confd/conf.d/
|
||||
COPY nginx-proxy /usr/bin/
|
||||
COPY test/portmap.yaml /etc/confd/values.yaml
|
||||
|
||||
ENTRYPOINT nginx-proxy
|
||||
@ -2,7 +2,5 @@
|
||||
src = "nginx.tmpl"
|
||||
dest = "/etc/nginx/nginx.conf"
|
||||
keys = [
|
||||
"SERVERS",
|
||||
"PORTS",
|
||||
"UDP_PORTS",
|
||||
]
|
||||
"ports"
|
||||
]
|
||||
@ -1,7 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Run confd
|
||||
confd -onetime -backend env
|
||||
set -e
|
||||
confd -onetime -backend file -file /etc/confd/values.yaml -log-level debug
|
||||
set +e
|
||||
|
||||
# Output Configuration
|
||||
echo "===== Initial nginx configuration ====="
|
||||
|
||||
@ -1,3 +1,10 @@
|
||||
###################################
|
||||
# Generated by confd {{datetime}} #
|
||||
# ####### #
|
||||
# # k3d # #
|
||||
# ####### #
|
||||
###################################
|
||||
|
||||
{{- $servers := split (getenv "SERVERS") "," -}}
|
||||
{{- $ports := split (getenv "PORTS") "," -}}
|
||||
{{- $udp_ports := split (getenv "UDP_PORTS") "," -}}
|
||||
@ -12,42 +19,28 @@ events {
|
||||
|
||||
stream {
|
||||
|
||||
#######
|
||||
# TCP #
|
||||
#######
|
||||
{{- range $port := $ports }}
|
||||
upstream server_nodes_{{ $port }} {
|
||||
{{- range $server := $servers }}
|
||||
{{- range $portstring := lsdir "/ports" }}
|
||||
|
||||
|
||||
{{- $portdir := printf "/ports/%s/*" $portstring -}}
|
||||
{{- $port := index (split $portstring ".") 0 -}}
|
||||
{{- $protocol := index (split $portstring ".") 1 -}}
|
||||
{{- $upstream := replace $portstring "." "_" -1 }}
|
||||
|
||||
upstream {{ $upstream }} {
|
||||
{{- range $server := getvs $portdir }}
|
||||
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s;
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
server {
|
||||
listen {{ $port }};
|
||||
proxy_pass server_nodes_{{ $port }};
|
||||
listen {{ $port }} {{- if (eq $protocol "udp") }} udp{{- end -}};
|
||||
proxy_pass {{ $upstream }};
|
||||
proxy_timeout 600;
|
||||
proxy_connect_timeout 2s;
|
||||
}
|
||||
|
||||
|
||||
{{- end }}
|
||||
|
||||
#######
|
||||
# UDP #
|
||||
#######
|
||||
|
||||
{{- range $port := $udp_ports }}
|
||||
{{- if $port }}
|
||||
upstream server_nodes_udp_{{ $port }} {
|
||||
{{- range $server := $servers }}
|
||||
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s;
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
server {
|
||||
listen {{ $port }} udp;
|
||||
proxy_pass server_nodes_udp_{{ $port }};
|
||||
proxy_timeout 600;
|
||||
proxy_connect_timeout 2s;
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
7
proxy/test/portmap.yaml
Normal file
7
proxy/test/portmap.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
ports:
|
||||
1234.tcp:
|
||||
- server-0
|
||||
- server-1
|
||||
4321.udp:
|
||||
- agent-0
|
||||
- agent-1
|
||||
Loading…
x
Reference in New Issue
Block a user