-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathnginx-merge-app-by-id.tmpl
40 lines (36 loc) · 1.19 KB
/
nginx-merge-app-by-id.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
# Generated by nixy {{datetime}}
user www-data;
worker_processes auto;
pid /var/run/nginx.pid
events {
use epoll;
worker_connections 2048;
multi_accept on;
}
stream {
{{- range $appid, $app := .MergeAppsByLabel "streamservicename"}}
{{- if eq (index $app.Labels "internal") "stream"}}
{{- range $id, $definition := $app.PortDefinitions}}
{{- if ne (index $app.Labels "streamservicename") ""}}
upstream {{ (index $app.Labels "streamservicename") }}-{{ $id }} {
{{- else}}
upstream {{index $app.Hosts 0}}-{{ $id }} {
{{- end}}
least_conn;
{{- range $task := $app.Tasks}}
server {{ $task.Host }}:{{ index $task.Ports $id}}{{- with index $task.Labels "weight"}} weight={{ . }}{{- end}};
{{- end}}
}
server {
{{- if eq $definition.Protocol "tcp" }}
listen {{ $definition.Port }};
{{- else}}
listen {{ $definition.Port }} {{ $definition.Protocol }};
{{- end}}
{{- if ne (index $app.Labels "streamservicename") ""}}
proxy_pass {{ (index $app.Labels "streamservicename") }}-{{ $id }};
{{- else}}
proxy_pass {{index $app.Hosts 0}}-{{ $id }};
{{- end}}
}
}