init enhanced templating for the nginx config

pull/656/head
iwilltry42 3 years ago
parent 897e49a8ee
commit cabfe98023
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 1
      proxy/Dockerfile
  2. 6
      proxy/conf.d/nginx.toml
  3. 4
      proxy/nginx-proxy
  4. 45
      proxy/templates/nginx.tmpl
  5. 7
      proxy/test/portmap.yaml

@ -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 }}
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s;
{{- end }}
}
{{- range $portstring := lsdir "/ports" }}
server {
listen {{ $port }};
proxy_pass server_nodes_{{ $port }};
proxy_timeout 600;
proxy_connect_timeout 2s;
}
{{- end }}
#######
# UDP #
#######
{{- $portdir := printf "/ports/%s/*" $portstring -}}
{{- $port := index (split $portstring ".") 0 -}}
{{- $protocol := index (split $portstring ".") 1 -}}
{{- $upstream := replace $portstring "." "_" -1 }}
{{- range $port := $udp_ports }}
{{- if $port }}
upstream server_nodes_udp_{{ $port }} {
{{- range $server := $servers }}
upstream {{ $upstream }} {
{{- range $server := getvs $portdir }}
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s;
{{- end }}
}
server {
listen {{ $port }} udp;
proxy_pass server_nodes_udp_{{ $port }};
listen {{ $port }} {{- if (eq $protocol "udp") }} udp{{- end -}};
proxy_pass {{ $upstream }};
proxy_timeout 600;
proxy_connect_timeout 2s;
}
{{- end }}
{{- end }}
}

@ -0,0 +1,7 @@
ports:
1234.tcp:
- server-0
- server-1
4321.udp:
- agent-0
- agent-1
Loading…
Cancel
Save